[英]SableCC parsing given wrong result
I tried to parse the valid message using sablecc. 我试图使用sablecc解析有效消息。 There are three type of valid message format.
有效的消息格式有三种。
{messageid} messageid semi
) {messageid} messageid semi
) {flightnum} carriercode semi
) {flightnum} carriercode semi
) {load} hypene co semi
) {load} hypene co semi
) when I input valid string to the programme, it did not work. 当我向程序输入有效字符串时,它不起作用。
input: 输入:
abc;
abc; //type 1
//类型1
ZZ;
Z Z; //type 2
//类型2
ZZ;
Z Z; //type 2
//类型2
-ab2;
-ab2; //type3
// type3
sablecc grammar code : sablecc语法代码:
Helpers
/* Our helpers */
fa = ['0' .. '9'] ;
a = [['a' .. 'z'] + ['A' .. 'Z']] ;
m= [a + fa];
sp = ' ' ;
cr = 13 ; // carriage return
lf = 10 ; // line feed
tab = 9 ; // tab char
bl = sp | cr | lf | tab;
Tokens
/* Our simple token definition(s). */
semi = ';' bl*;
co = (a)(m)(m);
messageid = (a)(a)(a) ;
carriercode = (m)(m);
hypene ='-';
Productions
program = {single} statement |
{sequence} program statement;
statement = {messageid} messageid semi |
{flightnum}carriercode semi |
{load} hypene co semi ;
compilation succeed, when run the java code it throws parser exception : 编译成功,当运行Java代码时,它将引发解析器异常:
simpleAdders.parser.ParserException: [1,1] expecting: messageid, carriercode, '-'
simpleAdders.parser.ParserException:[1,1]期望:messageid,运营商代码,“-”
Even though first string is valid. 即使第一个字符串有效。
This error is caused by overlapping token definition. 此错误是由重叠的令牌定义引起的。 Sablecc is worked bottom up tree structure not a sequence manner.
Sablecc不是自下而上的树状结构。 This is code for solve the problem.
这是解决问题的代码。 Thanks Etienne for cleared the problem.
感谢Etienne消除了问题。
Helpers
/* Our helpers */
sp = ' ' ;
cr = 13 ; // carriage return
lf = 10 ; // line feed
tab = 9 ; // tab char
bl = sp | cr | lf | tab;
Tokens
/* Our simple token definition(s). */
fa = ['0' .. '9'] ;
a = [['a' .. 'z'] + ['A' .. 'Z']] ;
semi = ';' bl*;
hypene ='-';
Productions
program = {single} statement |
{sequence} program statement;
m = {a} a | {fa} fa ;
co = hypene a [m1]:m [m2]:m semi;
messageid = [a1]:a [a2]:a [a3]:a semi ;
carriercode =[m1]:m [m2]:m semi;
statement = {messageid} messageid|
{flightnum}carriercode |
{load} co ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.