Commit 513b2d53 authored by zygzagZ's avatar zygzagZ

nowe grammary

parent 062c55e3
position token PIdent (letter (letter|digit|'_'|'\'')*) ;
-- programs ------------------------------------------------
entrypoints Program ;
Prog. Program ::= [TopDef] ;
FnDef. TopDef ::= FunDef ;
ClDef. TopDef ::= ClassDef ;
separator nonempty TopDef "" ;
-- function def --------------------------------------------
FuncDef. FunDef ::= Type PIdent "(" [Arg] ")" Block ;
Ar. Arg ::= Type PIdent;
separator Arg "," ;
-- class def -----------------------------------------------
ClassDefN. ClassDef ::= "class" PIdent ClassBlock ;
ClassDefE. ClassDef ::= "class" PIdent "extends" PIdent ClassBlock ;
ClassBl. ClassBlock ::= "{" [ClassBlockDef] "}" ;
ClassMthd. ClassBlockDef ::= FunDef ;
ClassFld. ClassBlockDef ::= Type [Item] ";" ;
separator ClassBlockDef "" ;
-- statements ----------------------------------------------
Blk. Block ::= "{" [Stmt] "}" ;
separator Stmt "" ;
Empty. Stmt ::= ";" ;
BStmt. Stmt ::= Block ;
Decl. Stmt ::= Type [Item] ";" ;
NoInit. Item ::= PIdent ;
Init. Item ::= PIdent "=" Expr ;
separator nonempty Item "," ;
Ass. Stmt ::= Expr "=" Expr ";" ;
Incr. Stmt ::= Expr "++" ";" ;
Decr. Stmt ::= Expr "--" ";" ;
Ret. Stmt ::= "return" Expr ";" ;
VRet. Stmt ::= "return" ";" ;
Cond. Stmt ::= "if" "(" Expr ")" Stmt ;
CondElse. Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt ;
While. Stmt ::= "while" "(" Expr ")" Stmt ;
SExp. Stmt ::= Expr ";" ;
ForEach. Stmt ::= "for" "(" Type PIdent ":" Expr ")" Stmt ;
-- Types ---------------------------------------------------
Int. Type ::= "int" ;
Str. Type ::= "string" ;
Bool. Type ::= "boolean" ;
Void. Type ::= "void" ;
Array. Type ::= Type "[]" ;
ClassT. Type ::= PIdent ;
internal Fun. Type ::= Type "(" [Type] ")" ;
separator Type "," ;
-- Expressions ---------------------------------------------
EVar. Expr7 ::= PIdent ;
EIndexAcc. Expr7 ::= Expr7 "[" Expr "]" ;
EClsMmbr. Expr7 ::= Expr7 "." PIdent ;
EApp. Expr7 ::= Expr7 "(" [Expr] ")" ;
ELitInt. Expr6 ::= Integer ;
ELitTrue. Expr6 ::= "true" ;
ELitFalse. Expr6 ::= "false" ;
EString. Expr6 ::= String ;
ENewArray. Expr6 ::= "new" Type "[" Expr "]" ;
ENewClass. Expr6 ::= "new" PIdent ;
-- musi być ( Expr ) żeby parser się nie zastanawiał czy po ')' będzie 'null' czy '=' (czy to bedzie rzutowanie, czy przypisanie) bo to niejednoznaczne
NullCast. Expr5 ::= "(" Expr ")" "null" ;
Neg. Expr5 ::= "-" Expr6 ;
Not. Expr5 ::= "!" Expr6 ;
EMul. Expr4 ::= Expr4 MulOp Expr5 ;
EAdd. Expr3 ::= Expr3 AddOp Expr4 ;
ERel. Expr2 ::= Expr2 RelOp Expr3 ;
EAnd. Expr1 ::= Expr2 "&&" Expr1 ;
EOr. Expr ::= Expr1 "||" Expr ;
coercions Expr 7 ;
separator Expr "," ;
-- operators -----------------------------------------------
Plus. AddOp ::= "+" ;
Minus. AddOp ::= "-" ;
Times. MulOp ::= "*" ;
Div. MulOp ::= "/" ;
Mod. MulOp ::= "%" ;
LTH. RelOp ::= "<" ;
LE. RelOp ::= "<=" ;
GTH. RelOp ::= ">" ;
GE. RelOp ::= ">=" ;
EQU. RelOp ::= "==" ;
NE. RelOp ::= "!=" ;
-- comments ------------------------------------------------
comment "#" ;
comment "//" ;
comment "/*" "*/" ;
position token PIdent (letter (letter|digit|'_'|'\'')*) ;
-- programs ------------------------------------------------
entrypoints Program ;
Prog. Program ::= [TopDef] ;
FnDef. TopDef ::= Type PIdent "(" [Arg] ")" Block ;
separator nonempty TopDef "" ;
Ar. Arg ::= Type PIdent;
separator Arg "," ;
-- statements ----------------------------------------------
Blk. Block ::= "{" [Stmt] "}" ;
separator Stmt "" ;
Empty. Stmt ::= ";" ;
BStmt. Stmt ::= Block ;
Decl. Stmt ::= Type [Item] ";" ;
NoInit. Item ::= PIdent ;
Init. Item ::= PIdent "=" Expr ;
separator nonempty Item "," ;
Ass. Stmt ::= PIdent "=" Expr ";" ;
Incr. Stmt ::= PIdent "++" ";" ;
Decr. Stmt ::= PIdent "--" ";" ;
Ret. Stmt ::= "return" Expr ";" ;
VRet. Stmt ::= "return" ";" ;
Cond. Stmt ::= "if" "(" Expr ")" Stmt ;
CondElse. Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt ;
While. Stmt ::= "while" "(" Expr ")" Stmt ;
SExp. Stmt ::= Expr ";" ;
-- Types ---------------------------------------------------
Int. Type ::= "int" ;
Str. Type ::= "string" ;
Bool. Type ::= "boolean" ;
Void. Type ::= "void" ;
internal Fun. Type ::= Type "(" [Type] ")" ;
separator Type "," ;
-- Expressions ---------------------------------------------
EVar. Expr6 ::= PIdent ;
ELitInt. Expr6 ::= Integer ;
ELitTrue. Expr6 ::= "true" ;
ELitFalse. Expr6 ::= "false" ;
EApp. Expr6 ::= PIdent "(" [Expr] ")" ;
EString. Expr6 ::= String ;
Neg. Expr5 ::= "-" Expr6 ;
Not. Expr5 ::= "!" Expr6 ;
EMul. Expr4 ::= Expr4 MulOp Expr5 ;
EAdd. Expr3 ::= Expr3 AddOp Expr4 ;
ERel. Expr2 ::= Expr2 RelOp Expr3 ;
EAnd. Expr1 ::= Expr2 "&&" Expr1 ;
EOr. Expr ::= Expr1 "||" Expr ;
coercions Expr 6 ;
separator Expr "," ;
-- operators -----------------------------------------------
Plus. AddOp ::= "+" ;
Minus. AddOp ::= "-" ;
Times. MulOp ::= "*" ;
Div. MulOp ::= "/" ;
Mod. MulOp ::= "%" ;
LTH. RelOp ::= "<" ;
LE. RelOp ::= "<=" ;
GTH. RelOp ::= ">" ;
GE. RelOp ::= ">=" ;
EQU. RelOp ::= "==" ;
NE. RelOp ::= "!=" ;
-- comments ------------------------------------------------
comment "#" ;
comment "//" ;
comment "/*" "*/" ;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment