-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrammar.java
More file actions
42 lines (39 loc) · 1.44 KB
/
Copy pathGrammar.java
File metadata and controls
42 lines (39 loc) · 1.44 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
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import java.util.Scanner;
public class Grammar{
public static void main(String[] args) throws Exception{
while(true){
System.out.println("");
System.out.println("0. Salir");
System.out.println("1. Calcular Ecuacion");
System.out.println("2. Mostrar Arbol De Ecuacion");
System.out.print("Ingrese una opcion: ");
int opcion = new Scanner(System.in).nextInt();
if(opcion == 0)
break;
if(opcion == 1)
calcularEcuacion(args[0]);
else if(opcion == 2)
mostrarArbol(args[0]);
}
}
public static void calcularEcuacion(String args)throws Exception{
ANTLRFileStream str = new ANTLRFileStream(args);
GrammarLexer lexer = new GrammarLexer(str);
CommonTokenStream tokens = new CommonTokenStream(lexer);
GrammarParser parser = new GrammarParser(tokens);
ParseTree tree = parser.prog();
System.out.println("");
System.out.println(new personalVisitor().visit(tree));
System.out.println("");
}
public static void mostrarArbol(String args){
try {
String cmd = "cmd /c start cmd.exe /K \"grun Grammar prog " + args + " -gui";
Runtime.getRuntime().exec(cmd);
} catch (Exception ex) {
System.out.println(ex);
}
}
}