开发者

Grammars in compilers

开发者 https://www.devze.com 2023-01-20 23:35 出处:网络
How to generate rul开发者_开发问答es to translate 1 form of grammar into another?? for example:

How to generate rul开发者_开发问答es to translate 1 form of grammar into another??

for example:

GRAMMAR 1:

BLOCK: while ( id:=N) { BLOCK } | id:=N
N: 1 | 2 | 3 | 4 | 5

GRAMMAR 2:

BLOCK: while id:=N DO BLOCK END | id:=N
N: 1 | 2 | 3 | 4 | 5

I want 2 generate a translation such that I can translate a statement in Grammar 2 into the corresponding statement in Grammar 1...


Umm, create a parser that converts a sentence from Grammar 1 into a syntax tree, and then convert the syntax tree back into a sentence in Grammar 2?

0

精彩评论

暂无评论...
验证码 换一张
取 消