forked from antlr/examples-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython.stg
48 lines (31 loc) · 806 Bytes
/
Python.stg
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
group Python;
program(globals,functions) ::= <<
<functions; separator="\n">
>>
variable(type,name) ::= " "
globalVariable ::= variable
function(type,name,args,locals,stats) ::= <<
def <name>(<args; separator=", ">):
<stats>
>>
type_int() ::= "int"
type_char() ::= "char"
type_user_object(name) ::= "<name>"
parameter(type,name) ::= "<name>"
statement(expr) ::= "<expr>"
statementList(locals,stats) ::= <<
<stats; separator="\n">
>>
// python has a weird FOR, use a WHILE. :)
forLoop(e1,e2,e3,locals,stats) ::= <<
<e1>
while ( <e2> ):
<stats; separator="\n">
<e3>
>>
assign(lhs,rhs) ::= "<lhs> = <rhs>"
equals(left,right) ::= "<left> == <right>"
lessThan(left,right) ::= "<left> \< <right>"
add(left,right) ::= "<left> + <right>"
refVar(id) ::= "<id>"
iconst(value) ::= "<value>"