-
Notifications
You must be signed in to change notification settings - Fork 0
/
EBNF.txt
executable file
·38 lines (38 loc) · 1.5 KB
/
EBNF.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
Class = "public" "class" Identifier "{" ClassBody "}" "EOF".
ClassBody = {VarDec} {MethodDec}.
VarDec = {(PrimDec | RecDec)}.
PrimDec = Type ["[" "]"] Identifier ";".
Type = "int" | "boolean" | "char" | RecType.
RecDec = "class" Identifier "{" {PrimDec} "}".
MethodDec = "public" ("void" | Type ["[" "]"]) Identifier
"(" Param ")" "{" {PrimDec} {Statement} "}".
Statement = "System" "." "out" "." "println" "(" Expression
["+" Expression] ")" ";"
| Assignment ";"
| Identifier "=" Expression ";"
| ProcCall ";"
| "while" "(" Expression ")" (Statement | StatemSeq)
| "if" "(" Expression ")" (Statement | StatemSeq)
["else" (Statement | StatemSeq)]
| "return" [Expression] ";".
Assignment = Identifier [{("[" Expression "]" | "."
Identifier)}] "=" (Allocation | Expression).
Allocation = "new" Type ("(" ")" | "[" Expression "]").
StatemSeq = "{" {Statement} "}".
Param = Type ["[" "]"] Identifier [{"," Type
["[" "]"] Identifier}].
Expression = ["-" Term] { ("+" | "-" | "==" | ">"
| "<" | ">=" | "<=" | "||") Term.
Term = Factor {("*" | "/" | "&&") Factor}.
Factor = ProcCall
| Identifier | Number
| "(" Expression ")"
| "!" Expression
| "true"
| "false".
ProcCall = Identifier "." Identifier "(" [Expression
[{"," Expression}]] ")".
Identifier = Letter [{Letter | Digit}].
Number = ["-"] Digit {Digit}.
Letter = "a" | "b" | ... | "z" | "A" | "B" | ... | "Z".
Digit = "0" | "1" | ... | "9".