|Single boolean variable firstname.lastname@example.org (Eduardo Hasbun) (2003-10-31)|
|Re: Single boolean variable email@example.com (Nick Roberts) (2003-11-08)|
|From:||Nick Roberts <firstname.lastname@example.org>|
|Date:||8 Nov 2003 01:43:39 -0500|
|Posted-Date:||08 Nov 2003 01:43:38 EST|
Eduardo Hasbun wrote:
> 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:
My own approach in this kind of situation would be to simply not
distinguish the context of expressions at this (tree-building)
stage. In other words, use the same semantic action for all variables
(just add it to the tree). At some later stage, you can then check
that an expression in an if-then is of boolean type, and carry out the
special semantic actions required (for a boolean expression in an
To my mind, parsing (and building the initial parse tree) is just the
first phase of many. I would expect there to be several semantic
analysis phases after it, refining and decorating the tree.
Incidentally, which language is your compiler for, please?
Return to the
Search the comp.compilers archives again.