From c8b24673cc3105a8d16e37a915d5b04074b3a3a1 Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Fri, 14 Mar 2014 16:46:21 -0700 Subject: [PATCH] temporal --- grammer/spec_compiler.jj | 90 +++- grammer/util.jj | 436 ++++++++++++++++++ run-javacc.sh | 6 + .../codeGenerator/CodeVariables.java | 4 +- .../SequentialDefineSubConstruct.java | 2 +- .../specExtraction/SpecExtractor.java | 3 + .../specExtraction/SpecInfoScanner.java | 67 +++ 7 files changed, 585 insertions(+), 23 deletions(-) create mode 100644 grammer/util.jj create mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/SpecInfoScanner.java diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj index a58db93..9950ad8 100644 --- a/grammer/spec_compiler.jj +++ b/grammer/spec_compiler.jj @@ -114,6 +114,7 @@ import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Arrays; import edu.uci.eecs.specCompiler.specExtraction.Construct; import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct; @@ -141,10 +142,10 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; public static void main(String[] argvs) throws ParseException, TokenMgrError { try { - File f = new File("./grammer/spec.txt"); + File f = new File("./grammer/spec1.txt"); FileInputStream fis = new FileInputStream(f); SpecParser parser = new SpecParser(fis); - /* + ArrayList content = new ArrayList(); ArrayList constructs = new ArrayList(); ArrayList headers = new ArrayList(); @@ -156,9 +157,9 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; for (int i = 0; i < constructs.size(); i++) { System.out.println(constructs.get(i)); } - */ - parser.Test(); + + //parser.Test(); System.out.println("Parsing finished!"); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -181,6 +182,13 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; return null; } + + private static ArrayList breakLines(String all) { + String lines[] = all.split("[\\r\\n]+"); + return new ArrayList(Arrays.asList(lines)); + } + + public static ArrayList getTemplateArg(String line) throws ParseException { InputStream input = new ByteArrayInputStream(line.getBytes()); @@ -260,7 +268,7 @@ PARSER_END(SpecParser) -<*> SKIP : + SKIP : { " " | @@ -289,6 +297,10 @@ SKIP : { "/*": IN_COMMENT } + TOKEN: { + +} + <*> SKIP : { // "//" comment for the specification <"//" (~["\n", "\r"])* (["\n", "\r"])> @@ -366,7 +378,7 @@ SKIP : { } - TOKEN : + TOKEN : { /* Specification & C/C++ shared tokens */ // Reserved keywords @@ -562,7 +574,7 @@ String Type() : } { { type = ""; } - ("const" + ( { type = "const"; } )? (((str = .image | str = .image | str = .image) { type = type + " " + str; })? @@ -574,7 +586,7 @@ String Type() : type = name.fullName; }) ) - ((str = "const".image { + ((str = .image { if (!type.equals("")) type = type + " " + str; else @@ -624,8 +636,8 @@ String ParameterizedName() : } { (str = .image {res = str;}) - ("<" str = Type() { res = res + "<" + str; } - ("," str = Type() { res = res + ", " + str; })* ">" + ( str = Type() { res = res + "<" + str; } + ( str = Type() { res = res + ", " + str; })* { res = res + ">"; } )? { @@ -678,7 +690,7 @@ ArrayList TemplateParamList() : params = new ArrayList(); }