grammar - antlr left recursion for nesting boolean expressions -


i writing antlr grammar in i'd able have nested expressions, can either "simple" expressions or boolean expressions (with optional parentheses). simple expression 1 lhs , rhs, such a = 5

i'd able support these types of expressions:

a = 5 = 5 or b = 10 = 5 or (b = 10 , c = 12) (a = 5 , b = 10) or (c = 12 , d = 13) 

my grammar looks like:

string: char+; fragment char: ('a'..'z' | 'a'..'z' | '0'..'9');   booleanop: 'and' | 'or'; simpleexpr: string '=' string; expr: simpleexpr | parenexpr | booleanexpr; parenexpr: '(' expr ')'; booleanexpr: expr (booleanop expr)+; 

i'm getting error expr , booleanexpr mutually left recursive. understand why happening, i'm not sure how work around if want able nest boolean expressions within each other.

on homepage of www.antlr.org can see sample grammar:

grammar expr;   prog: (expr newline)* ;   expr: expr ('*'|'/') expr   | expr ('+'|'-') expr   | int    | '(' expr ')' ; 

a little editing , need. antlr 4. version using? i'm sure every version of antlr has expression grammar sample.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -