Single boolean variable

"Eduardo Hasbun" <ehasbun@ccs.hn>
31 Oct 2003 23:01:37 -0500

          From comp.compilers

Related articles
Single boolean variable ehasbun@ccs.hn (Eduardo Hasbun) (2003-10-31)
Re: Single boolean variable nick.roberts@acm.org (Nick Roberts) (2003-11-08)
| List of all articles for this month |

From: "Eduardo Hasbun" <ehasbun@ccs.hn>
Newsgroups: comp.compilers
Date: 31 Oct 2003 23:01:37 -0500
Organization: Compilers Central
Keywords: semantics, question
Posted-Date: 31 Oct 2003 23:01:37 EST
Content-Class: urn:content-classes:message

I'm trying to implement if-statements that work with a boolean
expression consisting only of a boolean variable. Up until now I have
been able to implement relational expressions and logical expressions.
The problem I have is how to make a semantic action that will generate
an intermediate representation of a single boolean variable and how to
know that that variable belongs to an if statement. I thought of a
solution of having a parallel grammar for these type of expressions
where I would know that the variable is only used as a boolean
expression, but it seems to awkward. I have this grammar working:


ifstmt : If lexpr Then stmtlist elsif_list else_part_opt End If
{MakeIf(); }


lexpr : lexpr logop rexpr
                         { DoLogOp();}
                        | rexpr


rexpr : rexpr relop expr
                         {DoLogOp();}
                        | expr


logop : Andop { Operator(AndOp);}
                        | Orop { Operator(OrOp);}
                        | Xorop { Operator(XorOp);}
                        | Andop Then { Operator(AndThenOp);}
                        | Orop Else { Operator(OrElseOp);}


relop : Eqop { Operator(EqOp);}
                        | Neqop { Operator(NeqOp);}
                        | Ltop { Operator(LtOp);}
                        | Leop {Operator(LeOp);}
                        | Gtop {Operator(GtOp);}
                        | Geop { Operator(GeOp);}


expr : expr addop term
                         { DoArithOp(); }
                        | term


term : term multop fact
                         {DoArithOp(); }
                        | fact


fact : unarylist notprimary
                         {PerformUnary(); }
                        | notprimary


notprimary : notoplist primary
                        | primary


notoplist : notop
                        | notop notoplist {MergeNotOps();}


notop : Notop {Operator(NotOp);}
unarylist : addop lambda
                        | addop unarylist{MergeAddOps(); }


primary : Lparen lexpr Rparen
                        | integer_const {IconstReduce(); }
                        | memref {AddrToPrimary(); }/*the address of the variable*/
                          /*this is where I would need to know what to do*/
                        | boolean_const {BconstReduce(); }


boolean_const: Btrue {PushBool(1);}
                          | Bfalse {PushBool(0);}


I would really appreciate your help.


Post a followup to this message

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