-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpasi.cpp
209 lines (197 loc) · 3.95 KB
/
mpasi.cpp
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <iostream>
#include "lexical/LexicalAnalysis.h"
#include "syntatic/SyntaticAnalysis.h"
#include "interpreter/command/Command.h"
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Usage: %s [miniPascal file]\n", argv[0]);
return 1;
}
try {
LexicalAnalysis l(argv[1]);
// O código a seguir é dado para testar o interpretador.
// TODO: descomentar depois que o analisador léxico estiver OK.
/*SyntaticAnalysis s(l);
std::cout << "good1";
Command* c = s.start();
std::cout << "good2";
c->execute();
std::cout << "good3";
delete c;
std::cout << "good4";*/
//teste do syntatic
SyntaticAnalysis s(l);
std::cout << "good1" << std::endl;
s.start();
std::cout << "all good" << std::endl;
/*
// O código a seguir é usado apenas para testar o analisador léxico.
// TODO: depois de pronto, comentar o código abaixo.
struct Lexeme lex;
while ((lex = l.nextToken()).type > 0) {
//printf("(\"%s\", %d)\n", lex.token.str(), lex.type);
std::cout << lex.str() << std::endl;
}
switch (lex.type) {
case TKN_INVALID_TOKEN:
printf("%02d: Invalid Lexeme [%s]\n", l.line(), lex.token.c_str());
break;
case TKN_UNEXPECTED_EOF:
printf("%02d: Fim de arquivo inesperado\n", l.line());
break;
default:
//printf("(\"%s\", %d)\n", lex.token.c_str(), lex.type);
std::cout << "end: " << lex.str() <<"\nok";
break;
}
*/
} catch (std::string msg) {
fprintf(stderr, "Internal error: %s\n", msg.c_str());
std::cout << "Ops: " << msg.c_str();
return 2;
}
return 0;
}
/*
C:\MinGW\msys\1.0\bin>make --directory=C:\Users\ofzbo\Documents\CeFeT_Mg\CEFET\Semestre4\LP\mPascal_interpreter
make: Entering directory `/c/Users/ofzbo/Documents/CeFeT_Mg/CEFET/Semestre4/LP/mPascal_interpreter'
g++ -g -ggdb -O2 -Wall -c -o mpasi.o mpasi.cpp
g++ -o mpasi mpasi.o lexical/SymbolTable.o lexical/LexicalAnalysis.o
make: Leaving directory `/c/Users/ofzbo/Documents/CeFeT_Mg/CEFET/Semestre4/LP/mPascal_interpreter'
C:\Users\ofzbo\Documents\CeFeT_Mg\CEFET\Semestre4\LP\mPascal_interpreter>mpasi triangle.mpas
("(* a program to check triangles' dimensions *)program", 41)
("triangle", 41)
(";", 4)
("const", 20)
("MSG", 41)
("=", 8)
("'Enter the three sizes of a triangle: '", 44)
(";", 4)
("var", 21)
("a", 41)
(",", 2)
("b", 41)
(",", 2)
("c", 41)
(";", 4)
("valid", 41)
("=", 8)
("1", 42)
(";", 4)
("begin", 22)
("repeat", 31)
("write", 35)
("(", 5)
("MSG", 41)
(")", 6)
(";", 4)
("readln", 37)
("(", 5)
("a", 41)
(",", 2)
("b", 41)
(",", 2)
("c", 41)
(")", 6)
(";", 4)
("write", 35)
("(", 5)
("'('", 44)
(",", 2)
("a", 41)
(",", 2)
("', '", 44)
(",", 2)
("b", 41)
(",", 2)
("', '", 44)
(",", 2)
("c", 41)
(",", 2)
("') '", 44)
(")", 6)
(";", 4)
("if", 24)
("(", 5)
("a", 41)
("+", 14)
("b", 41)
(")", 6)
("<=", 12)
("c", 41)
("or", 40)
("(", 5)
("a", 41)
("+", 14)
("c", 41)
(")", 6)
("<=", 12)
("b", 41)
("or", 40)
("(", 5)
("b", 41)
("+", 14)
("c", 41)
(")", 6)
("<=", 12)
("a", 41)
("then", 25)
("begin", 22)
("writeln", 36)
("(", 5)
("'is an invalid triangle'", 44)
(")", 6)
(";", 4)
("valid", 41)
(":=", 7)
("0", 42)
("end", 23)
("else", 26)
("if", 24)
("a", 41)
("=", 8)
("b", 41)
("and", 39)
("b", 41)
("=", 8)
("c", 41)
("then", 25)
("writeln", 36)
("(", 5)
("'is an equilateral triangle'", 44)
(")", 6)
("else", 26)
("if", 24)
("a", 41)
("=", 8)
("b", 41)
("or", 40)
("a", 41)
("=", 8)
("c", 41)
("or", 40)
("b", 41)
("=", 8)
("c", 41)
("then", 25)
("writeln", 36)
("(", 5)
("'is a isosceles triangle'", 44)
(")", 6)
("else", 26)
("writeln", 36)
("(", 5)
("'is a scalene triangle'", 44)
(")", 6)
(";", 4)
("writeln", 36)
("(", 5)
(")", 6)
("until", 32)
("valid", 41)
("=", 8)
("0", 42)
("end", 23)
(".", 1)
("", 0)
*/