FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Generating d code now..

 
Post new topic   Reply to topic     Forum Index -> lr-lalr
View previous topic :: View next topic  
Author Message
Ivan Senji



Joined: 03 Sep 2004
Posts: 8
Location: Zagreb, Croatia

PostPosted: Sun Sep 12, 2004 6:18 am    Post subject: Generating d code now.. Reply with quote

Now you can add D code into the grammar definition and it will generate D code (a recursive descent parser of (la)lr generated parse tree)


The example is in the tests\translate-gram and it is a grammar that translates simple expressions into postfix form.

Code fragments are delimited with {{{ and }}} (maybe change it because
it is a little bit ugly).
The code between the first {{{ and }}} int the grammar file is wher you put a main() of your parser.
Other rules look like this.
<S> -> <A> <B> <C>
{{{ inout int x, inout int y /*parameters for S*/
part 0 //before A is executed
//some D code here
call x+1, y+1 /*optional: what params to pass to A*/
part 1 //before B is executed
//...D code
call x /*pass this param to B*/
part 2 //before C is executed
//D code
call y,x,x+y /*pass this to C*/
part 3 //after C is executed
printf("\nDone parsing S Smile");
}}}

Maybe it has some more bugs i couldn't find and the format of the embeded code fragments is ugly, but i didn't have better ideas at the moment.

To use it compile main.d lr.d ivan_set.d ivan_nodetree.d into (for example) lr.exe

With grammar file "test1" call it like this:
lr -i test1 +forseRecalc //optionaly "+lalr 0" for lalr table
this will generate a file test1.d wich has to be compiled with lr.d, ivan_set.d and ivan_nodetree.d to get the final parser.

PS I know my descriptions are awfull and i hope this doesn't sound too complicated. Looking at translate-gram example should make everything clearer Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> lr-lalr All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group