"Zach Tollen" <[email protected]> wrote in message 
news:[email protected]...
> What I'm really wondering is if you wanted a program which helped you edit 
> the syntax tree directly and only produced a text file for saving and 
> running, what kind of data structure would you like to have representing 
> the syntax tree? Without knowing anything else, I guessed that it would be 
> nice to have something resembling the official D parse-tree.

The code inside dmd that does lowerings does something like this.

Want to add printf to the end of a function?  Sure!

fbody = new CompoundStatement(loc, fbody, new ExpStatement(loc, new 
CallExp(loc, new VarExp(loc, new IdentifierExp(loc, 
Lexer::idPool("printf"))), new StringExp(loc, "Hello world!\\n"))));

It is a lot better to have the parser generate the syntax tree for you!

fbody = new CompoundStatement(loc, fbody, new CompileStatement(loc, 
"printf(\"Hello world!\\n\");"));

(I know this isn't what you meant, but that's what the parse tree looks 
like) 


Reply via email to