为什么 "myStat" 不匹配
why "myStat" are not matched
目标:
我要翻译一个伪代码(混合了个人定义的代码和标准C)到标准C.Just翻译个人定义的代码并复制标准C的部分(包括blanks/tabs)。
pseudocode:
int main()
{
int a = 0;
-Export() //personal defined code
return 0;
}
target file:
int main()
{
int a = 0;
MyExport(); //translated
return 0;
}
g4 file:
prog: myStat* |
cppStat* ;
myStat : EXPORTFUNC;
cppStat : OtherLine ;
EXPORTFUNC : [\t ]*'-Export()\r\n';
NL : '\r'?'\n'
OtherLine : OTHER* (NL|EOF);
fragment OTHER :~[\r\n]+ ;
问题:
伪代码中的“-Export()”不能被解析规则"myStat".
匹配
(prog (cppStat int main()\r\n)
(cppStat {\r\n)
(cppStat \tint a= 0;\r\n)
-Export\r\n //doesn't match "myStat"
(cppStat \taaaaa\r\n)
(cppStat }\r\n) \r\n)
我应该怎么做才能纠正?
源代码中的-Export()
行可以被myStat
和cppStat
规则匹配。由于最长的规则匹配获胜并且 cppStat
包含前导空格,因此 myStat
失败。
作为一般原则,skip
任何在语法上对解析不重要的内容。
目标: 我要翻译一个伪代码(混合了个人定义的代码和标准C)到标准C.Just翻译个人定义的代码并复制标准C的部分(包括blanks/tabs)。
pseudocode:
int main()
{
int a = 0;
-Export() //personal defined code
return 0;
}
target file:
int main()
{
int a = 0;
MyExport(); //translated
return 0;
}
g4 file:
prog: myStat* |
cppStat* ;
myStat : EXPORTFUNC;
cppStat : OtherLine ;
EXPORTFUNC : [\t ]*'-Export()\r\n';
NL : '\r'?'\n'
OtherLine : OTHER* (NL|EOF);
fragment OTHER :~[\r\n]+ ;
问题: 伪代码中的“-Export()”不能被解析规则"myStat".
匹配(prog (cppStat int main()\r\n)
(cppStat {\r\n)
(cppStat \tint a= 0;\r\n)
-Export\r\n //doesn't match "myStat"
(cppStat \taaaaa\r\n)
(cppStat }\r\n) \r\n)
我应该怎么做才能纠正?
源代码中的-Export()
行可以被myStat
和cppStat
规则匹配。由于最长的规则匹配获胜并且 cppStat
包含前导空格,因此 myStat
失败。
作为一般原则,skip
任何在语法上对解析不重要的内容。