dmd Lexer and Parser in D
yebblies at nospamgmail.com
Sat Feb 4 21:10:48 PST 2012
"Zach Tollen" <reachzachatgooglesmailservice at dot.com> wrote in message
news:jgjqfo$2puc$1 at digitalmars.com...
> 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,
(I know this isn't what you meant, but that's what the parse tree looks
More information about the Digitalmars-d