-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
48 lines (38 loc) · 1.39 KB
/
Main.java
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
import java.io.*;
import java.util.Scanner;
import java_cup.runtime.Symbol;
public class Main {
public static void main(String[] args) {
try {
String filepath = args[0];
/* Paso el archivo por el analizador lexico */
BufferedReader buffer = new BufferedReader(new FileReader(filepath));
Lexico analizadorJFlex = new Lexico(buffer);
boolean lexical_errors = false;
while (true) {
// Obtener el token analizado
Symbol token = analizadorJFlex.next_token();
// no hay mas tokens que leer
if (token.sym == 0) {
break;
} else if (token.sym == 48) {
// si es un TkError
if (!lexical_errors)
lexical_errors = true;
}
}
// si no ocurre ningun error lexico, paso el archivo al parser
if (!lexical_errors) {
try {
buffer = new BufferedReader(new FileReader(filepath));
parser p = new parser(new Lexico(buffer));
p.parse();
} catch (Exception e) {
System.out.println(e.toString());
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
}