|
|
|
Re: Left recursion [message #1012912 is a reply to message #1012904] |
Fri, 22 February 2013 12:52 |
|
I see basically 3 differences:
(1) assignment in '('expr=Orexpr ')' instead of '('Orexpr ')'
(2) dont use type rewrites/specificing return types at all expression rules
(3) dont use the pattern of assigning parsed stuff to a subtree
=> i simply recommend to use / adopt the pattern as it is in the blog
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: Left recursion [message #1012953 is a reply to message #1012946] |
Fri, 22 February 2013 14:09 |
Rafael Bielen Messages: 5 Registered: February 2013 |
Junior Member |
|
|
Here is my full code, the recursion error is at the var statement:
Start : Prog;
Prog : 'game' name=ID '(' (attrasslist=Attrasslist)? ')' (decl+=Decl)* stmtblock=Stmtblock (block+=Block)*;
Decl : name=Vardecl ';' | name=Objdecl ';';
Vardecl : 'int' name=ID ( ('[' size=INT ']') | init=Init? );
Objdecl : type=Objtyp name=ID ( ('[' size=INT ']') | '('attrasslist=Attrasslist? ')' );
Init : '=' Expr;
Objtyp : 'rectangle' | 'triangle' | 'circle';
Attribute : 'height' | 'width' | 'speed' | 'x' | 'y' | 'size';
Attrasslist : Attrass (',' attrasslist+=Attrasslist)*;
Attrass : var = ( 'height' | 'width' | 'speed' | 'x' | 'y' | 'size') '=' expr=Expr;
Block : Animblock | Eventblock;
Animblock : 'animation' name=ID '(' type=Objtyp var_decl=ID ')' stmtblock=Stmtblock;
Eventblock : 'on' Keystroke Stmtblock;
Keystroke : 'space' | 'leftarrow' | 'rightarrow' | 'uparrow' | 'downarrow';
Stmtblock : '{' (stmt+=Stmt)* '}';
Stmt : Ifstmt | Forstmt | Assstmt ';';
Ifstmt : 'if' '(' expr=Expr ')' stmtblockif=Stmtblock ( 'else' stmtblockelse=Stmtblock )?;
Forstmt : 'for' '(' assstmt1=Assstmt ';' expr=Expr ';' assstmt2=Assstmt ')' stmtblock=Stmtblock;
Assstmt : Var '=' expr=Expr;
Array : '[' expr=Expr ']';
//Error
Var : var=[Objdecl] array = Array? '.' attribute = Attribute
| var=[Vardecl] array = Array? ;
Expr returns Expression: KonjunktionExpr ({Or.left=current} '||' right=KonjunktionExpr)*;
KonjunktionExpr returns Expression: RelationExpr ({Konjunktion.left=current} '&&' right=RelationExpr)*;
RelationExpr returns Expression: AddExpr ({Relation.left=current} type=('==' | '<=' | '<') right=AddExpr)*;
AddExpr returns Expression: MultExpr ({PlusMinus.left=current} type=('+' | '-') right=MultExpr)*;
MultExpr returns Expression: UnExpr ({PointArr.left=current} type=('*' | '/') right=UnExpr)*;
UnExpr returns Expression: type=('!' | '-')? atom=Atom;
Atom returns Expression:
{NumberLiteral} value=INT |
{TouchedVar} var=Var ('touches' touched=Var)? |
{ExprVar} '(' expr=Expr ')';
[Updated on: Fri, 22 February 2013 14:18] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05977 seconds