[antlr-interest] Problem with ANTLR 2.7.4

Mihai Christodorescu warkda at yahoo.com
Mon Sep 13 12:30:59 PDT 2004


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

<*> 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