Questions tagged [ebnf]

EBNF stands for Extended Backus-Naur Form, or Extended Backus Normal Form. It is an extension to BNF and is used to describe the syntax of context-free grammars, such as programming languages, document formats, or communication protocols. It improves over BNF by providing operators to express optional, zero or more, and one or more occurrences of a term. This makes EBNF much more expressive and concise compared to BNF.

EBNF is standardized format for documenting syntax. It includes an extension mechanism for defining a two-level grammar that can produce an infinite number of production rules.

References

354 questions
6
votes
3 answers

Question about EBNF notation and JSON

Recently I've been studying parsers and grammars and how they work. I was reading over the formal grammar for JSON at http://www.ietf.org/rfc/rfc4627.txt, which uses EBNF. I was pretty confident in my understanding of BNF and EBNF, but apparently…
Channel72
  • 24,139
  • 32
  • 108
  • 180
6
votes
3 answers

Java EBNF?

Does anyone know of an accurate source for an (E)BNF for the Java language? Preferably, it would be from an authorative source, e.g. Sun. Thanks.
Eyvind
  • 5,221
  • 5
  • 40
  • 59
6
votes
2 answers

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…
svrist
  • 7,042
  • 7
  • 44
  • 67
6
votes
1 answer

How do I parse children nodes?

So lets say I have the following grammar: let_stat = "let" iden [ "=" expr ]; if_stat = "if" expr "->" stat; stat = let_stat | if_stat; This would be the following psuedo-ish code: let_stat parseLetStat() { if token is "let" { consume…
metro-man
  • 1,763
  • 2
  • 15
  • 28
6
votes
3 answers

What is the difference between EBNF and CFG

I understand that EBNF can be used to express Context Free Grammar, but is there any difference between the two? I am asking because there are questions that ask to convert EBNF to CFG, but as of my current understanding, they look same. Therefore,…
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
6
votes
1 answer

Extended BNF syntax highlighting

I try to find the Extended BNF (EBNF) nice syntax highlighting. Can't find it through the Google. Anybody know the link? Thank you.
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
5
votes
2 answers

How to parse comments with EBNF grammars

When defining the grammar for a language parser, how do you deal with things like comments (eg /* .... */) that can occur at any point in the text? Building up your grammar from tags within tags seems to work great when things are structured, but…
Jagu
  • 2,471
  • 2
  • 22
  • 26
5
votes
1 answer

How to denote at least one repetition in EBNF?

https://en.wikipedia.org/wiki/Extended_Backus–Naur_form The above article mentions that curly braces denote repetition of arbitrary times (incl. zero), while square brackets denote at most one repetition. What I want however, is at least one…
user4385532
5
votes
1 answer

How to understand this EBNF Pascal Definition

I'm implementing a Pascal parser from this EBNF defintion. There is something I don't understand in the following specifications: variable entire-variable | component-variable | referenced-variable entire-variable variable-identifier |…
Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
5
votes
1 answer

Convert EBNF Grammar to Context-Free Grammar

I have to write a JavaCUP specification, and I've been given an EBNF grammar. 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",…
muttley91
  • 12,278
  • 33
  • 106
  • 160
5
votes
1 answer

Convert EBNF grammar to PEG

I have an EBNF grammar and want to convert it to PEG (https://github.com/anatoo/PHPPEG): query = { word | wildcard } word = ( [apostrophe] ( letter { alpha } ) ) | ” , ” letter = ” a ” | ... | ” z ” | ” A ” | ... | ” Z ” alpha = letter | ” 0 ” | ...…
XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60
5
votes
1 answer

BNF example for language grammar where indenting level defines a block?

I attempt to document a syntax I use in menuentries.conf, which is a configuration file for menu entries, by describing the syntax / grammar using the notation known as extended Backus-Naur-Form EBNF(BNF) This menuentries.conf uses indenting levels…
humanityANDpeace
  • 4,350
  • 3
  • 37
  • 63
5
votes
1 answer

Optional or Repeated Items in Prolog DCG

So I'm writing a simple parser for Pascal in SWI-Prolog using Definite Clause Grammars. I don't understand how to implement repeating (2 or more) or optionally repeating (1 or more) predicates. For example, in EBNF, for Pascal's "program"…
Marcus Hallett
  • 105
  • 1
  • 7
5
votes
2 answers

Recursion in Pyparsing

Im unable to translate this EBNF expression into Pyparsing, any idea? token:: [A-Z] P:: !|token;P|(P^P)|(P*P) The problem is when using recursion, the interpreter fails. Expression like this should be…
ccamacho
  • 707
  • 8
  • 22
5
votes
1 answer

Parsing of optionals with PEG (Grako) falling short?

My colleague PaulS asked me the following: I'm writing a parser for an existing language (SystemVerilog - an IEEE standard), and the specification has a rule in it that is similar in structure to this: cover_point = [[data_type]…
Apalala
  • 9,017
  • 3
  • 30
  • 48
1 2
3
23 24