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
0
votes
1 answer

UnexpectedCharacters Error when parsing for roman numeral using lark parser (ebnf grammar)

i'm using the follow grammar in lark-parser to parse alphabets and roman numerals. The grammar is as follows: DIGIT: "0".."9" INT: DIGIT+ _L_PAREN: "(" _R_PAREN: ")" LCASE_LETTER: "a".."z" ROMAN_NUMERALS: "viii" | "vii" | "iii" | "ii" | "ix" | "vi"…
snowflake
  • 902
  • 1
  • 6
  • 18
0
votes
2 answers

Is it possible to describe block comments using EBNF?

Say, I have the following EBNF: document = content , { content } ; content = hello world | answer | space ; hello world = "hello" , space , "world" ; answer = "42" ; space = " " ; This lets me parse something like: hello world…
jan.sende
  • 750
  • 6
  • 23
0
votes
1 answer

Is there a metalanguage, similar to BNF that can concisely describe self-describing data?

Say for instance I had a data set that was self describing. The first few well-structured records define data type IDs, which include the name and length of records, followed by content records, which start with the data IDs and contain a variable…
Mike Godin
  • 3,727
  • 3
  • 27
  • 29
0
votes
3 answers

EBNF for capturing a comma between two optional values

I have two optional values, and when both are present, a comma needs to be in between them. If one or both values are present, there may be a trailing comma, but if no values are present, no comma is allowed. Valid…
chharvey
  • 8,580
  • 9
  • 56
  • 95
0
votes
1 answer

Optional prefix in LBNF/BNFC grammar without shift/reduce conflicts

I am trying to write a LBNF/BNFC grammar for a C-like language. In C there are many possible modifiers that you may or may not write in front of a declaration (like inline, const, volatile and so on). I am trying to write my grammar to reuse code…
Grisu47
  • 530
  • 5
  • 16
0
votes
1 answer

Problems to convert a particular EBNF rule to BNF

I am working with Flex/Bison and VHDL 93. I have a problem with the following rule: choices ::= choice { | choice } If I convert it to BNF: N1 ::= %empty | choice N2 ::= %empty | N2 N1 choices ::= choice N2 choices ::= choice | choice N2 N1 choices…
RAM
  • 65
  • 4
  • 11
0
votes
1 answer

How to deal with unary minus and exponentiation in an expression parser

I know that exponentiation has higher precedence that the unary minus. However if I build an expression parser based on that I still can’t parse expressions like 2—-3. In order to deal with these I’ve found I also need to add unary minus handling to…
rhody
  • 2,274
  • 2
  • 22
  • 40
0
votes
1 answer

JavaCUP - How to convert this line of EBNF to CFG Grammar?

I posted a couple days ago about converting EBNF grammar to CFG. Well I think I have the jist of it now, but I'm a bit stuck on this particular one: How would you convert: MultiplicativeExpr -> PrimaryExpr (( '*' | '/' ) PrimaryExpr)* to CFG? My…
muttley91
  • 12,278
  • 33
  • 106
  • 160
0
votes
1 answer

how define default rule in EBNF/Tatsu?

I have a problem in my EBNF and Tatsu implementation extract grammar EBNF for Tatsu : define ='#define' constantename [constante] ; constante = CONSTANTE ; CONSTANTE = ( Any | ``true`` ) ; Any = /.*/ ; constantename = (/[A-Z0-9_()]*/) ; When…
0
votes
1 answer

How to define standard mathematical notation with mpc parser

I am reading a compiler tutorial here www.buildyourownlisp.com. It uses a parser combinator called mpc. What I have at the moment will parse polish notation, but I'm trying to work out how to use standard notation with it. I just can't seem to how…
db24624
  • 1
  • 1
0
votes
0 answers

How to translate EBNF with multiple non-terminal productions to function calls

I'm learning compiler construction and already managed to create small Python scripts that can interpret simple lines of code. However, I'm struggling with the correct way of implementing EBNF statements that offer choices of non-terminal…
SophonAlpha
  • 21
  • 1
  • 6
0
votes
2 answers

Converting Extended BNF to Bison grammar, but having shift/reduce errors

Background I'm working on a compiler for a latex-like language. I've already written the lex file and that's working the way it ought to, so far. However, I've been running into problems now that I'm working on the grammar in the .y…
NMR-3
  • 35
  • 2
  • 8
0
votes
1 answer

EBNF Nested Optional/Grouping

I'm observing the python grammar listed in the manual and considering the outputs of their form of EBNF, specifically with varargslist: varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**'…
0
votes
0 answers

Is something bad with my grammar

I am using jison and I saw the documentation of ebnf grammars but I can't make my grammar works: Here are the images of my grammar, input and error In the error, the grammar is recognizing just one line but kleen star should recognize 0 to several…
Marilu
  • 1
  • 2
0
votes
1 answer

Conflicting shift/reduce with conditions and PEMDAS EBNF in Bison

I currently have an error in my Bison with regards to my EBNF while creating the parsing for PEMDAS and conditions. I don't understand well on how I'm going to reduce the EBNF. I got 1 shift/reduce error in the output file. Here's the part where the…
spy91
  • 1