[antlr-interest] conditional processing

Harald Mueller harald_m_mueller at gmx.de
Tue Nov 27 01:08:10 PST 2007


Hi -

You need a context that keeps knowledge about the world - variable values, but also results of evaluations e.g. for ifs, returns etc. Usually the context is a stack - see any text on fundamentals of progam language semantics. The context is threaded through all your calls (as a simple parameter), and your calls - e.g. "simpleStatement" - can then react to it:

if (boolStack.Top) {
    ...do evaluation...
}

Just imagine what data a virtual machine would need to do what you want - exactly these data are what you need in your context.

Regards
Harald

-------- Original-Nachricht --------
> Datum: Mon, 26 Nov 2007 21:02:46 -0600
> Von: "Mark Volkmann" <r.mark.volkmann at gmail.com>
> An: antlr-interest at antlr.org
> Betreff: [antlr-interest] conditional processing

> Part of my AST looks like this.
> 
> ^('if' condition simpleStatement)
> 
> In my tree grammar, the rule for "condition" evaluates the matching
> content to true or false. The rule for "simpleStatement" executes the
> statement, for example, it could be a simple print statement. I only
> want simpleStatement to be executed if condition evaluates to true. I
> haven't been able to figure out how to make this work because when
> this part of my AST is matched, the rules for both condition and
> simpleStatement are fired.
> 
> I'd appreciate any hints on how to achieve this.
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail


More information about the antlr-interest mailing list