Hi folks,

I have a relatively simple grammar, which works well under most
conditions, but in one case it has issues. Here is a snippet of the
grammar:

expression :    or      ;
or      :       and (OR ^ and)*         ;
and     :       equality (AND ^ equality)*      ;       
equality:       comparison ((EQUALITY ^ | NOTEQUALS ^) comparison)*     ;
comparison:     add ((GREATER ^| GREATER_EQUAL ^| LESS ^| LESS_EQUAL^) add)*    
;
add     :       multiply ((PLUS ^| MINUS^) multiply)*   ;
multiply:       combo_expression ((MULTIPLY ^| DIVIDE ^|MODULO^) 
combo_expression)*     ;
combo_expression
        :       atom
        |       NOT atom
        |       CAST LEFT_PAREN assignment_declaration COMMA expression 
RIGHT_PAREN
        ;
atom    : qualified_name
        (
                LEFT_SQR_BRACE expression RIGHT_SQR_BRACE //this condition 
breaks
        |       (COLON ID)? LEFT_PAREN (expression (COMMA expression)*)?
RIGHT_PAREN //so does this one
        )?
        | (MINUS)? INT
        | BOOLEAN
        | (MINUS)? DECIMAL
        | STRING
        | NULL
        | LIBRARY_CALL LEFT_PAREN expression COMMA expression COMMA
expression RIGHT_PAREN
        | INPUT LEFT_PAREN expression RIGHT_PAREN
        | LEFT_PAREN expression RIGHT_PAREN -> ^(expression) ;

So far as I can tell from testing, this works fine, except in the case
where you have an expression with surrounding parentheses and the item
inside of it is a qualified_name, with either square braces or the
part of the rule after it. In this particular case, the following
exception is thrown:

java.lang.RuntimeException: more than one node as root (TODO: make
exception hierarchy)
        at 
org.antlr.runtime.tree.BaseTreeAdaptor.becomeRoot(BaseTreeAdaptor.java:150)
        at org.sonify.vm.hop.parser.HopParser.atom(HopParser.java:4954)
//notice it is in the parser, not the tree grammar
        at 
org.sonify.vm.hop.parser.HopParser.combo_expression(HopParser.java:4403)

To give an example of what would break in the language (not all rules
shown), this would work fine:

boolean array a
a[0] = 10
a[1] = a[0]

and this would throw the above exception

boolean array a
a[0] = 10
a[1] = (a[0])

I've tried everything obvious (to me) that I can think of (e.g.,
pulling out the rules one by one), but am perplexed as to why that
rule throws a double root exception.
I'm pretty sure the problem is relative to this portion of the
grammar, but just in case, here is the full grammar:

https://sourceforge.net/apps/trac/sodbeans/browser/trunk/sodbeans/Compiler/src/org/sonify/vm/hop/parser/Hop.g
and the full tree grammar:
https://sourceforge.net/apps/trac/sodbeans/browser/trunk/sodbeans/Compiler/src/org/sonify/vm/hop/parser/HopSymbolTableWalker.g

When I run the code in the ANTLRWorks interpreter, it generates the
trees just fine. One final clue is that my tree grammar is showing UP
and DOWN tokens, which I know means there is a mismatch somewhere ---
where, however, and how to fix, I'm not quite sure about, and this
error seems to be coming from the parser anyway, so I don't "suspect"
that that is the cause for this immediate problem.

Any help would be greatly appreciated, as the error is driving me a bit crazy,

Stefik

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to