Merged in pa2 and updated test scripts

master
Sanjar Ahmadov 3 years ago
commit 6deb97be81

@ -1,9 +1,11 @@
# Compiler Construction PA3 Worklog
## Team:
**Apoorva Ranade**(ar6496)   **Sanjar Ahmadov**(sa5640)   **Yinqi Sun**(ys3540)
<br>
## Challenges:
- Nested structures were a challenge. A function inside a function/class needs us to build correct scoping as well as dealing with dependencies.
- This is dealt by the class:StackVarRuntimeInfo and function:getStackVar.

@ -0,0 +1,4 @@
#!/bin/bash
./build.sh
./test_sample.sh
./test_benchmarks.sh

@ -0,0 +1,32 @@
## Grading
Core Tests: 59/59
Extra: 21/21
=========================
Standard tests: 80/80
Work Log: 10/10
Additional Tests: 10/10
Code style: 10/10
Improvements: +1
Overall: 111/110
Congratulations! Your analyzer has solved every test case correctly again. Your improvement is solid and easy to verify. The two-passes design is clear and direct.
## Testing
The additional test cases provided in the `student_contributed` directory are carefully selected and well structured. I am surprised that you managed to reproduce those error messages from reference-implementation. Some of them are weird and probably not worth reproducing, but thanks for reducing the workload on my end.
## Miscellaneous
The Code structure is clear and consistent but could still be improved by removing commented codes (at least in the final version).
The automatic test shell scripts are very helpful. It would be even better if you could organize them with CI tools like travis.ci or gitflow. It is totally optional but it would be fun to construct a CI pipeline.
The worklog contains some typos that could be avoided by adding a spellchecker to the IDE or CI.

@ -0,0 +1,24 @@
# Tests for PA1: ChocoPy Parser
Clone a student repository:
```
TEAM="team"
git clone --branch=pa1final \
https://github.com/nyu-compiler-construction/pa1-chocopy-parser-${TEAM}
```
Build it:
```
cd pa1-chocopy-parser-${TEAM}
mvn clean package
```
Clone the tests _into_ the student repository:
```
git clone https://github.com/nyu-compiler-construction/pa1-tests
```
Run the tests:
```
./pa1-tests/run-tests.sh
```

Binary file not shown.

@ -0,0 +1,16 @@
{
"kind" : "Program",
"location" : [ 1, 6, 1, 6 ],
"declarations" : [ ],
"statements" : [ ],
"errors" : {
"errors" : [ {
"kind" : "CompilerError",
"location" : [ 1, 8, 1, 8 ],
"message" : "Parse error near token EQ: =",
"syntax" : true
} ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,16 @@
{
"kind" : "Program",
"location" : [ 1, 7, 1, 7 ],
"declarations" : [ ],
"statements" : [ ],
"errors" : {
"errors" : [ {
"kind" : "CompilerError",
"location" : [ 1, 9, 1, 9 ],
"message" : "Parse error near token EQ: =",
"syntax" : true
} ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,6 @@
def foo(a, b) -> 1:
x:int = a
return 1
print(1)
print(3**6)

@ -0,0 +1,64 @@
{
"kind" : "Program",
"location" : [ 2, 13, 6, 8 ],
"declarations" : [ ],
"statements" : [ {
"kind" : "ExprStmt",
"location" : [ 2, 13, 2, 13 ],
"expr" : {
"kind" : "Identifier",
"location" : [ 2, 13, 2, 13 ],
"name" : "a"
}
}, {
"kind" : "ReturnStmt",
"location" : [ 3, 5, 3, 12 ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 3, 12, 3, 12 ],
"value" : 1
}
}, {
"kind" : "ExprStmt",
"location" : [ 5, 1, 5, 8 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 5, 1, 5, 8 ],
"function" : {
"kind" : "Identifier",
"location" : [ 5, 1, 5, 5 ],
"name" : "print"
},
"args" : [ {
"kind" : "IntegerLiteral",
"location" : [ 5, 7, 5, 7 ],
"value" : 1
} ]
}
} ],
"errors" : {
"errors" : [ {
"kind" : "CompilerError",
"location" : [ 1, 10, 1, 10 ],
"message" : "Parse error near token COMMA: ,",
"syntax" : true
}, {
"kind" : "CompilerError",
"location" : [ 2, 13, 2, 13 ],
"message" : "Parse error near token IDENTIFIER: a",
"syntax" : true
}, {
"kind" : "CompilerError",
"location" : [ 5, 1, 5, 0 ],
"message" : "Parse error near token DEDENT: ",
"syntax" : true
}, {
"kind" : "CompilerError",
"location" : [ 6, 9, 6, 9 ],
"message" : "Parse error near token TIMES: *",
"syntax" : true
} ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,3 @@
x = 1
y = 2
z = 3

@ -0,0 +1,47 @@
{
"kind" : "Program",
"location" : [ 2, 3, 3, 6 ],
"declarations" : [ ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 2, 3, 2, 7 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 2, 3, 2, 3 ],
"name" : "y"
} ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 7, 2, 7 ],
"value" : 2
}
}, {
"kind" : "AssignStmt",
"location" : [ 3, 1, 3, 5 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 3, 1, 3, 1 ],
"name" : "z"
} ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 3, 5, 3, 5 ],
"value" : 3
}
} ],
"errors" : {
"errors" : [ {
"kind" : "CompilerError",
"location" : [ 2, 1, 2, 2 ],
"message" : "Parse error near token INDENT: ",
"syntax" : true
}, {
"kind" : "CompilerError",
"location" : [ 3, 1, 3, 0 ],
"message" : "Parse error near token DEDENT: ",
"syntax" : true
} ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,4 @@
1 + 2
3 == 4 or (not False && True)
5 + 6
7 << 8

@ -0,0 +1,65 @@
{
"kind" : "Program",
"location" : [ 1, 1, 4, 7 ],
"declarations" : [ ],
"statements" : [ {
"kind" : "ExprStmt",
"location" : [ 1, 1, 1, 5 ],
"expr" : {
"kind" : "BinaryExpr",
"location" : [ 1, 1, 1, 5 ],
"left" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 1, 1, 1 ],
"value" : 1
},
"operator" : "+",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 5, 1, 5 ],
"value" : 2
}
}
}, {
"kind" : "ExprStmt",
"location" : [ 3, 1, 3, 5 ],
"expr" : {
"kind" : "BinaryExpr",
"location" : [ 3, 1, 3, 5 ],
"left" : {
"kind" : "IntegerLiteral",
"location" : [ 3, 1, 3, 1 ],
"value" : 5
},
"operator" : "+",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 3, 5, 3, 5 ],
"value" : 6
}
}
}, {
"kind" : "ExprStmt",
"location" : [ 4, 6, 4, 6 ],
"expr" : {
"kind" : "IntegerLiteral",
"location" : [ 4, 6, 4, 6 ],
"value" : 8
}
} ],
"errors" : {
"errors" : [ {
"kind" : "CompilerError",
"location" : [ 2, 22, 2, 22 ],
"message" : "Parse error near token UNRECOGNIZED: &",
"syntax" : true
}, {
"kind" : "CompilerError",
"location" : [ 4, 4, 4, 4 ],
"message" : "Parse error near token LT: <",
"syntax" : true
} ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,2 @@
x[0] = y = z.f = 1
z.g = y = x[0]

@ -0,0 +1,85 @@
{
"kind" : "Program",
"location" : [ 1, 1, 2, 15 ],
"declarations" : [ ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 1, 1, 1, 18 ],
"targets" : [ {
"kind" : "IndexExpr",
"location" : [ 1, 1, 1, 4 ],
"list" : {
"kind" : "Identifier",
"location" : [ 1, 1, 1, 1 ],
"name" : "x"
},
"index" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 3, 1, 3 ],
"value" : 0
}
}, {
"kind" : "Identifier",
"location" : [ 1, 8, 1, 8 ],
"name" : "y"
}, {
"kind" : "MemberExpr",
"location" : [ 1, 12, 1, 14 ],
"object" : {
"kind" : "Identifier",
"location" : [ 1, 12, 1, 12 ],
"name" : "z"
},
"member" : {
"kind" : "Identifier",
"location" : [ 1, 14, 1, 14 ],
"name" : "f"
}
} ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 18, 1, 18 ],
"value" : 1
}
}, {
"kind" : "AssignStmt",
"location" : [ 2, 1, 2, 14 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 2, 1, 2, 3 ],
"object" : {
"kind" : "Identifier",
"location" : [ 2, 1, 2, 1 ],
"name" : "z"
},
"member" : {
"kind" : "Identifier",
"location" : [ 2, 3, 2, 3 ],
"name" : "g"
}
}, {
"kind" : "Identifier",
"location" : [ 2, 7, 2, 7 ],
"name" : "y"
} ],
"value" : {
"kind" : "IndexExpr",
"location" : [ 2, 11, 2, 14 ],
"list" : {
"kind" : "Identifier",
"location" : [ 2, 11, 2, 11 ],
"name" : "x"
},
"index" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 0
}
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,32 @@
{
"kind" : "Program",
"location" : [ 1, 1, 1, 14 ],
"declarations" : [ ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 1, 1, 1, 13 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 1, 1, 1, 1 ],
"name" : "x"
}, {
"kind" : "Identifier",
"location" : [ 1, 5, 1, 5 ],
"name" : "y"
}, {
"kind" : "Identifier",
"location" : [ 1, 9, 1, 9 ],
"name" : "z"
} ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 13, 1, 13 ],
"value" : 1
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,4 @@
class Foo(object):
x:int = 1
f = Foo()

@ -0,0 +1,65 @@
{
"kind" : "Program",
"location" : [ 1, 1, 4, 10 ],
"declarations" : [ {
"kind" : "ClassDef",
"location" : [ 1, 1, 2, 14 ],
"name" : {
"kind" : "Identifier",
"location" : [ 1, 7, 1, 9 ],
"name" : "Foo"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 1, 11, 1, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 2, 5, 2, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 2, 5, 2, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 2, 5, 2, 5 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 2, 7, 2, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 1
}
} ]
} ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 4, 1, 4, 9 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 4, 1, 4, 1 ],
"name" : "f"
} ],
"value" : {
"kind" : "CallExpr",
"location" : [ 4, 5, 4, 9 ],
"function" : {
"kind" : "Identifier",
"location" : [ 4, 5, 4, 7 ],
"name" : "Foo"
},
"args" : [ ]
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,5 @@
class Foo(object):
x:int = 1
f = Foo()
print(f.x)

@ -0,0 +1,91 @@
{
"kind" : "Program",
"location" : [ 1, 1, 5, 11 ],
"declarations" : [ {
"kind" : "ClassDef",
"location" : [ 1, 1, 2, 14 ],
"name" : {
"kind" : "Identifier",
"location" : [ 1, 7, 1, 9 ],
"name" : "Foo"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 1, 11, 1, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 2, 5, 2, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 2, 5, 2, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 2, 5, 2, 5 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 2, 7, 2, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 1
}
} ]
} ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 4, 1, 4, 9 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 4, 1, 4, 1 ],
"name" : "f"
} ],
"value" : {
"kind" : "CallExpr",
"location" : [ 4, 5, 4, 9 ],
"function" : {
"kind" : "Identifier",
"location" : [ 4, 5, 4, 7 ],
"name" : "Foo"
},
"args" : [ ]
}
}, {
"kind" : "ExprStmt",
"location" : [ 5, 1, 5, 10 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 5, 1, 5, 10 ],
"function" : {
"kind" : "Identifier",
"location" : [ 5, 1, 5, 5 ],
"name" : "print"
},
"args" : [ {
"kind" : "MemberExpr",
"location" : [ 5, 7, 5, 9 ],
"object" : {
"kind" : "Identifier",
"location" : [ 5, 7, 5, 7 ],
"name" : "f"
},
"member" : {
"kind" : "Identifier",
"location" : [ 5, 9, 5, 9 ],
"name" : "x"
}
} ]
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,5 @@
class Foo(object):
x:int = 1
f = Foo()
f.x = 2

@ -0,0 +1,87 @@
{
"kind" : "Program",
"location" : [ 1, 1, 5, 8 ],
"declarations" : [ {
"kind" : "ClassDef",
"location" : [ 1, 1, 2, 14 ],
"name" : {
"kind" : "Identifier",
"location" : [ 1, 7, 1, 9 ],
"name" : "Foo"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 1, 11, 1, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 2, 5, 2, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 2, 5, 2, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 2, 5, 2, 5 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 2, 7, 2, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 1
}
} ]
} ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 4, 1, 4, 9 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 4, 1, 4, 1 ],
"name" : "f"
} ],
"value" : {
"kind" : "CallExpr",
"location" : [ 4, 5, 4, 9 ],
"function" : {
"kind" : "Identifier",
"location" : [ 4, 5, 4, 7 ],
"name" : "Foo"
},
"args" : [ ]
}
}, {
"kind" : "AssignStmt",
"location" : [ 5, 1, 5, 7 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 5, 1, 5, 3 ],
"object" : {
"kind" : "Identifier",
"location" : [ 5, 1, 5, 1 ],
"name" : "f"
},
"member" : {
"kind" : "Identifier",
"location" : [ 5, 3, 5, 3 ],
"name" : "x"
}
} ],
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 5, 7, 5, 7 ],
"value" : 2
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,8 @@
class Foo(object):
x:int = 0
def __init__(self:"Foo", x:int):
self.x = x
f = Foo(1)
print(f.x)

@ -0,0 +1,159 @@
{
"kind" : "Program",
"location" : [ 1, 1, 8, 11 ],
"declarations" : [ {
"kind" : "ClassDef",
"location" : [ 1, 1, 7, 0 ],
"name" : {
"kind" : "Identifier",
"location" : [ 1, 7, 1, 9 ],
"name" : "Foo"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 1, 11, 1, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 2, 5, 2, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 2, 5, 2, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 2, 5, 2, 5 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 2, 7, 2, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 0
}
}, {
"kind" : "FuncDef",
"location" : [ 4, 5, 5, 19 ],
"name" : {
"kind" : "Identifier",
"location" : [ 4, 9, 4, 16 ],
"name" : "__init__"
},
"params" : [ {
"kind" : "TypedVar",
"location" : [ 4, 18, 4, 27 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 4, 18, 4, 21 ],
"name" : "self"
},
"type" : {
"kind" : "ClassType",
"location" : [ 4, 23, 4, 27 ],
"className" : "Foo"
}
}, {
"kind" : "TypedVar",
"location" : [ 4, 30, 4, 34 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 4, 30, 4, 30 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 4, 32, 4, 34 ],
"className" : "int"
}
} ],
"returnType" : {
"kind" : "ClassType",
"location" : [ 4, 36, 4, 36 ],
"className" : "<None>"
},
"declarations" : [ ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 5, 9, 5, 18 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 5, 9, 5, 14 ],
"object" : {
"kind" : "Identifier",
"location" : [ 5, 9, 5, 12 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 5, 14, 5, 14 ],
"name" : "x"
}
} ],
"value" : {
"kind" : "Identifier",
"location" : [ 5, 18, 5, 18 ],
"name" : "x"
}
} ]
} ]
} ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 7, 1, 7, 10 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 7, 1, 7, 1 ],
"name" : "f"
} ],
"value" : {
"kind" : "CallExpr",
"location" : [ 7, 5, 7, 10 ],
"function" : {
"kind" : "Identifier",
"location" : [ 7, 5, 7, 7 ],
"name" : "Foo"
},
"args" : [ {
"kind" : "IntegerLiteral",
"location" : [ 7, 9, 7, 9 ],
"value" : 1
} ]
}
}, {
"kind" : "ExprStmt",
"location" : [ 8, 1, 8, 10 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 8, 1, 8, 10 ],
"function" : {
"kind" : "Identifier",
"location" : [ 8, 1, 8, 5 ],
"name" : "print"
},
"args" : [ {
"kind" : "MemberExpr",
"location" : [ 8, 7, 8, 9 ],
"object" : {
"kind" : "Identifier",
"location" : [ 8, 7, 8, 7 ],
"name" : "f"
},
"member" : {
"kind" : "Identifier",
"location" : [ 8, 9, 8, 9 ],
"name" : "x"
}
} ]
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,9 @@
class Foo(object):
x:int = 0
def set(self:"Foo", x:int) -> object:
self.x = x
f = Foo()
f.set(1)
print(f.x)

@ -0,0 +1,181 @@
{
"kind" : "Program",
"location" : [ 1, 1, 9, 11 ],
"declarations" : [ {
"kind" : "ClassDef",
"location" : [ 1, 1, 7, 0 ],
"name" : {
"kind" : "Identifier",
"location" : [ 1, 7, 1, 9 ],
"name" : "Foo"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 1, 11, 1, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 2, 5, 2, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 2, 5, 2, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 2, 5, 2, 5 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 2, 7, 2, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 2, 13, 2, 13 ],
"value" : 0
}
}, {
"kind" : "FuncDef",
"location" : [ 4, 5, 5, 19 ],
"name" : {
"kind" : "Identifier",
"location" : [ 4, 9, 4, 11 ],
"name" : "set"
},
"params" : [ {
"kind" : "TypedVar",
"location" : [ 4, 13, 4, 22 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 4, 13, 4, 16 ],
"name" : "self"
},
"type" : {
"kind" : "ClassType",
"location" : [ 4, 18, 4, 22 ],
"className" : "Foo"
}
}, {
"kind" : "TypedVar",
"location" : [ 4, 25, 4, 29 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 4, 25, 4, 25 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 4, 27, 4, 29 ],
"className" : "int"
}
} ],
"returnType" : {
"kind" : "ClassType",
"location" : [ 4, 35, 4, 40 ],
"className" : "object"
},
"declarations" : [ ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 5, 9, 5, 18 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 5, 9, 5, 14 ],
"object" : {
"kind" : "Identifier",
"location" : [ 5, 9, 5, 12 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 5, 14, 5, 14 ],
"name" : "x"
}
} ],
"value" : {
"kind" : "Identifier",
"location" : [ 5, 18, 5, 18 ],
"name" : "x"
}
} ]
} ]
} ],
"statements" : [ {
"kind" : "AssignStmt",
"location" : [ 7, 1, 7, 9 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 7, 1, 7, 1 ],
"name" : "f"
} ],
"value" : {
"kind" : "CallExpr",
"location" : [ 7, 5, 7, 9 ],
"function" : {
"kind" : "Identifier",
"location" : [ 7, 5, 7, 7 ],
"name" : "Foo"
},
"args" : [ ]
}
}, {
"kind" : "ExprStmt",
"location" : [ 8, 1, 8, 8 ],
"expr" : {
"kind" : "MethodCallExpr",
"location" : [ 8, 1, 8, 8 ],
"method" : {
"kind" : "MemberExpr",
"location" : [ 8, 1, 8, 5 ],
"object" : {
"kind" : "Identifier",
"location" : [ 8, 1, 8, 1 ],
"name" : "f"
},
"member" : {
"kind" : "Identifier",
"location" : [ 8, 3, 8, 5 ],
"name" : "set"
}
},
"args" : [ {
"kind" : "IntegerLiteral",
"location" : [ 8, 7, 8, 7 ],
"value" : 1
} ]
}
}, {
"kind" : "ExprStmt",
"location" : [ 9, 1, 9, 10 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 9, 1, 9, 10 ],
"function" : {
"kind" : "Identifier",
"location" : [ 9, 1, 9, 5 ],
"name" : "print"
},
"args" : [ {
"kind" : "MemberExpr",
"location" : [ 9, 7, 9, 9 ],
"object" : {
"kind" : "Identifier",
"location" : [ 9, 7, 9, 7 ],
"name" : "f"
},
"member" : {
"kind" : "Identifier",
"location" : [ 9, 9, 9, 9 ],
"name" : "x"
}
} ]
}
} ],
"errors" : {
"errors" : [ ],
"kind" : "Errors",
"location" : [ 0, 0, 0, 0 ]
}
}

@ -0,0 +1,38 @@
count:int = 0
def foo(s: str) -> int:
return len(s)
class bar(object):
p: bool = True
def baz(self:"bar", xx: [int]) -> str:
global count
x:int = 0
y:int = 1
def qux(y: int) -> object:
nonlocal x
if x > y:
x = -1
for x in xx:
self.p = x == 2
qux(0) # Yay! ChocoPy
count = count + 1
while x <= 0:
if self.p:
xx[0] = xx[1]
self.p = not self.p
x = x + 1
elif foo("Long"[0]) == 1:
return self is None
return "Nope"
print(bar().baz([1,2]))

@ -0,0 +1,613 @@
{
"kind" : "Program",
"location" : [ 1, 1, 36, 24 ],
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 1, 1, 1, 13 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 1, 1, 1, 9 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 1, 1, 1, 5 ],
"name" : "count"
},
"type" : {
"kind" : "ClassType",
"location" : [ 1, 7, 1, 9 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 1, 13, 1, 13 ],
"value" : 0
}
}, {
"kind" : "FuncDef",
"location" : [ 3, 1, 4, 18 ],
"name" : {
"kind" : "Identifier",
"location" : [ 3, 5, 3, 7 ],
"name" : "foo"
},
"params" : [ {
"kind" : "TypedVar",
"location" : [ 3, 9, 3, 14 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 3, 9, 3, 9 ],
"name" : "s"
},
"type" : {
"kind" : "ClassType",
"location" : [ 3, 12, 3, 14 ],
"className" : "str"
}
} ],
"returnType" : {
"kind" : "ClassType",
"location" : [ 3, 20, 3, 22 ],
"className" : "int"
},
"declarations" : [ ],
"statements" : [ {
"kind" : "ReturnStmt",
"location" : [ 4, 5, 4, 17 ],
"value" : {
"kind" : "CallExpr",
"location" : [ 4, 12, 4, 17 ],
"function" : {
"kind" : "Identifier",
"location" : [ 4, 12, 4, 14 ],
"name" : "len"
},
"args" : [ {
"kind" : "Identifier",
"location" : [ 4, 16, 4, 16 ],
"name" : "s"
} ]
}
} ]
}, {
"kind" : "ClassDef",
"location" : [ 6, 1, 36, 0 ],
"name" : {
"kind" : "Identifier",
"location" : [ 6, 7, 6, 9 ],
"name" : "bar"
},
"superClass" : {
"kind" : "Identifier",
"location" : [ 6, 11, 6, 16 ],
"name" : "object"
},
"declarations" : [ {
"kind" : "VarDef",
"location" : [ 7, 5, 7, 18 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 7, 5, 7, 11 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 7, 5, 7, 5 ],
"name" : "p"
},
"type" : {
"kind" : "ClassType",
"location" : [ 7, 8, 7, 11 ],
"className" : "bool"
}
},
"value" : {
"kind" : "BooleanLiteral",
"location" : [ 7, 15, 7, 18 ],
"value" : true
}
}, {
"kind" : "FuncDef",
"location" : [ 9, 5, 34, 22 ],
"name" : {
"kind" : "Identifier",
"location" : [ 9, 9, 9, 11 ],
"name" : "baz"
},
"params" : [ {
"kind" : "TypedVar",
"location" : [ 9, 13, 9, 22 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 9, 13, 9, 16 ],
"name" : "self"
},
"type" : {
"kind" : "ClassType",
"location" : [ 9, 18, 9, 22 ],
"className" : "bar"
}
}, {
"kind" : "TypedVar",
"location" : [ 9, 25, 9, 33 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 9, 25, 9, 26 ],
"name" : "xx"
},
"type" : {
"kind" : "ListType",
"location" : [ 9, 29, 9, 33 ],
"elementType" : {
"kind" : "ClassType",
"location" : [ 9, 30, 9, 32 ],
"className" : "int"
}
}
} ],
"returnType" : {
"kind" : "ClassType",
"location" : [ 9, 39, 9, 41 ],
"className" : "str"
},
"declarations" : [ {
"kind" : "GlobalDecl",
"location" : [ 10, 9, 10, 20 ],
"variable" : {
"kind" : "Identifier",
"location" : [ 10, 16, 10, 20 ],
"name" : "count"
}
}, {
"kind" : "VarDef",
"location" : [ 11, 9, 11, 17 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 11, 9, 11, 13 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 11, 9, 11, 9 ],
"name" : "x"
},
"type" : {
"kind" : "ClassType",
"location" : [ 11, 11, 11, 13 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 11, 17, 11, 17 ],
"value" : 0
}
}, {
"kind" : "VarDef",
"location" : [ 12, 9, 12, 17 ],
"var" : {
"kind" : "TypedVar",
"location" : [ 12, 9, 12, 13 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 12, 9, 12, 9 ],
"name" : "y"
},
"type" : {
"kind" : "ClassType",
"location" : [ 12, 11, 12, 13 ],
"className" : "int"
}
},
"value" : {
"kind" : "IntegerLiteral",
"location" : [ 12, 17, 12, 17 ],
"value" : 1
}
}, {
"kind" : "FuncDef",
"location" : [ 14, 9, 19, 8 ],
"name" : {
"kind" : "Identifier",
"location" : [ 14, 13, 14, 15 ],
"name" : "qux"
},
"params" : [ {
"kind" : "TypedVar",
"location" : [ 14, 17, 14, 22 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 14, 17, 14, 17 ],
"name" : "y"
},
"type" : {
"kind" : "ClassType",
"location" : [ 14, 20, 14, 22 ],
"className" : "int"
}
} ],
"returnType" : {
"kind" : "ClassType",
"location" : [ 14, 28, 14, 33 ],
"className" : "object"
},
"declarations" : [ {
"kind" : "NonLocalDecl",
"location" : [ 15, 13, 15, 22 ],
"variable" : {
"kind" : "Identifier",
"location" : [ 15, 22, 15, 22 ],
"name" : "x"
}
} ],
"statements" : [ {
"kind" : "IfStmt",
"location" : [ 16, 13, 19, 8 ],
"condition" : {
"kind" : "BinaryExpr",
"location" : [ 16, 16, 16, 20 ],
"left" : {
"kind" : "Identifier",
"location" : [ 16, 16, 16, 16 ],
"name" : "x"
},
"operator" : ">",
"right" : {
"kind" : "Identifier",
"location" : [ 16, 20, 16, 20 ],
"name" : "y"
}
},
"thenBody" : [ {
"kind" : "AssignStmt",
"location" : [ 17, 17, 17, 22 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 17, 17, 17, 17 ],
"name" : "x"
} ],
"value" : {
"kind" : "UnaryExpr",
"location" : [ 17, 21, 17, 22 ],
"operator" : "-",
"operand" : {
"kind" : "IntegerLiteral",
"location" : [ 17, 22, 17, 22 ],
"value" : 1
}
}
} ],
"elseBody" : [ ]
} ]
} ],
"statements" : [ {
"kind" : "ForStmt",
"location" : [ 19, 9, 22, 8 ],
"identifier" : {
"kind" : "Identifier",
"location" : [ 19, 13, 19, 13 ],
"name" : "x"
},
"iterable" : {
"kind" : "Identifier",
"location" : [ 19, 18, 19, 19 ],
"name" : "xx"
},
"body" : [ {
"kind" : "AssignStmt",
"location" : [ 20, 13, 20, 27 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 20, 13, 20, 18 ],
"object" : {
"kind" : "Identifier",
"location" : [ 20, 13, 20, 16 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 20, 18, 20, 18 ],
"name" : "p"
}
} ],
"value" : {
"kind" : "BinaryExpr",
"location" : [ 20, 22, 20, 27 ],
"left" : {
"kind" : "Identifier",
"location" : [ 20, 22, 20, 22 ],
"name" : "x"
},
"operator" : "==",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 20, 27, 20, 27 ],
"value" : 2
}
}
} ]
}, {
"kind" : "ExprStmt",
"location" : [ 22, 9, 22, 14 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 22, 9, 22, 14 ],
"function" : {
"kind" : "Identifier",
"location" : [ 22, 9, 22, 11 ],
"name" : "qux"
},
"args" : [ {
"kind" : "IntegerLiteral",
"location" : [ 22, 13, 22, 13 ],
"value" : 0
} ]
}
}, {
"kind" : "AssignStmt",
"location" : [ 24, 9, 24, 25 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 24, 9, 24, 13 ],
"name" : "count"
} ],
"value" : {
"kind" : "BinaryExpr",
"location" : [ 24, 17, 24, 25 ],
"left" : {
"kind" : "Identifier",
"location" : [ 24, 17, 24, 21 ],
"name" : "count"
},
"operator" : "+",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 24, 25, 24, 25 ],
"value" : 1
}
}
}, {
"kind" : "WhileStmt",
"location" : [ 26, 9, 34, 8 ],
"condition" : {
"kind" : "BinaryExpr",
"location" : [ 26, 15, 26, 20 ],
"left" : {
"kind" : "Identifier",
"location" : [ 26, 15, 26, 15 ],
"name" : "x"
},
"operator" : "<=",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 26, 20, 26, 20 ],
"value" : 0
}
},
"body" : [ {
"kind" : "IfStmt",
"location" : [ 27, 13, 34, 8 ],
"condition" : {
"kind" : "MemberExpr",
"location" : [ 27, 16, 27, 21 ],
"object" : {
"kind" : "Identifier",
"location" : [ 27, 16, 27, 19 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 27, 21, 27, 21 ],
"name" : "p"
}
},
"thenBody" : [ {
"kind" : "AssignStmt",
"location" : [ 28, 17, 28, 29 ],
"targets" : [ {
"kind" : "IndexExpr",
"location" : [ 28, 17, 28, 21 ],
"list" : {
"kind" : "Identifier",
"location" : [ 28, 17, 28, 18 ],
"name" : "xx"
},
"index" : {
"kind" : "IntegerLiteral",
"location" : [ 28, 20, 28, 20 ],
"value" : 0
}
} ],
"value" : {
"kind" : "IndexExpr",
"location" : [ 28, 25, 28, 29 ],
"list" : {
"kind" : "Identifier",
"location" : [ 28, 25, 28, 26 ],
"name" : "xx"
},
"index" : {
"kind" : "IntegerLiteral",
"location" : [ 28, 28, 28, 28 ],
"value" : 1
}
}
}, {
"kind" : "AssignStmt",
"location" : [ 29, 17, 29, 35 ],
"targets" : [ {
"kind" : "MemberExpr",
"location" : [ 29, 17, 29, 22 ],
"object" : {
"kind" : "Identifier",
"location" : [ 29, 17, 29, 20 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 29, 22, 29, 22 ],
"name" : "p"
}
} ],
"value" : {
"kind" : "UnaryExpr",
"location" : [ 29, 26, 29, 35 ],
"operator" : "not",
"operand" : {
"kind" : "MemberExpr",
"location" : [ 29, 30, 29, 35 ],
"object" : {
"kind" : "Identifier",
"location" : [ 29, 30, 29, 33 ],
"name" : "self"
},
"member" : {
"kind" : "Identifier",
"location" : [ 29, 35, 29, 35 ],
"name" : "p"
}
}
}
}, {
"kind" : "AssignStmt",
"location" : [ 30, 17, 30, 25 ],
"targets" : [ {
"kind" : "Identifier",
"location" : [ 30, 17, 30, 17 ],
"name" : "x"
} ],
"value" : {
"kind" : "BinaryExpr",
"location" : [ 30, 21, 30, 25 ],
"left" : {
"kind" : "Identifier",
"location" : [ 30, 21, 30, 21 ],
"name" : "x"
},
"operator" : "+",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 30, 25, 30, 25 ],
"value" : 1
}
}
} ],
"elseBody" : [ {
"kind" : "IfStmt",
"location" : [ 31, 13, 34, 8 ],
"condition" : {
"kind" : "BinaryExpr",
"location" : [ 31, 18, 31, 36 ],
"left" : {
"kind" : "CallExpr",
"location" : [ 31, 18, 31, 31 ],
"function" : {
"kind" : "Identifier",
"location" : [ 31, 18, 31, 20 ],
"name" : "foo"
},
"args" : [ {
"kind" : "IndexExpr",
"location" : [ 31, 22, 31, 30 ],
"list" : {
"kind" : "StringLiteral",
"location" : [ 31, 22, 31, 27 ],
"value" : "Long"
},
"index" : {
"kind" : "IntegerLiteral",
"location" : [ 31, 29, 31, 29 ],
"value" : 0
}
} ]
},
"operator" : "==",
"right" : {
"kind" : "IntegerLiteral",
"location" : [ 31, 36, 31, 36 ],
"value" : 1
}
},
"thenBody" : [ {
"kind" : "ReturnStmt",
"location" : [ 32, 17, 32, 35 ],
"value" : {
"kind" : "BinaryExpr",
"location" : [ 32, 24, 32, 35 ],
"left" : {
"kind" : "Identifier",
"location" : [ 32, 24, 32, 27 ],
"name" : "self"
},
"operator" : "is",
"right" : {
"kind" : "NoneLiteral",
"location" : [ 32, 32, 32, 35 ]
}
}
} ],
"elseBody" : [ ]
} ]
} ]
}, {
"kind" : "ReturnStmt",
"location" : [ 34, 9, 34, 21 ],
"value" : {
"kind" : "StringLiteral",
"location" : [ 34, 16, 34, 21 ],
"value" : "Nope"
}
} ]
} ]
} ],
"statements" : [ {
"kind" : "ExprStmt",
"location" : [ 36, 1, 36, 23 ],
"expr" : {
"kind" : "CallExpr",
"location" : [ 36, 1, 36, 23 ],
"function" : {
"kind" : "Identifier",
"location" : [ 36, 1, 36, 5 ],
"name" : "print"
},
"args" : [ {
"kind" : "MethodCallExpr",
"location" : [ 36, 7, 36, 22 ],
"method" : {
"kind" : "MemberExpr",
"location" : [ 36, 7, 36, 15 ],
"object" : {
"kind" : "CallExpr",
"location" : [ 36, 7, 36, 11 ],
"function" : {
"kind" : "Identifier",
"location" : [ 36, 7, 36, 9 ],
"name" : "bar"
},
"args" : [ ]
},
"member" : {
"kind" : "Identifier",
"location" : [ 36, 13, 36, 15 ],
"name" : "baz"
}
},
"args" : [ {
"kind" : "ListExpr",
"location" : [ 36, 17, 36, 21 ],
"elements" : [ {
"kind" : "IntegerLiteral",
"location" : [ 36, 18, 36, 18 ],
"value" : 1
}, {
"kind" : "IntegerLiteral",
"location" : [ 36, 20, 36, 20 ],
"value" : 2
} ]
} ]
} ]