Re: Single boolean variable

Nick Roberts <nick.roberts@acm.org>
8 Nov 2003 01:43:39 -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: Nick Roberts <nick.roberts@acm.org>
Newsgroups: comp.compilers
Date: 8 Nov 2003 01:43:39 -0500
Organization: Compilers Central
References: 03-10-131
Keywords: design
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
if-then).


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.


HTH


Incidentally, which language is your compiler for, please?


--
Nick Roberts


Post a followup to this message

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