-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxFunc Grammar.txt
71 lines (56 loc) · 1.95 KB
/
xFunc 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
// It's just a reference grammar for xFunc (The implementation is not completely equal to grammar).
statement = for
/ while
/ exp
def = ('assign') '(' variable ',' exp ')'
undef = ('unassign') '(' variable ')'
if = 'if' '(' conditional ',' exp (',' exp)* ')'
for = 'for' '(' statement ',' exp ',' conditional ',' statement ')'
while = 'while' '(' exp ',' conditional ')'
exp = assign /
ternary
assign = variable (':=', '+=' / '-=' / '*=' / '/=' / '<<=' / '>>=') exp
ternary = conditional ('?' exp ':' exp)*
conditional = bitwise (('&&' / '||') bitwise)*
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / 'impl' / 'eq' / 'nor' / 'nand') equality)*
equality = shift (('==' / '!=' / '<' / '<=' / '>' / '>=') shift)*
shift = addSub (('<<' / '>>') addSub)*
addSub = mulDivMod (('+' / '-') mulDivMod)*
mulDivMod = mulImplicit (('*' / '/' / '%') mulImplicit)*
mulImplicit = mulImplicitLeftUnary / leftUnary
mulImplicitLeftUnary = '-'* number rightUnary
leftUnary = ('~' / '-')* exponentiation
exponentiation = rightUnary ('^' exponentiation)*
rightUnary = incDec
/ factorialOrCallExpression
incDec = variable ('++' / '--')
factorialOrCallExpression = factorial
/ callExp
factorial = (operand '!')
callExp = operand parameters*
operand = complexnumber /
if /
def /
undef /
number /
function /
variable /
boolean /
bracketExp /
lambda /
matrix /
vector
digitWithoutZero = [1-9]
digit = [0] / digitWithoutZero
letter = [a-z]
number = digitWithoutZero (digit)*
id = letter (digit / letter)*
variable = id
boolean = 'true' / 'false'
complexnumber = number '∠' number '°'
bracketExp = '(' exp ')'
function = id '(' parameters ')'
parameters = (statement (',' statement)*)*
vector = ('{' / '(') parameters ('}' / ')')
matrix = ('{' / '(') vector (',' vector) ('}' / ')')
lambda = '(' (id (',' id) / '') ')' '=>' exp