From 54ff7e2bcb45be4294ddf39a2a1d40ccda730356 Mon Sep 17 00:00:00 2001 From: Anders Nilsson <anders.nilsson@cs.lth.se> Date: Fri, 17 Aug 2007 16:38:56 +0200 Subject: [PATCH] Cleaned up main program and made it possible to control naming an d placement of generated code. Created a README --- GenCompiler.java | 33 ++++++++++++++++++++++++++------- README | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 README diff --git a/GenCompiler.java b/GenCompiler.java index aa8e143..084bba2 100644 --- a/GenCompiler.java +++ b/GenCompiler.java @@ -12,37 +12,56 @@ import java.io.PrintStream; public class GenCompiler extends Parser { public static void main(String args[]) { - Start ast = parse(args); - File siarasDir = new File("x3d"); + String dir = "x3d"; + String outName = "x3d"; + String[] schema = new String[1]; + 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++]; + } + } + + + Start ast = parse(schema); + + 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 = "x3d/x3d.ast"; + fileName = common+".ast"; PrintStream pStream = new PrintStream(new File(fileName)); ast.genAbsGrammar(pStream); // Generate JavaCC input - fileName = "x3d/x3d.jjt"; + fileName = common+".jjt"; pStream = new PrintStream(new File(fileName)); ast.genJavaCC(pStream); // Generate Parser.java - fileName = "x3d/Parser.java"; + fileName = dir+"/Parser.java"; pStream = new PrintStream(new File(fileName)); ast.genParser(pStream); // Generate PrettyPrint.java - fileName = "x3d/PrettyPrint.java"; + fileName = dir+"/PrettyPrint.java"; pStream = new PrintStream(new File(fileName)); ast.genPrettyPrint(pStream); // Generate aspects - fileName = "x3d/GeneratedAspects.jrag"; + fileName = dir+"/GeneratedAspects.jrag"; pStream = new PrintStream(new File(fileName)); ast.genAspects(pStream); diff --git a/README b/README new file mode 100644 index 0000000..e0379c3 --- /dev/null +++ b/README @@ -0,0 +1,32 @@ + + +ABOUT + +The main purpose of the Schemacompiler is to automatically generate +compiler front-ends for different XML dialects. Given an XML schema, +the schemacompiler will generate an abstract grammar and some aspect +code for JastAdd, as well as a JavaCC parser description. The +generated compiler may then be extended with more aspects, and +possibly new abstract grammar rules, to form a complete compiler. + + +USAGE + +$ java GenCompiler [-d dir] [-o outfile] schema + +options: + -d dir directory where generated files are put. + Will be created if not already exists. + Default is 'x3d'. + + -o outfile Name for generated grammar files. + Default is 'x3d'. + +'$ java GenCompiler examples/x3d-3.0.xsd' will generate a compiler for +x3d in the x3d subdirectory. x3d/build.xml should be studied as an +example on how to use the generated code. + + +AUTHOR + +Anders Nilsson <anders.nilsson@cs.lth.se> \ No newline at end of file -- GitLab