Re: Please assist: if/else condition problem with lex/yacc

Pakt <paktsardines@gmail.com>
Mon, 24 May 2010 19:40:54 -0700 (PDT)

          From comp.compilers

Related articles
Please assist: if/else condition problem with lex/yacc paktsardines@gmail.com (Pakt) (2010-05-17)
Re: Please assist: if/else condition problem with lex/yacc kevinlynx@gmail.com (Kevin Lynx) (2010-05-20)
Re: Please assist: if/else condition problem with lex/yacc cfc@shell01.TheWorld.com (Chris F Clark) (2010-05-21)
Re: Please assist: if/else condition problem with lex/yacc paktsardines@gmail.com (Pakt) (2010-05-24)
Re: Please assist: if/else condition problem with lex/yacc gone_pecan@nowhere.net (Bruce C. Baker) (2010-05-26)
Re: Please assist: if/else condition problem with lex/yacc gneuner2@comcast.net (George Neuner) (2010-05-26)
Re: Please assist: if/else condition problem with lex/yacc gneuner2@comcast.net (George Neuner) (2010-05-27)
Re: Please assist: if/else condition problem with lex/yacc gneuner2@comcast.net (George Neuner) (2010-06-01)
| List of all articles for this month |

From: Pakt <paktsardines@gmail.com>
Newsgroups: comp.compilers
Date: Mon, 24 May 2010 19:40:54 -0700 (PDT)
Organization: Compilers Central
References: 10-05-104 10-05-116 10-05-121
Keywords: yacc, interpreter
Posted-Date: 26 May 2010 00:59:50 EDT

Thank you everyone for your help, particularly Chris for your extended
reply with sample code. It was helpful - and tempting, to read that I
can do conditions without an AST (thanks Kevin!) but it sounds like
ASTs are the better solution, particularly as I want to tackle loops
next.


I think I'll build the AST by hand as it'll probably be just as fast
as trying to work out how to make a tool do it for me, particularly
with Chris' sample for reference. I'm confident I'll be able to build
the tree with little trauma.


My next question is probably an obvious one, but what do I with the
tree once it's built? How do I traverse it? I guess don't understand
the 'big picture' view of how an AST helps.
I've tried reading what I can online, but I haven't found anything
that's of any real/comprehensible use. In fact there seems to be
ample examples on how to use yacc to build postfix calculators and the
like, but next to nothing on how to do anything more sophisticated,
such as conditions, loops etc. I even found mention by Yacc's author
of hopes (in 1990's) to one day expand the tutorial to cover
conditions and loops. :)


If my original question is as frequently asked as is claimed, does
anyone have any helpful, straightforward links to pass on, or code
snippets? If someone could point me a helpful direction then I'll
hopefully stop pestering you with silly questions.


Thanks again for any assistance,


Pakt.
[Once you have the AST, you interpret expressions by an ordinary
depth-first recursive tree walk. For if/then/else, you interpret the
condition, then depending on its value you interpret either the "then"
subtree or the "else" subtree. It's not very complicated. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.