[antlr-interest] AST with optional parameters

John B. Brodie jbb at acm.org
Tue Jun 7 07:57:49 PDT 2011


On Tue, 2011-06-07 at 10:33 -0400, David Smith wrote:
> Yes, the language is Matlab and a semicolon on the end of an 
> assignment expression suppresses display of the result of the assignment.
> Bart, I appreciate the suggestion; I haven't tried that (much 
> simpler) solution - I'll let you know.


you didn't ask about this but may i suggest an alternative tree form in
this case.

i believe you said that the optional semicolon occurs on many statements
(i am not that familiar with Matlab so sorry if this is obvious). so
rather than having the semicolon on every statement in the tree forcing
the tree processor to check for it on every statement; make the display
operator explicit in the tree at parse-time. something like

...
    | (ID GETS) => gets
...
    ;

gets :
  (ID GETS expr -> ^(GETS ID expr)) (SEMI -> ^(DISPLAY[$SEMI] gets))? ;

where DISPLAY is an imaginary token (i may have the meta-syntax wrong
but i hope you get the idea).

now you have separated the notion of assignment from the notion of
displaying a result. and thereby, i suspect, life becomes easier.

Just my unsolicited 2 cents worth...
   -jbb

> At 08:26 AM 6/7/2011, Bart Kiers wrote:
> >Hi John,
> >
> >Have you tried:
> >
> >    |   (ID GETS) => ID GETS e=expr (s=SEMI)? -> ^(GETS ID $e $s?)
> >
> >is the semicolon really necessary in the tree? (e.g. does the presence
> >of the semicolon actually change the meaning of of the statement?)
> >
> >
> >Exactly my thought after I sent my previous e-mail!
> >
> >perhaps:
> >
> >    | (ID GETS) => ID GETS^ expr SEMI!?
> >
> >
> >Or the equivalent rewrite rule:
> >
> >(ID GETS) => ID GETS expr SEMI? -> ^(GETS ID expr)
> >
> >
> >Regards,
> >
> >Bart.
> >
> >
> >
> >Hope this helps...
> >   -jbb
> >
> >
> >
> >List: 
> ><http://www.antlr.org/mailman/listinfo/antlr-interest>http://www.antlr.org/mailman/listinfo/antlr-interest
> >Unsubscribe: 
> ><http://www.antlr.org/mailman/options/antlr-interest/your-email-address>http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
> 
> David M. Smith http://www.cc.gatech.edu/fac/David.Smith
> Georgia Institute of Technology, College of Computing
> Sent from my ASR-33 Teletype 
> 





More information about the antlr-interest mailing list