From fc76713419276fe5d6eede25468d63487d693e92 Mon Sep 17 00:00:00 2001 From: Anders Nilsson <andersn@gosling> Date: Wed, 19 Sep 2007 09:11:56 +0200 Subject: [PATCH] Fixed some issues with compiler generation. --- .bzrignore | 1 + CompilerGeneration.jrag | 10 +++++ GenCompiler.java | 86 ++++++++++++++++++++++------------------- JavaCCChunks.jrag | 1 + 4 files changed, 58 insertions(+), 40 deletions(-) diff --git a/.bzrignore b/.bzrignore index 8d1f0a3..2411d31 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 8d43500..93c4265 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 894ddce..b64a7d5 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 63f36e7..b204df4 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("}"); -- GitLab