}
PARSER_BEGIN(UtilParser)
-package edu.uci.eecs.specCompiler.grammerParser.utilParser;
-import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
-import edu.uci.eecs.specCompiler.specExtraction.QualifiedName;
-import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
+package edu.uci.eecs.utilParser;
+import edu.uci.eecs.specExtraction.FunctionHeader;
+import edu.uci.eecs.specExtraction.QualifiedName;
+import edu.uci.eecs.specExtraction.VariableDeclaration;
+//import edu.uci.eecs.specExtraction.WrongAnnotationException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.ArrayList;
+
- public class UtilParser {
- public static void main(String[] argvs)
- throws ParseException, TokenMgrError {
- try {
- File f = new File("./grammer/spec1.txt");
- FileInputStream fis = new FileInputStream(f);
- UtilParser parser = new UtilParser(fis);
-
- //parser.Test();
- System.out.println("Parsing finished!");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
+public class UtilParser {
+ public static void main(String[] argvs)
+ throws ParseException, TokenMgrError {
+ try {
+ File f = new File("./grammer/spec1.txt");
+ FileInputStream fis = new FileInputStream(f);
+ UtilParser parser = new UtilParser(fis);
+
+ //parser.Test();
+ System.out.println("Parsing finished!");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
}
+ }
- public static ArrayList<VariableDeclaration> getTemplateArg(String line)
- throws ParseException {
- InputStream input = new ByteArrayInputStream(line.getBytes());
- UtilParser parser = new UtilParser(input);
- return parser.TemplateParamList();
- }
+ public static ArrayList<VariableDeclaration> getTemplateArg(String line)
+ throws ParseException {
+ InputStream input = new ByteArrayInputStream(line.getBytes());
+ UtilParser parser = new UtilParser(input);
+ return parser.TemplateParamList();
+ }
- public static FunctionHeader parseFuncHeader(String line)
- throws ParseException {
- InputStream input = new ByteArrayInputStream(line.getBytes());
- UtilParser parser = new UtilParser(input);
- return parser.FuncDecl();
- }
+ public static FunctionHeader parseFuncHeader(String line)
+ throws ParseException {
+ InputStream input = new ByteArrayInputStream(line.getBytes());
+ UtilParser parser = new UtilParser(input);
+ return parser.FuncDecl();
+ }
+ public static VariableDeclaration parseDeclaration(String line)
+ throws ParseException {
+ InputStream input = new ByteArrayInputStream(line.getBytes());
+ UtilParser parser = new UtilParser(input);
+ return parser.Declaration();
+ }
- public static String stringArray2String(ArrayList<String> content) {
- StringBuilder sb = new StringBuilder();
- if (content.size() == 1)
- return content.get(0);
- for (int i = 0; i < content.size(); i++) {
- sb.append(content.get(i) + "\n");
- }
- return sb.toString();
+ public static String stringArray2String(ArrayList<String> content) {
+ StringBuilder sb = new StringBuilder();
+ if (content.size() == 1)
+ return content.get(0);
+ for (int i = 0; i < content.size(); i++) {
+ sb.append(content.get(i) + "\n");
}
+ return sb.toString();
}
+}
PARSER_END(UtilParser)
SKIP :
(<CONST>
{ type = "const"; }
)?
- (((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) { type = type + " " + str; })?
+ (
+ ((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) {
+ type = type.equals("") ? type + str : type + " " + str;
+ })?
(
name = ParseQualifiedName() {
if (!type.equals(""))
}
{
(str = <IDENTIFIER>.image {res = str;})
- (<OPEN_BRACKET> str = Type() { res = res + "<" + str; }
- (<COMMA> str = Type() { res = res + ", " + str; })* <CLOSE_BRACKET>
+ (<LESS_THAN> str = Type() { res = res + "<" + str; }
+ (<COMMA> str = Type() { res = res + ", " + str; })* <GREATER_THAN>
{ res = res + ">"; }
)?
{
params = new ArrayList<VariableDeclaration>();
}
<TEMPLATE>
- <OPEN_BRACKET>
+ <LESS_THAN>
(type = <IDENTIFIER>.image
name = <IDENTIFIER>.image
{
params.add(new VariableDeclaration(type, name));
}
)*
- <CLOSE_BRACKET>
+ <GREATER_THAN>
{
//System.out.println(params);
return params;
}
}
+VariableDeclaration Declaration() :
+{
+ String type, param;
+}
+{
+ (type = Type()) (param = <IDENTIFIER>.image) <SEMI_COLON>
+ {
+ return new VariableDeclaration(type, param);
+ }
+}
+
VariableDeclaration TypeParam() :
{
String type, param;