This repository was archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammar.txt
77 lines (69 loc) · 3.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
program -> declaration* EOF
| "start" declaration* "stop"
declaration -> classDeclaration
| variableDeclaration
| statement
classDeclaration -> "class" IDENTIFIER "extends" IDENTIFIER
memberDeclaration*
"endclass"
memberDeclaration -> ( ( "public" | "private" | "protected" ) variableDeclaration )*
variableDeclaration -> ( "num" | "string" | "boolean" ) IDENTIFIER ( "=" expression )? ";"
| functionDeclaration
functionDeclaration -> ( "void" | "num" | "string" | "boolean" ) IDENTIFIER
"("parameters? ")" "=>" statement
| ( "void" | "num" | "string" | "boolean" ) IDENTIFIER
"("parameters? ")" declaration* "endfunc"
statement -> expressionStatement
| outputStatement
| simpleBlock
| curlBlock
| ifStatement
| whileStatement
| forStatement
| inputStatement
simpleBlock -> "block" declaration* "endblock"
curlBlock -> "{" declaration* "}"
ifStatement -> "if" "(" expression ")" "=>" statement
| "if" "(" expression ")"
declaration*
("elseif" declaration*)*
("else" declaration*)?
"endif"
whileStatement -> "while" "(" expression ")" "=>" statement
-> "while" "(" expression ")" declaration* "endwhile"
forStatement -> "for"
"(" ( variableDeclaration | expressionStatement | ";" )
expression? ";"
expression?
")" "=>" statement
| "for"
"(" ( variableDeclaration | expressionStatement | ";" )
expression? ";"
expression?
")" declaration* "endfor"
outputStatement -> "output" expression ";"
inputStatement -> "input" IDENTIFIER ";"
expressionStatement -> expression ";"
expression -> assignment
assignment -> "set" ( call "->" )? IDENTIFIER "=" assignment
| logicOr
logicOr -> logicAnd ( "or" | "||" logicAnd )*
logicAnd -> logicEqual ( "and" | "&&" logicEqual )*
logicEqual -> comparison ( ( "!=" | "==" ) comparison )*
comparison -> term ( ( ">" | ">=" | "<" | "<=" ) term )*
term -> factor ( ( "+" | "-" ) factor )*
factor -> power ( ( "*" | "/" | "%" ) power )*
power -> unary ( "^" unary )*
unary -> ( "!" | "-" ) unary
| prefix
prefix -> ( "++" | "--" ) prefix
| postfix
postfix -> call ( "++" | "--" )*
call -> "new" primary "(" arguments* ")"
| primary ( "(" arguments ")" )*
primary -> literal | grouping | IDENTIFIER
grouping -> "(" expression ")"
literal -> NUMBER | STRING | BOOLEAN | "this"
operator -> "==" | "!=" | ">" | ">=" | "<" | "<="
| "+" | "-" | "*" | "/" | "%" | "^"
| "."