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)
"\n"
|
"\r"
+|
+ "\r\n"
|
"\t"
+ /*
|
// "#" comment for the specification
<"#" (~["\n", "\r"])* (["\n", "\r"])>
|
// "//" comment for the specification
<"//" (~["\n", "\r"])* (["\n", "\r"])>
+ */
}
TOKEN :
<POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
|
<#DIGIT: ["0"-"9"]>
-|
- <#NONZERO_DIGIT: ["1"-"9"]>
|
<#LETTER: ["a"-"z", "A"-"Z"]>
-|
- <#NUM: <NONZERO_DIGIT> <DIGIT>>
|
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>
}
void Start() :
{}
{
- Global_construct() <EOF>
+ //Global_construct() <EOF>
+ <EOF>
+ //<IDENTIFIER> <EOF>
}
void Global_construct() :
{
<HEAD>
<BEGIN>
- Global_define() (Interface_cluster())? (Happens_before())?
+ //Global_define() (Interface_cluster())? (Happens_before())?
<END>
<TAIL>
}
void C_CPP_CODE() :
-{}
+{String code;}
{
<(~["@"])+>
}
void Interface() :
{}
{
- <HEAD>
- <BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
- <END>
<TAIL>
}
{
<HEAD>
<BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
<END>
<TAIL>
}
{
<HEAD>
<BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
<END>
<TAIL>
}
{
<HEAD>
<BEGIN>
- <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")" "->" <IDENTIFIER>
<END>
<TAIL>
}
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 {
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)