简体   繁体   English

将EBNF语法转换为无上下文语法

[英]Convert EBNF Grammar to Context-Free Grammar

I have to write a JavaCUP specification, and I've been given an EBNF grammar. 我必须编写一个JavaCUP规范,并且我已经获得了EBNF语法。 However, I don't know how to convert between the two. 但是,我不知道如何在两者之间进行转换。 I've heard the basic ideas, but I don't really understand what I need to change, what would be the "terminals", etc. 我听说过基本的想法,但我真的不明白我需要改变什么,什么是“终端”等等。

Can anyone explain how to convert from one to another, or if there's somewhere where I can read about it? 任何人都可以解释如何从一个转换为另一个,或者是否有某个地方我可以阅读它?

EBNF grammars are similar to normal BNF, but with some extra features (similar to regular expression operators) as syntax sugar. EBNF语法与普通BNF类似,但具有一些额外的功能(类似于正则表达式运算符)作为语法糖。 Since you did not show your grammar, I can only guess at what parts you need to desugar to convert to normal BNF, but here are the most common (for a LALR generator like JavaCUP): 既然你没有显示你的语法,我只能猜测你需要哪些部分来转换为普通的BNF,但这里最常见的(对于像JavaCUP这样的LALR生成器):

B*    becomes Bstar, defined as Bstar ::= epsilon; Bstar ::= Bstar B
B+    becomes Bplus, defined as Bplus ::= B; Bplus ::= Bplus B
B?    becomes Bquestion, defined as Bquestion ::= epsilon; Bquestion ::= B
B | C becomes BorC, defined as BorC ::= B; BorC ::= C

The epsilon identifier here is however your parser generator denotes the empty string. 这里的epsilon标识符是你的解析器生成器表示空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM