-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
58 lines (42 loc) · 2.09 KB
/
grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
program -> moduleDecl decl*
moduleDecl -> "module" IDENT ";"
decl -> ( varDecl | funcDecl | classDecl ) ";"
varDecl -> typedVarDecl | untypedVarDecl
typedVarDecl -> ( IDENT ":" type "=" expr ) | ( IDENT ":" type ":" expr )
untypedVarDecl -> ( IDENT ":" "=" expr ) | ( IDENT ":" ":" expr )
funcDecl -> "func" IDENT "(" parameters? ")" type blockStmt
classDecl -> "class" IDENT classBody
classBody -> "{" ( ( memberDecl | funcDecl ) ";" )* "}"
memberDecl -> IDENT type
parameters -> paramDecl ( "," paramDecl )*
paramDecl -> IDENT type
blockStmt -> "{" stmtList "}"
stmtList -> (stmt ";") *
stmt -> simpleStmt | compoundStmt | varDeclStmt
simpleStmt -> incStmt | reverseStmt | assignment | expr
incStmt -> expr ("++" | "--")
reverseStmt -> ( "reverse" expr ) | ( "reverse" )
assignment -> expr assignOp expr
assignOp -> "=" | "+=" | "*=" | "-=" | "/=" | "**=" | "%="
compoundStmt -> ifStmt | forStmt | skipStmt
ifStmt -> "if" condBlockStmt "else" blockStmt
condBlockStmt -> equality blockStmt
skipStmt -> "skip" "{" blockStmt "}" seizeStmt seizeStmt*
seizeStmt -> ( "seize" expr "{" blockStmt "}" ) | ( "seize" "{" blockStmt "}" )
forStmt -> "for" varDecl ";" expr ";" simpleStmt blockStmt
varDeclStmt -> varDecl
expr -> or
or -> and ( "or" and )*
and -> equality ( "and" equality )*
equality -> comparison ( ( "!=" | "==" ) comparison )*
comparison -> shift ( ( ">" | ">=" | "<" | "<=" ) shift )*
shift -> term ( ( ">>" | "<<" ) term )*
term -> factor ( ( "-" | "+" | "|" | "^" ) factor )*
factor -> unary ( ( "/" | "*" | "&" | "%" ) unary )*
unary -> ( "!" | "-" | "~" ) unary | primary
primary -> atom ( ( "(" arguments? ")" ) | ( "." IDENT ) | ( "[" expr "]" ) )*
atom -> NUMBER | STRING | IDENT | "true" | "false" | group | litlist
group -> "(" expr ")"
litlist -> "[" arguments? "]"
arguments -> expr ( "," expr ) *
type -> IDENT | IDENT ( "." IDENT )*