开发者

ANTLR, how to convert BNF,EBNF data in ANTLR?

I have to generate parser of CSV data. Somehow I managed to write BNF, EBNF for CSV data but I don't know how to convert this into an ANTLR grammar 开发者_StackOverflow中文版(which is a parser generator). For example, in EBNF we write:

[{header entry}newline]newline

but when I write this in ANTLR to generate a parser, it's giving an error and not taking brackets. I am not expert in ANTLR can anyone help?


hi , i have to generate parser of CSV data ...

In most languages I know, there already exists a decent 3rd party CSV parser. So, chances are that you're reinventing the wheel.

For Example in EBNF we wrire [{header entry}newline]newline

The equivalent in ANTLR would look like this:

((header entry)* newline)? newline

In other words:

                 | (E)BNF | ANTLR
-----------------+--------+------
'a' zero or once | [a]    | a?
'a' zero or more | {a}    | a*
'a' once or more | a {a}  | a+

Note that you can group rules by using parenthesis (sub-rules is what they're called):

'a' 'b'+

matches: ab, abb, abbb, ..., while:

('a' 'b')+

matches: ab, abab, ababab, ...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜