-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasdl
More file actions
54 lines (45 loc) · 1.95 KB
/
Copy pathasdl
File metadata and controls
54 lines (45 loc) · 1.95 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
-- ASDL's 7 builtin types are:
-- identifier, int, string, bytes, object, singleton, constant
--
module Compiler
{
program = Program(decl* decls)
decl = ConstDecl(basic_type type, expr value)
| VarDecl(basic_type type, int is_array, int size)
| FuncDef(basic_type return_type, decl* args, decl* decls, stmt* stmts)
| ArgDecl(basic_type type)
attributes (identifier name, location loc)
stmt = Read(expr* names)
| Write(expr? str, expr? value)
| Assign(expr target, expr value)
| For(stmt initial, expr condition, stmt step, stmt* body)
| While(expr condition, stmt* body)
| Return(expr? value)
| If(expr test, stmt* body, stmt* orelse)
-- not to conflict with Expr.
| ExprStmt(expr value)
attributes (location loc)
expr = BinOp(expr left, operator op, expr right)
-- expression in parentheses, added for type_check.
-- when a character is in parentheses, it is considered participate in
-- calculation and thus cast to an int.
-- const char a = 'a'; int b; b = (a); is correct because (a) yields an
-- int value which matches that of b.
| ParenExpr(expr value)
-- expression as condition in Grammar, added for type_check.
-- there is no implicit char2int conversion in this context.
| BoolOp(expr value, int has_cmpop)
| UnaryOp(unaryop op, expr operand)
| Call(identifier func, expr* args)
| Num(int n)
| Str(string s)
| Char(int c)
-- the following expression can appear in assignment context
| Subscript(identifier name, expr index, expr_context ctx)
| Name(identifier id, expr_context ctx)
attributes (location loc)
operator = Add | Sub | Mult | Div | Eq | NotEq | Lt | LtE | Gt | GtE
unaryop = UAdd | USub
expr_context = Load | Store
basic_type = Int | Character | Void
}