# entry point.
LANG = C;
@Global_define:
+ @DeclareStruct:
@DeclareVar:
@InitVar:
@DefineFunc:
File f = new File("./grammer/spec.txt");
FileInputStream fis = new FileInputStream(f);
SpecParser parser = new SpecParser(fis);
-
+ /*
ArrayList<String> content = new ArrayList<String>();
ArrayList<Construct> constructs = new ArrayList<Construct>();
ArrayList<String> headers = new ArrayList<String>();
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();
<OPTIONS: "@Options:">
|
<GLOBAL_DEFINE: "@Global_define:">
+|
+ <DECLARE_STRUCT: "@DeclareStruct:">
|
<DECLARE_VAR: "@DeclareVar:">
|
<STRUCT: "struct">
|
<CLASS: "class">
+|
+ <UNSIGNED: "unsigned">
|
<TEMPLATE: "template">
|
("const"
{ type = "const"; }
)?
- (((str = <STRUCT>.image | str = <CLASS>.image) { type = type + " " + str; })?
+ (((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) { type = type + " " + str; })?
(
name = ParseQualifiedName() {
if (!type.equals(""))
{
System.out.println(func);
}
+
+
}
String ParameterizedName() :
(
LOOKAHEAD(2)
(
- t = <CONST> | t = <STRUCT> | t = <CLASS> |
+ t = <CONST> | t = <STRUCT> | t = <CLASS> | t = <UNSIGNED> |
(t = <TEMPLATE> { inTemplate = true; })|
- (header = <INCLUDE>.image {
+ (t = <INCLUDE>
+ {
+ header = t.image;
+ newLine = true;
if (headers != null) {
headers.add(header.substring(header.lastIndexOf(' ') + 1));
}
)+
{
+ if (content.size() == 0) {
+ content.add(text);
+ }
return content;
}
}
SequentialDefineSubConstruct Global_define() :
{
- ArrayList<String> initVar, defineFunc, code;
+ ArrayList<String> initVar, defineFunc, code, declareStruct;
ArrayList<ArrayList<String>> defineFuncs;
ArrayList<VariableDeclaration> declareVars;
+ ArrayList<ArrayList<String>> declareStructs;
VariableDeclaration declareVar;
}
{
{
- declareVars = null;
+ declareVars = new ArrayList<VariableDeclaration>();
initVar = null;
defineFuncs = new ArrayList<ArrayList<String>>();
+ declareStructs = new ArrayList<ArrayList<String>>();
}
<GLOBAL_DEFINE>
+ (<DECLARE_STRUCT> (declareStruct = C_CPP_CODE(null) {
+ declareStructs.add(declareStruct); }))*
(<DECLARE_VAR> ((declareVar = TypeParam() ";" {
declareVars.add(declareVar); } )*))?
(<INIT_VAR> (code = C_CPP_CODE(null) { initVar = code; } ))?
(<DEFINE_FUNC> (defineFunc = C_CPP_CODE(null) { defineFuncs.add(defineFunc); }))*
{
SequentialDefineSubConstruct res = new
- SequentialDefineSubConstruct(declareVars, initVar, defineFuncs);
+ SequentialDefineSubConstruct(declareStructs, declareVars, initVar, defineFuncs);
//System.out.println(res);
return res;
}
{
{
res = null;
- action = null;
+ action = new ArrayList<String>();
condition = "";
idCode = "";
check = "";
postCheck = "";
commitPointSet = new ArrayList<String>();
hbConditions = new HashMap<String, String>();
-
- action = null;
- postAction = null;
+ postAction = new ArrayList<String>();
}
<BEGIN>
<INTERFACE> (interfaceName = <IDENTIFIER>.image)