Best practices for parsing files

Sean Kelly sean at f4.ca
Thu Jan 25 16:03:47 PST 2007


lurker wrote:
> Hi.
> 
> I'm new to D but not to programming. I would like to write a small scripting
> engine using the great D programming language but I'm undecided on what
> techniques should use to parse source files.
> 
> Since slices seem to be a central feature of D I was thinking on reading the
> whole file in memory and use slices to build the syntax tree.
> 
> Does anyone have examples of parsing files using this method?

The DMD lexer works pretty much this way, and it's available in every 
DMD distribution :-)

> Any other methods I should consider?

This is the method I've used in the past, even in C++.  It seems to make 
for cleaner code than the allocate/copy method, and it's faster to boot.



Sean



More information about the Digitalmars-d mailing list