diff --git a/.bzrignore b/.bzrignore index 8d1f0a32b6a207d6758709374367c9b170207017..2411d31664cddac4c1bbaeb2231d71ca4dd3d93a 100644 --- a/.bzrignore +++ b/.bzrignore @@ -15,3 +15,4 @@ javadoc SchemaCompile.jar examples/configForm/config-sheet.html examples/x3d/x3d_demo.x3d +examples/x3d/X3DAST diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index 8d43500575a73c8df2e9c3549a5a44648ef3755e..93c42654adeb5ed6e40ca6ee9da6ff5baa8a8a4f 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -9,6 +9,16 @@ import java.io.*; 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 { void ASTNode.genAbsGrammar(PrintStream pStream) { for (int i=0; i<getNumChild(); i++) { diff --git a/GenCompiler.java b/GenCompiler.java index 894ddcee376f224d8770e4886f9c1d9f2e904ec3..b64a7d56028b3650023378af0a6fa9b4279b7674 100644 --- a/GenCompiler.java +++ b/GenCompiler.java @@ -11,63 +11,69 @@ import java.io.File; import java.io.PrintStream; public class GenCompiler extends Parser { - public static void main(String args[]) { + public static void main(String args[]) { String dir = "examples/x3d"; String outName = "x3d"; String[] schema = new String[1]; + String grammarName = new String(); boolean first = true; for (int i=0; i<args.length; i++) { if (args[i].equals("-d")) { dir = args[++i]; - } else if (args[i].equals("-o")) { - outName = args[++i]; - } else { - // OK, we suppose the remaing arg to be parsed. - schema[0] = args[i++]; - } - } + } + if (args[i].equals("-g")) { + grammarName = args[++i]; + } else if (args[i].equals("-o")) { + 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); - if (!siarasDir.isDirectory()) { - siarasDir.mkdir(); - } + File siarasDir = new File(dir); + if (!siarasDir.isDirectory()) { + siarasDir.mkdir(); + } - String fileName = null; - String common = dir+File.separator+outName; - try { - // Generate JastAdd abstract grammar - fileName = common+".ast"; - PrintStream pStream = new PrintStream(new File(fileName)); - ast.genAbsGrammar(pStream); + String fileName = null; + String common = dir+File.separator+outName; + try { + // Generate JastAdd abstract grammar + fileName = common+".ast"; + PrintStream pStream = new PrintStream(new File(fileName)); + ast.genAbsGrammar(pStream); - // Generate JavaCC input - fileName = common+".jjt"; - pStream = new PrintStream(new File(fileName)); - ast.genJavaCC(pStream); + // Generate JavaCC input + fileName = common+".jjt"; + pStream = new PrintStream(new File(fileName)); + ast.genJavaCC(pStream); - // Generate Parser.java - fileName = dir+"/Parser.java"; - pStream = new PrintStream(new File(fileName)); - ast.genParser(pStream); + // Generate Parser.java + fileName = dir+"/Parser.java"; + pStream = new PrintStream(new File(fileName)); + ast.genParser(pStream); - // Generate PrettyPrint.java - fileName = dir+"/PrettyPrint.java"; - pStream = new PrintStream(new File(fileName)); - ast.genPrettyPrint(pStream); + // Generate PrettyPrint.java + fileName = dir+"/PrettyPrint.java"; + pStream = new PrintStream(new File(fileName)); + ast.genPrettyPrint(pStream); - // Generate aspects - fileName = dir+"/GeneratedAspects.jrag"; - pStream = new PrintStream(new File(fileName)); - ast.genAspects(pStream); + // Generate aspects + fileName = dir+"/GeneratedAspects.jrag"; + pStream = new PrintStream(new File(fileName)); + ast.genAspects(pStream); - } catch (java.io.FileNotFoundException e) { - System.out.println("Could not create file: "+fileName); - e.printStackTrace(); - } + } catch (java.io.FileNotFoundException e) { + System.out.println("Could not create file: "+fileName); + e.printStackTrace(); } + } + } diff --git a/JavaCCChunks.jrag b/JavaCCChunks.jrag index 63f36e754ad181cbe7956d309968283d08a4a9cc..b204df4294d9e23c443a5020dc1752b1e7339875 100644 --- a/JavaCCChunks.jrag +++ b/JavaCCChunks.jrag @@ -24,6 +24,7 @@ aspect JavaCCChunks { pStream.println("} "); pStream.println(); pStream.println("PARSER_BEGIN(XmlParser)"); +// pStream.println(" package "+getGrammar()+"AST;"); pStream.println(" package AST;"); pStream.println(" public class XmlParser {"); pStream.println("}");