-
Notifications
You must be signed in to change notification settings - Fork 22
/
grammar.txt
67 lines (52 loc) · 1.45 KB
/
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
/* A simplified BNF grammar for AA suitable for https://smlweb.cpsc.ucalgary.ca/start.html */
Prog -> Stmts.
Stmts ->
/* multiple statements */
Stmt ; Stmts
/* final ; is optional */
| Stmt
/* type expression */
| TStmt
| .
/* 3 variables x,y,z */
Id -> x | y | z.
/* variable assignment; '#' stands in for 'equals' which is part of the meta-grammar */
Stmt -> Id # Ifex
| ret Ifex.
/* type variable assignment */
TStmt -> Id # Type.
/* Ternary logic. A missing ':Stmt' defaults to nil */
Ifex -> Apply
| Apply ? Stmt
| Apply ? Stmt : Stmt.
/* Functional adjecency call goes here, but not implemented in this grammar */
Apply -> Expr.
/* Any collection of binary ops */
Expr -> Term
| Term + Term.
/* Unary ops, both pre and post; also balanced ops. */
Term -> Id ++
| Fact Post.
Post ->
/* .field lookup, using '_' because cannot use '.' */
_ Id Post
/* function call, args in parens followed by another Post */
| ( Id ) Post
/* array lookup the double parens hint at square brackets */
| (( Stmts )) Post
| _ Id ++
/* .field assignment, , using '_' and '#' because cannot use '.' and '=' */
| _ Id # Stmt
| .
Fact ->
Id
/* Any integer, float, string constant */
| 3
| (( Stmts ))
/* Nested grouped statements */
| ( Stmts ) .
Type -> TCon | TVar | TFun .
TVar -> Id .
TCon -> int | flt | str .
TFun ->
(( Id * #~ Type )) .