ebnf

Is it easier to write a recursive-descent parser using an EBNF or a BNF?

I've got a BNF and EBNF for a grammar. The BNF is obviously more verbose. I have a fairly good idea as far as using the BNF to build a recursive-descent parser; there are many resources for this. I am having trouble finding resources to convert an EBNF to a recursive-descent parser. Is this because it's more difficult? I recall from my C...

BNF vs EBNF vs ABNF: which to choose?

I want to come up with a language syntax. I have read a bit about these three, and can't really see anything that one can do that another can't. Is there any reason to use one over another? Or is it just a matter of preference? ...

How to deal with overlapping character groups in different tokens in an EBNF grammar?

I'm using an LL(k) EBNF grammar to parse a character stream. I need three different types of tokens: CHARACTERS letter = 'A'..'Z' + 'a'..'z' . digit = "0123456789" . messageChar = '\u0020'..'\u007e' - ' ' - '(' - ')' . TOKENS num = ['-'] digit { digit } [ '.' digit { digit } ] . ident = letter { letter | digit | '_' } . ...

How to read alternates in EBNF grammars

I have an EBNF grammar that has a few rules with this pattern: sequence ::= item | item extra* sequence Is the above equivalent to the following? sequence ::= item (extra* sequence)* Edit Due to some of you observing bugs or ambiguities in both sequences, I'll give a specific example. The SVG specification provides a g...

BNF / EBNF for Turbo Pascal (preferably 5.5 or later, because of OOP)?

Does anyone of you know if the BNF or EBNF of Turbo Pascal is available somewhere (LEGALLY!!)? ...

why does 'a'..'z' in ANTLR match wildcards like $ or £

When I run the following grammer: test : WORD+; WORD : ('a'..'z')+; WS : ' '+ {$channel = HIDDEN;}; and I give the input "?test" why does antlr accept this as valid input? I thought the ('a'..'z') would only match characters within the lowercase alphabet? ...

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 (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 brack...

Scala Parser Combinators tricks for recursive bnf?

Im trying to match this syntax: pgm ::= exprs exprs ::= expr [; exprs] expr ::= ID | expr . [0-9]+ My scala packrat parser combinator looks like this: import scala.util.parsing.combinator.PackratParsers import scala.util.parsing.combinator.syntactical._ object Dotter extends StandardTokenParsers with PackratParsers { lexical.del...

Implementing parser for markdown-like language

I have markup language which is similar to markdown and the one used by SO. Legacy parser was based on regexes and was complete nightmare to maintain, so I've come up with my own solution based on EBNF grammar and implemented via mxTextTools/SimpleParse. However, there are issues with some tokens which may include each other, and I don...

python: replacing regex with BNF or pyparsing

I am parsing a relatively simple text, where each line describes a game unit. I have little knowledge of parsing techniques, so I used the following ad hoc solution: class Unit: # rules is an ordered dictionary of tagged regex that is intended to be applied in the given order # the group named V would correspond to the value (if...

Parsing a code block with EBNF expression

Hello there, I am using CocoR to generate a java-like scanner/parser: I'm having some troubles in creating a EBNF expression to match a codeblock: I'm assuming a code block is surrounded by two well-known tokens: <& and &> example: public method(int a, int b) <& various code &> If I define a nonterminal symbol codeblock =...

When do the parentheses get used in EBNF?

If you have grammar like this: <assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> + <term> | <term> <term> → <term> * <factor> | <factor> <factor> → ( <expr> ) | <id> And then the sentence A = B + C * A, you get this leftmost derivation: <assign> => <id> = <expr> => A = <expr> ...

Why would there be two operands in a EBNF sentence?

Have this EBNF grammar < calculation> -> <expr> = <expr> -> <term> (+ | -) <expr> | <term> <term> -> <factor> (* | /) <term> | <factor> <factor> -> ( <expr> ) | <value> <value> -> [ <sign> ] <unsigned> ...