History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ANTLR-206
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Terence Parr
Reporter: Terence Parr
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ANTLR v3

ANTLR fails to detect left recursion

Created: 29/Dec/07 06:00 PM   Updated: 29/Dec/07 06:21 PM
Component/s: analysis
Affects Version/s: 3.0.1
Fix Version/s: 3.1


 Description  « Hide
grammar T;

options {
        //language=CSharp;
        output=AST;
        ASTLabelType=CommonTree;
}

tokens {
    EQ;
}

@header {
        #pragma warning disable 0219
}

file
    : block EOF!
    ;

statement
    : assignment
    | loop
    | conditional
    | block
    | write
    ;

assignment
    : ID '='^ expr
    ;

loop
    : 'while'^ condition 'do'! statement
    ;

conditional
    : 'if'^ condition 'then'! statement
    ;

block
        : 'begin'^ statement* 'end'!
        ;

write
        : 'write'^ expr
        ;

expr
        : (condition) => condition '?'^ expr ':'! expr
        | simpleExpr
        ;

simpleExpr
        : term (('+' | '-')^ term)*
        ;
    
term
        : factor (('*' | '/' | '%')^ factor)*
        ;
      
factor
    : '('! expr ')'!
        | ID ('['^ expr ']'!)*
        | NUMBER
        ;

condition
        : expr '<'^ expr
        | expr '>'^ expr
        | expr '<='^ expr
        | expr '>='^ expr
        | expr '<>'^ expr
        | e1=expr '=' e2=expr -> ^(EQ $e1 $e2)
        ;

NUMBER
        : ('0'..'9')+
        ;

ID
        : ('a'..'z')+
        ;

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


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Terence Parr - 29/Dec/07 06:21 PM
I wasn't avoiding decisions in left-recursive rules.