-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfork.ebnf
More file actions
82 lines (46 loc) · 1.74 KB
/
fork.ebnf
File metadata and controls
82 lines (46 loc) · 1.74 KB
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
program = [module], {import}, { definition }
module = 'module', id
import = 'import', id
definition = entry | function
entry = 'entry', stmtEnd, body, '/entry'
function = 'func', id, '(', argList, ')', [type], stmtEnd, body, '/func'
argList = {argTypeList, ','}, argTypeList
argTypeList = {id, ','}, id, type
body = {stmt}
stmt = (if | while | declaration | expr | return | 'break' | 'continue'), stmtEnd
return = 'return', expr
if = 'if', expr, stmtEnd, body, [elseBlock], '/if'
while = 'while', expr, stmtEnd, breakBody, '/while'
elseBlock = 'else', body
var = 'var', singleVar
decl = 'decl', declType
stmtEnd = newLine | ';'
singleVar = assign | declType
declType = id, type
varDecl = id | assign
assign = id, '=', expr
alias = 'alias', id, type
typeModifier = 'val' | 'ptr' | ('[', number, ']')
funcType = 'func', '(', [type,{',', type}], ')', [type]
structType = 'struct', '(', argList, ')'
type = [typeModifier], (id | funcType | structType)
id = letter, {(letter | cipher)}
membAccess = id, ',', id
arrayAccess = expr, '[', expr, ']'
cast = 'cast', '<', type, '>', '(', expr, ')'
expr = ('(', exprC, ')') | exprC
exprC = dec | inc | id | (expr, binOp, expr) | (unOp,expr) | assign | const | membAccess | cast | arrayAccess
boolVal = 'true' | 'false'
const = number | string |boolVal
string = '"', {letter}, '"'
number = decNumber | binNumber | hexNumber
binOp = '+' | '-' | '*' | '/' | 'and' | 'or' | '==' | '!='
unOp = '-' | '!'
inc = id, '++'
dec = id, '--'
decNumber = ? decimal number ?
hexNumber = ? hexadecimal number like 456h, letters A-F can be both cases, h should be lowcase ?
binNumber = ? binary number like 10101b, b should be lowcase ?
letter = ? any Unicode letter ?
cipher = ? any cipher ?
newLine = ? new line delimiter ?