Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
latte
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zygzagZ
latte
Commits
513b2d53
Commit
513b2d53
authored
Dec 10, 2020
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nowe grammary
parent
062c55e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
0 deletions
+149
-0
Grammar2.cf
Grammar2.cf
+84
-0
GrammarOrig.cf
GrammarOrig.cf
+65
-0
No files found.
Grammar2.cf
0 → 100644
View file @
513b2d53
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 "/*" "*/" ;
GrammarOrig.cf
0 → 100644
View file @
513b2d53
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 "/*" "*/" ;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment