-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
81 lines (73 loc) · 1.48 KB
/
test.py
File metadata and controls
81 lines (73 loc) · 1.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from proc_comp.parser import parser
from proc_comp.codegen.codegen import CodeGen
import yaml
import json
inp_yaml = """\
name: commands
body:
- name: set-param
param:
variable_name: x
type: Int8
type: Int8
value: 8
- name: binop
result:
variable_name: x
type: Int8
left:
variable_name: x
type: Int8
right:
variable_name: y
type: Int8
operator: Add
"""
inp_json = """\
{
"name": "commands",
"body": [
{
"name": "set-param",
"param": {
"variable_name": "x",
"type": "Int8"
},
"type": "Int8",
"value": 8
},
{
"name": "binop",
"result": {
"variable_name": "x",
"type": "Int8"
},
"left": {
"variable_name": "x",
"type": "Int8"
},
"right": {
"variable_name": "y",
"type": "Int8"
},
"operator": "Add"
}
]
}
"""
obj_yaml = yaml.safe_load(inp_yaml)
obj_json = json.loads(inp_json)
parsed_yaml = parser.parse(obj_yaml)
parsed_json = parser.parse(obj_json)
print('### YAML ###')
print(parsed_yaml.pprint())
print()
G1 = CodeGen()
for l in G1.code_gen(parsed_yaml):
print(l)
print('\n\n### JSON ###')
print(parsed_json.pprint())
print()
G2 = CodeGen()
for l in G2.code_gen(parsed_json):
print(l)