Select Git revision
Hepial.java
Hepial.java 2.04 KiB
/*
* Main program that launch the parsing.
*/
import java.io.FileReader;
public class Hepial {
public static void main(String[] arg) {
try {
String filePath = "";
String mode = "";
switch (arg.length) {
case 1:
filePath = arg[0];
mode = "genbytecode";
break;
case 2:
filePath = arg[0];
mode = arg[1];
break;
default:
throw new Exception("Usage : prg [filePath] [genbytecode | gensourcecode]");
}
parser myP = new parser(new HepialLexer(new FileReader(filePath)));
try {
DeclarationProgramme program = (DeclarationProgramme)myP.parse().value;
if (program == null)
return;
program.accept(new SemanticAnalyzer());
switch(mode){
case "genbytecode":
ByteCodeGenerator codeGenerator = new ByteCodeGenerator();
program.accept(codeGenerator);
System.out.println(codeGenerator.getByteCode());
break;
case "gensourcecode":
SourceCodeGenerator sourceGenerator = new SourceCodeGenerator();
program.accept(sourceGenerator);
System.out.println(sourceGenerator.getCode());
break;
default:
throw new Exception("Unrecognized running mode: '" + mode + "'");
}
} catch (Exception e) {
//le contenu du fichier est incorrect
System.out.println("Parse error: " + e);
e.printStackTrace();
}
} catch (Exception e) {
//le contenu du fichier est incorrect
System.out.println("Invalid file: " + e);
e.printStackTrace();
}
}
}