From: Peizhao Ou Date: Thu, 10 Oct 2013 08:01:20 +0000 (-0700) Subject: SpecExtractor.java seems to work X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=commitdiff_plain;h=d821fcb5090481c9a4a0d93918446ce02022b89e SpecExtractor.java seems to work --- diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj index 6ce4495..f7a4248 100644 --- a/grammer/spec-compiler.jj +++ b/grammer/spec-compiler.jj @@ -64,12 +64,20 @@ options { PARSER_BEGIN(SpecParser) package edu.uci.eecs.specCompiler.grammerParser; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + class SpecParser { public static void main(String[] argvs) throws ParseException, TokenMgrError { - SpecParser parser = new SpecParser(System.in); - parser.Start(); - System.out.println("Parsing finished!"); + try { + FileInputStream fis = new FileInputStream("./grammer/spec.txt"); + SpecParser parser = new SpecParser(fis); + parser.Start(); + System.out.println("Parsing finished!"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } } } PARSER_END(SpecParser) @@ -81,14 +89,18 @@ SKIP : "\n" | "\r" +| + "\r\n" | "\t" + /* | // "#" comment for the specification <"#" (~["\n", "\r"])* (["\n", "\r"])> | // "//" comment for the specification <"//" (~["\n", "\r"])* (["\n", "\r"])> + */ } TOKEN : @@ -136,12 +148,8 @@ TOKEN : | <#DIGIT: ["0"-"9"]> -| - <#NONZERO_DIGIT: ["1"-"9"]> | <#LETTER: ["a"-"z", "A"-"Z"]> -| - <#NUM: > | ( | | "_")> } @@ -149,7 +157,9 @@ TOKEN : void Start() : {} { - Global_construct() + //Global_construct() + + // } void Global_construct() : @@ -157,13 +167,13 @@ void Global_construct() : { - Global_define() (Interface_cluster())? (Happens_before())? + //Global_define() (Interface_cluster())? (Happens_before())? } void C_CPP_CODE() : -{} +{String code;} { <(~["@"])+> } @@ -201,10 +211,6 @@ void Happens_before() : void Interface() : {} { - - - "(" ")" "->" - } @@ -213,7 +219,6 @@ void Potential_commit_point_define() : { - "(" ")" "->" } @@ -224,7 +229,6 @@ void Commit_point_define() : { - "(" ")" "->" } @@ -235,7 +239,6 @@ void Commit_point_define_check() : { - "(" ")" "->" } diff --git a/src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java b/src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java index ba04343..2d28fce 100644 --- a/src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java +++ b/src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java @@ -57,25 +57,29 @@ public class SpecExtractor { if (trimedLine.startsWith("/**")) { _beginLine = reader.getLineNumber(); _foundHead = true; + specText.append("\n"); + specText.append(curLine); if (trimedLine.endsWith("*/")) { _endLine = reader.getLineNumber(); _foundHead = false; System.out.println("Spec<" + specIndex + "> Begin: " + _beginLine + " End: " + _endLine); - System.out.println(curLine); + System.out.println(specText); + specIndex++; } } } else { + specText.append("\n"); + specText.append(curLine); if (trimedLine.endsWith("*/")) { _endLine = reader.getLineNumber(); _foundHead = false; - specText.append("\n"); - specText.append(curLine); System.out.println("Spec<" + specIndex + "> Begin: " + _beginLine + " End: " + _endLine); - System.out.println(curLine); + System.out.println(specText); + specIndex++; specText = new StringBuilder(); } else { @@ -95,16 +99,12 @@ public class SpecExtractor { char ch; for (i = 0; i < line.length(); i++) { ch = line.charAt(i); - if (ch == ' ' || ch == '\t') - i++; - else + if (ch != ' ' && ch != '\t') break; } for (j = line.length() - 1; j >= 0; j--) { ch = line.charAt(j); - if (ch == ' ' || ch == '\t') - j--; - else + if (ch != ' ' && ch != '\t') break; } if (i > j)