-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTStyles.txt
139 lines (122 loc) · 2.16 KB
/
ASTStyles.txt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
x = 5
IF x == 6 THEN
PRINT x
ELSEIF x > 0
IF x != 0 THEN
PRINT x + 1
ELSEIF x == 5
PRINT x - 1
ENDIF
ENDIF
myString = "correct output: 6 \n 4"
*/
/*
Target AST
{
Type: "Program",
Tasks:[
{
Type: "Assign",
Assign: {
Variable: {
Type: "Variable",
Value: "x"
},
Expression: {
Type: "Literal",
Value: 5
}
}
},
{
Type: "Conditional",
Loop: false,
Contingency: {
Type: "Compute",
Operator: "==",
Left:{
Type: "Variable",
Value: "x"
},
Right: {
Type: "Literal",
Value: 6
}
},
IfValid: {
Type: "Program",
Tasks:[
{
Type: "Call",
Function: "PRINT",
Arguments: [
{
Type: "Variable",
Value: "x"
}
]
}
]
},
else:
}
]
}
###############################
AST style
Types: PROGRAM, ASSIGN, COMPUTE, CALL, LITERAL, VARIABLE, CONDITIONAL
Program (void)
{
Type: "Program",
Tasks:[
{list of things to do}
]
}
Assign (void)
{
Type: "Assign",
Variable: {see variable ast style},
Expression: {can be a literal expression, computation, or variable}
}
Compute (returns value)
{
Type: "Compute",
Operator: "+,-,/,==,!=,etc"
Left: {some expression} <--- make sure left/right can be 'operator'd'; (left: string, right: int)
Right: {some expression}
}
Call (returns value)
{
Type: "Call",
Function: "function name (Print)",
Arguments:[{expression},{expression}]
}
NumbericalLiteral (returns value)
{
Type: "NumbericalLiteral",
Value: 10.0 <-- all floats for now for simplicty
}
StringLiteral
{
Type: "StringLiteral",
Value: "String Literal"
}
BooleanLiteral
{
Type: "BooleanLiteral",
Value: "String Literal"
}
Variable (returns value)
{
Type: "Variable",
Value: "x"
}
Conditional (void)
{
Type: "Conditional",
Loop: false,
CheckFirst: true,
Contingency: {boolean expression}
IfBlock: {ProgramNode}
Else: {ProgramNode, empty if no else/elseif}
}