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

Kevin Lynx <kevinlynx@gmail.com>
Thu, 20 May 2010 15:11:15 +0800

          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: Kevin Lynx <kevinlynx@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 20 May 2010 15:11:15 +0800
Organization: Compilers Central
References: 10-05-104
Keywords: bison , comment
Posted-Date: 20 May 2010 15:22:46 EDT

paktsardines@gmail.com (Pakt) wrote:
"
if_else_block:
                    TOK_IF expression LBRACE commands RBRACE TOK_ELSE LBRACE commands
RBRACE {
                                    if ($2 == true) {
                                                    $$=$4;
                                    }
                                    else {
                                                    $$=$8;
                                    }
                    }
                    ;
"
I suppose this will not work as you wish. Actually, yacc will parse
the two "commands" above, but not parse one of them by the
"expression". The simple solution is to set a global flag to indicate
the "expression" result, and when you interpret "command", you can
check the flag to do your special things.


Kevin Lynx
[A flag will work for if/then/else, but I still encourage people to turn
anything they plan to interpret into an AST first. Flags won't help
when you want to add loops. -John]


Post a followup to this message

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