-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammatica_funny.txt
executable file
·51 lines (42 loc) · 1.43 KB
/
grammatica_funny.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
EBNF grammar for Funny
variable *names* start with lowercase, token *names* start with Uppercase.
---- * 0 o più
---- + 1 o più
---- ? 0 o 1
program ::= function Eos .
function ::= "{" optParams optLocals optSequence "}" .
optParams ::= ( "(" optIds ")" )? .
optLocals ::= optIds .
optSequence ::= ( "->" sequence )? .
optIds::= id* .
id ::= Id .
sequence ::= optAssignment ( ";" optAssignment )* .
optAssignment := assignment? .
assignment ::= Id ( "=" | "+=" | "-=" | "*=" | "/=" | "%=" ) assignment
| logicalOr .
logicalOr ::= logicalAnd ( "||" logicalOr )? .
logicalAnd ::= equality ( "&&" logicalAnd )? .
equality ::= comparison ( ( "==" | "!=" ) comparison )? . binary binaryExpr()
comparison ::= add ( ( "<" | "<=" | ">" | ">=" ) add )? . binary
add ::= mult ( ( "+" | "-" ) mult )* . binary
mult ::= unary ( ( "*" | "/" | "%" ) unary )* . binary
unary ::= ( "+" | "-" | "!" ) unary
| postfix .
postfix ::= primary args* .
args ::= "(" ( sequence ( "," sequence )* )? ")" .
primary ::= num | bool | nil | string
| getId
| function
| subsequence
| cond
| loop
| print .
num ::= Num .
bool ::= True | False .
nil ::= Nil .
string ::= String .
getId ::= Id .
subsequence ::= "(" sequence ")" .
cond ::= ( "if" | "ifnot" ) sequence "then" sequence ( "else" sequence )? "fi" .
loop ::= ( "while" | "whilenot" ) sequence ( "do" sequence )? "od" .
print ::= ( "print" | "println" ) args .