forked from samshadwell/TrumpScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.txt
35 lines (26 loc) · 1.26 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
Abstract grammar for TrumpScript
{
mod = Module(stmt* body)
stmt = Assign(expr* targets, expr value)
| Print(expr? dest, expr* values, bool nl) <- secretly represented by Call, which makes it an expr
| While(expr test, stmt* body, stmt* orelse)
| If(expr test, stmt* body, stmt* orelse)
| Expr(expr value)
-- BoolOp() can use left & right?
expr = BoolOp(boolop op, expr* values)
| BinOp(expr left, operator op, expr right)
| UnaryOp(unaryop op, expr operand) <- only used for Not
-- need sequences for compare to distinguish between
-- x < 4 < 3 and (x < 4) < 3
| Compare(expr left, cmpop* ops, expr* comparators)
| Call(expr func, expr* args, keyword* keywords, <- not actually used in our grammar
expr? starargs, expr? kwargs)
| Num(object n) -- a number as a PyObject.
| Str(string s) -- need to specify raw, unicode, etc?
| Name(identifier id, expr_context ctx)
expr_context = Load | Store (| Param?) <- not part of our grammar
boolop = And | Or <- are they given their own handlers?
operator = Add | Sub | Mult | Div <- not given their own handlers
unaryop = Not
cmpop = Eq | Lt | Gt (| NotEq | GtE | LtE can all be built using not/or) <- not given their own operation
}