-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.txt
More file actions
62 lines (61 loc) · 1.64 KB
/
Copy pathgrammar.txt
File metadata and controls
62 lines (61 loc) · 1.64 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
SPL = decl+
decl = | 'type' id '=' decltype ';' | id '(' funDecl | varDecl
funDecl = fargs '(' vardeclList stmt stmtList
| fargs '::' funtype '(' vardeclList stmtList
fargs = ')' | fargs2
fargs2 = id ')' | id ',' fargs2
stmtList = '}' | stmt stmtList
stmt = 'if' '(' exp ')' '{' stmtList 'else' '{' stmtList
| 'if' '(' exp ')' '{' stmtList
| 'while' '(' exp ')' '{' stmtList
| 'return' ';'
| 'return' exp ';'
| id '(' funcall
| id field '=' exp
| 'match' exp 'with' caseList
caseList =
| '|' exp '->' stmtList caseList
| '|' exp '->' stmtList ';'
vardeclList = varDecl*
varDecl = 'var' varDeclRest
| type varDeclRest
varDeclRest = id '=' exp ';'
funtype = '->' rettype | type funtype
decltype = constructor [constructortype] | type
constructortype = '|' constructor [constructortype]
rettype = 'void' | type
type = basictype
| id
| '(' type , type ')'
| '[' type ']'
basictype = 'int' | 'bool' | 'char'
exp = expLogical [opColon exp]
expLogical = expEq [opLogical expLogical]
expEq = expPlus [opEq expEq]
expPlus = expTimes [opPlus expPlus]
expTimes = expStrongest [opTimes expTimes]
expStrongest = int
| char
| 'False'
| 'True'
| '[]'
| id funcall
| id field
| '(' exp ',' exp ')'
| '(' exp ')'
| op1 exp
| '_'
| constructor
funcall = ')' | actargs
actargs = exp ')' | exp ',' actargs
field = '.' fieldtoken [field]
fieldtoken = 'hd' | 'tl' | 'fst' | 'snd'
opColon = ':'
opLogical = '||' | '&&'
opEq = '==' | '>=' | '<=' | '!=' | '<' | '>'
opPlus = '+' | '-'
opTimes = '*' | '/' | '%'
op1 = '!' | '-'
int = digit+
id = lowerAlpha ( '_' | alphaNum )*
constructor = capitalAlpha ('_' | alphaNum)*