-
Notifications
You must be signed in to change notification settings - Fork 1
/
JoaoGrammar.txt
86 lines (51 loc) · 2.39 KB
/
JoaoGrammar.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
78
79
80
81
82
83
84
85
86
Here is the complete syntax of João in extended BNF. As usual in extended BNF, {A} means 0 or more As, and [A] means an optional A. Brace characters are escaped with single-quotes.
program ::= {classdef | funcdef | includefile}
repl ::= {funcdef | stat | exp}
includefile ::== 'include ' LiteralString
classdef ::= directory '{' {varstat ';'} '}'
funcdef ::= directory '(' [parlist] '){' block '}'
directory ::= '/'{Name'/'}Name
parlist ::= Name {','Name} [',']
varstat :: init_var | (var assignop exp)
block ::= {stat}
stat ::= ';' |
varstat ';' |
functioncall ';' |
'return' [exp] ';' |
'break' [PositiveInteger] ';' |
'continue;' |
'while(' exp '){' block '}' |
'if(' exp '){' block '}' {'elseif(' exp '){' block '}'} ['else(' exp '){' block '}'] |
'for('for_generic_init | for_each_init'){' block '}' |
'try{' block '}catch(' Name '){' block '}' |
'throw' [exp] ';'
for_generic_init ::= '[varstat | exp] ';' [exp] ';' [varstat | exp]
for_each_init ::= Name ',' Name ' in ' exp
init_var ::= ('Value' | 'Object' | 'Number' | 'String' | 'Boolean') Name
var ::= init_var | var_access
var_access ::= scoped_access | var_access property | var_access element
scoped_access ::= './' Name |
{'../'}'../' Name |
'/' Name |
Name
functioncall ::= var_access '(' explist ')' [func_access]
func_access ::= (property | element)['(' explist ')'][func_access]
property ::= {'.' Name }
element ::= {'[' exp ']'}
explist ::= exp {, exp}
exp ::= comparison {('&&' | '||' | '~~') comparison}
comparison ::= bitwise {(‘<’ | ‘<=’ | ‘>’ | ‘>=’ | ‘==’ | ‘!=’) bitwise}
bitwise ::= concat {(‘&’ | ‘~’ | ‘|’ | ‘>>’ | ‘<<’) concat}
concat ::= term {'..' term}
term ::= factor {(‘+’ | ‘-’) factor}
factor ::= unary {(‘*’ | ‘/’ | ‘//’| ‘%’) unary}
unary ::= {unop} power
power ::= {lvalue '^'} lvalue
lvalue ::= 'null' | 'false' | 'true' | Numeral | LiteralString |
tableconstructor | var_access | functioncall | '(' exp ')' | constructor | constexpr
constructor ::= directory '/New(' [explist] ')' [func_access]
tableconstructor ::= '{' [exp] {',' exp} [',']'}' |
'{' [(Name | LiteralString) '=' exp] {',' [(Name | LiteralString) '=' exp]}[','] '}'
assignop ::= '=' | '+=' | '-=' | '*=' | '/='
unop ::= ‘-’ | '!' | ‘#’ | ‘~’
constexpr ::= 'const{' [block] '}'