-
Notifications
You must be signed in to change notification settings - Fork 0
/
instanciation_manuelle_ast.py
34 lines (30 loc) · 1.03 KB
/
instanciation_manuelle_ast.py
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
from ast_iki import *
from visitors.Checker import Checker
from visitors.GraphPrinter import GraphPrinter
from visitors.PrettyPrinter import PrettyPrinter
if __name__ == "__main__":
# Instanciation de l'objet Program
block = Block([
Declaration(Identifier("x"), Type("int")),
Declaration(Identifier("y"), Type("int")),
WhileLoop(
BinaryOperator("-", VarExp(Identifier("y")), Literal(5)),
Block([
Declaration(Identifier("y"), Type("int")),
Read([VarExp(Identifier("x")), VarExp(Identifier("y"))]),
Assignment(
VarExp(Identifier("x")),
BinaryOperator("*", Literal(2), BinaryOperator("+", Literal(3), VarExp(Identifier("y"))))
)
])
),
Write([Literal(5)])
])
program = Program(block)
pp = PrettyPrinter()
program.accept(pp)
ppg = GraphPrinter()
program.accept(ppg)
ppg.graph.render()
checker = Checker()
program.accept(checker)