[antlr-interest] Problem with ANTLR 2.7.4

Terence Parr parrt at cs.usfca.edu
Mon Sep 13 12:40:39 PDT 2004


Hi.  You can only use

> #assemblerStatement = #( #[ASSEMBLER_STATEMENT], a );

type statements at the end of an alternative as you will mess up the 
automatic AST construction algorithm.

In your case, you can simply put "!" on the rule definition to turn it 
off :)

Ter
On Sep 13, 2004, at 12:30 PM, Mihai Christodorescu wrote:

> I am trying to parse x86 assembly text, but the problem I am having is
> not related to this task.
>
> I have the following rule in the grammar:
>
> assemblerStatement
>     :   a:asId
>         (   b:expression
>             (   COMMA! c:expression
>                 (   COMMA! d:expression
>                 )?
>             )?
>         )?
>     ;
>
> This works just fine, it parses things and builds an AST.
>
> Now, I want to build an AST node for the assemblerStatement rule
> containing different number of children, based on how many expressions
> are matched. So I modified the rule as follows:
>
> assemblerStatement
>     :   a:asId
>         {
>             #assemblerStatement = #( #[ASSEMBLER_STATEMENT], a );
>         }
>         (   b:expression
>             {
>                 #assemblerStatement = #( #[ASSEMBLER_STATEMENT], a, b
> );
>             }
>             (   COMMA! c:expression
>                     {
>                         #assemblerStatement = #(
> #[ASSEMBLER_STATEMENT], a, b, c );
>                     }
>                 (   COMMA! d:expression
>                     {
>                         #assemblerStatement = #(
> #[ASSEMBLER_STATEMENT], a, b, c, d );
>                     }
>                 )?
>             )?
>         )?
>     ;
>
> Unfortunately, the parser no longer terminates (it does not crash, it
> just hangs). I could debug it if necessary, but I wonder whether the
> problem is with my grammar.
>
> Any help is much appreciated.
>
> Thanks,
>
> Mihai
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list