Howdy All,

I've got an old grammar that used to work in ANTLR 2 but that now  
fails in ANTLR 3. I'd like to make the switch, but I'm at a loss as to  
how to fix this. For the following example code:

--------------

void input_a() {
    integer a, bb, xyz, b3, c, p, q;
    real b;
    a = b3;
    b = -2.5;
    xyz = 2 + a + bb + c - p / q;
    a = xyz * ( p + q );
    p = a - xyz - p;
}

-------------

I get this tree result:

-------------

def
        function_declaration
                type
                        void
                input_a
                (
                )
                code_block
                        FailedPredicateException(code_block,{can't deal with 
predicates  
yet}?)
                        FailedPredicateException(code_block,{synpred2_javalet}?)

------------

Here's the grammar I'm using. Has anyone seen anything like this  
before for a grammar that worked in ANTLR 2? I'm not sure how to get  
it to parse properly so I don't get the failed predicate exception.

Thanks,

Elliot

------------

grammar Javalet;
options {
        backtrack = true;
        output=AST;
        ASTLabelType=CommonTree;
        k=2;
        }
tokens  {
        FUNCTION = 'function';
}

@header {package javalet.compiler;}
@lexer::header{package javalet.compiler;}

def     :       function_declaration
        ;


code_block
        :       '{' statement* '}' -> (statement)*
        |       statement
        ;

statement
        :       block_statement
        |       variable_declaration ';' -> variable_declaration
        |       assignment ';' -> assignment
        ;

block_statement
        :       IF '(' value_0 ')' code_block
                (else_block)? -> ^(IF value_0 code_block (else_block)?)
        |       WHILE '(' value_0 ')' code_block -> ^(WHILE value_0 code_block)
        ;

else_block
        :       ELSE code_block -> ^(ELSE code_block)
        ;

assignment
        :       ID EQ value_0 -> ^(EQ ID value_0)
        ;

variable_declaration
        :       type ID (',' ID)* -> ^(type ID*)
        ;

function_declaration
        :       type ID '(' ')' code_block -> ^('function' type ID code_block)
        ;

operator_0
        :       LOGICAL_OR
        ;
        
LOGICAL_OR
        :       '||'
        ;

operator_1
        :       LOGICAL_AND
        ;

LOGICAL_AND
        :       '&&'
        ;

operator_2
        :       LOGICAL_EQUALITY
        |       LOGICAL_INEQUALITY
        |       LOGICAL_GREATER_THAN
        |       LOGICAL_LESS_THAN
        |       LOGICAL_GREATER_THAN_OR_EQUAL
        |       LOGICAL_LESS_THAN_OR_EQUAL
        ;

LOGICAL_EQUALITY
        :       '=='
        ;

LOGICAL_INEQUALITY
        :       '!='
        ;

LOGICAL_GREATER_THAN
        :       '>'
        ;

LOGICAL_LESS_THAN
        :       '<'
        ;

LOGICAL_GREATER_THAN_OR_EQUAL
        :       '>='
        ;

LOGICAL_LESS_THAN_OR_EQUAL
        :       '<='
        ;

operator_3
        :       ADD
        |       SUBTRACT
        ;

ADD     :       '+';
SUBTRACT:       '-';

operator_4
        :       MULTIPLY
        |       DIVIDE
        ;

MULTIPLY:       '*';
DIVIDE  :       '/';

value_0
        :       value_1 operator_0 value_0 -> ^(operator_0 value_1 value_0)
        |       value_1
        ;

value_1
        :       value_2 operator_1 value_1 -> ^(operator_1 value_2 value_1)
        |       value_2
        ;

value_2
        :       value_3 operator_2 value_2 -> ^(operator_2 value_3 value_2)
        |       value_3
        ;

value_3
        :       value_4 operator_3 value_3 -> ^(operator_3 value_4 value_3)
        |       value_4
        ;

value_4
        :       value_5 operator_4 value_4 -> ^(operator_4 value_5 value_4)
        |       value_5
        ;

value_5
        :       '(' value_0 ')' -> ^(value_0)
        |       num
        ;


num
        :       (REAL|INTEGER|ID)
        ;

WS      :       (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
        ;

COMMENT :       '/*' .* '*/' {$channel=HIDDEN;}
        ;

LINE_COMMENT
        :       '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;

//fragment
IF      :       'if' ;

//fragment
ELSE    :       'else' ;

//fragment
WHILE   :       'while' ;


//fragment
DO      :       'do' ;

//fragment
FOR     :       'for' ;

//fragment
EQ      :       '='
        ;

fragment
DIGIT   :       '0'..'9' ;

fragment
LETTER  :       ('a'..'z'|'A'..'Z') ;

type    :       TYPE_VOID
        |       TYPE_INTEGER
        |       TYPE_REAL
        ;
        
TYPE_VOID
        :       'void'
        ;
TYPE_INTEGER
        :       'integer'
        ;
TYPE_REAL
        :       'real'
        ;

INTEGER :       (DIGIT)+ ;

REAL    :       ('+'|'-') (DIGIT)+ '.' (DIGIT)+ ;

ID      :       LETTER ('_' | DIGIT | LETTER)* ;

____________

[email protected]
Worcester Polytechnic Institute '09
Computer Science


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