Skip to content
Snippets Groups Projects
Commit fc767134 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Fixed some issues with compiler generation.

parent 58f52600
No related branches found
No related tags found
No related merge requests found
...@@ -15,3 +15,4 @@ javadoc ...@@ -15,3 +15,4 @@ javadoc
SchemaCompile.jar SchemaCompile.jar
examples/configForm/config-sheet.html examples/configForm/config-sheet.html
examples/x3d/x3d_demo.x3d examples/x3d/x3d_demo.x3d
examples/x3d/X3DAST
...@@ -9,6 +9,16 @@ ...@@ -9,6 +9,16 @@
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
aspect Misc {
private static String ASTNode.grammar = new String();
public static void ASTNode.setGrammar(String s) {
grammar = s;
}
public static String ASTNode.getGrammar() {
return grammar;
}
}
aspect AbsGrammarGeneration { aspect AbsGrammarGeneration {
void ASTNode.genAbsGrammar(PrintStream pStream) { void ASTNode.genAbsGrammar(PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) { for (int i=0; i<getNumChild(); i++) {
......
...@@ -11,63 +11,69 @@ import java.io.File; ...@@ -11,63 +11,69 @@ import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
public class GenCompiler extends Parser { public class GenCompiler extends Parser {
public static void main(String args[]) { public static void main(String args[]) {
String dir = "examples/x3d"; String dir = "examples/x3d";
String outName = "x3d"; String outName = "x3d";
String[] schema = new String[1]; String[] schema = new String[1];
String grammarName = new String();
boolean first = true; boolean first = true;
for (int i=0; i<args.length; i++) { for (int i=0; i<args.length; i++) {
if (args[i].equals("-d")) { if (args[i].equals("-d")) {
dir = args[++i]; dir = args[++i];
} else if (args[i].equals("-o")) { }
outName = args[++i]; if (args[i].equals("-g")) {
} else { grammarName = args[++i];
// OK, we suppose the remaing arg to be parsed. } else if (args[i].equals("-o")) {
schema[0] = args[i++]; outName = args[++i];
} } else {
} // OK, we suppose the remaing arg to be parsed.
schema[0] = args[i++];
}
}
Start ast = parse(schema);
Start ast = parse(schema); ast.setGrammar(grammarName);
File siarasDir = new File(dir); File siarasDir = new File(dir);
if (!siarasDir.isDirectory()) { if (!siarasDir.isDirectory()) {
siarasDir.mkdir(); siarasDir.mkdir();
} }
String fileName = null; String fileName = null;
String common = dir+File.separator+outName; String common = dir+File.separator+outName;
try { try {
// Generate JastAdd abstract grammar // Generate JastAdd abstract grammar
fileName = common+".ast"; fileName = common+".ast";
PrintStream pStream = new PrintStream(new File(fileName)); PrintStream pStream = new PrintStream(new File(fileName));
ast.genAbsGrammar(pStream); ast.genAbsGrammar(pStream);
// Generate JavaCC input // Generate JavaCC input
fileName = common+".jjt"; fileName = common+".jjt";
pStream = new PrintStream(new File(fileName)); pStream = new PrintStream(new File(fileName));
ast.genJavaCC(pStream); ast.genJavaCC(pStream);
// Generate Parser.java // Generate Parser.java
fileName = dir+"/Parser.java"; fileName = dir+"/Parser.java";
pStream = new PrintStream(new File(fileName)); pStream = new PrintStream(new File(fileName));
ast.genParser(pStream); ast.genParser(pStream);
// Generate PrettyPrint.java // Generate PrettyPrint.java
fileName = dir+"/PrettyPrint.java"; fileName = dir+"/PrettyPrint.java";
pStream = new PrintStream(new File(fileName)); pStream = new PrintStream(new File(fileName));
ast.genPrettyPrint(pStream); ast.genPrettyPrint(pStream);
// Generate aspects // Generate aspects
fileName = dir+"/GeneratedAspects.jrag"; fileName = dir+"/GeneratedAspects.jrag";
pStream = new PrintStream(new File(fileName)); pStream = new PrintStream(new File(fileName));
ast.genAspects(pStream); ast.genAspects(pStream);
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {
System.out.println("Could not create file: "+fileName); System.out.println("Could not create file: "+fileName);
e.printStackTrace(); e.printStackTrace();
}
} }
}
} }
...@@ -24,6 +24,7 @@ aspect JavaCCChunks { ...@@ -24,6 +24,7 @@ aspect JavaCCChunks {
pStream.println("} "); pStream.println("} ");
pStream.println(); pStream.println();
pStream.println("PARSER_BEGIN(XmlParser)"); pStream.println("PARSER_BEGIN(XmlParser)");
// pStream.println(" package "+getGrammar()+"AST;");
pStream.println(" package AST;"); pStream.println(" package AST;");
pStream.println(" public class XmlParser {"); pStream.println(" public class XmlParser {");
pStream.println("}"); pStream.println("}");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment