Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

compiler-construction - 是否可以切换到其他规则(Is it possible to switch to another rule)

My understanding is that in Lex/Bison, the lexical analysis is done by lex, the syntaxical by the rules of Bison, and the semantic one by the actions of Bison.

(我的理解是,在Lex / Bison中,词法分析由lex完成,语法分析由Bison规则完成,语义分析由Bison的动作完成。)

Is it then possible to go back from the semantic analysis, ie the actions, to the syntaxical one ?

(那么是否有可能从语义分析(即动作)返回到语法上的动作呢?)

One exemple would be that : suppose I want to be able to detect pseudo-C as "i++", "i=i+1","i=i+2".

(一个示例是:假设我希望能够将伪C检测为“ i ++”,“ i = i + 1”,“ i = i + 2”。)

But I want that "i=i+1" to be reduce as "i++", and "i=i+2" to be a second rule.

(但是我希望将“ i = i + 1”减少为“ i ++”,而将“ i = i + 2”作为第二个规则。)

Is it the possible to do something like that :

(是否可以做这样的事情:)

identifier_plusplus: IDENTIFIER '+' '+'
add:                 IDENTIFIER '=' IDENTIFIER '+' NUMBER {if($1 == $3 && $5 == 1) REDUCE_IN(identifier_plusplus);}

Here, it is not very usefull, but in a case where I use identifier_plusplus in another rule, it could be very powerfull.

(在这里,它不是很有用,但是在我在另一条规则中使用identifier_plusplus的情况下,它可能会非常强大。)

EDIT : An example where it can be usefull would be if I have another rule that catch For loops which increment one by one.

(编辑:一个可能有用的示例是,如果我有另一个规则来捕获一个递增一个的For循环。)

I would like to type something as :

(我想输入以下内容:)

for_one:    FOR '(' IDENTIFIER '=' '0' ';' IDENTIFIER '<' CONST ';' IDENTIFIER PLUSPLUS ')' exprs 

With no care if I wrote i++ or i=i+1.

(不管我写i ++还是i = i + 1。)

Is it more clear now ?

(现在更清楚了吗?)

(please excuse my english...)

((请原谅我的英语...))

Thank you in advance.

(先感谢您。)

  ask by EzrielS translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...