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

Calculate first, follow and predict from EBNF notation

Grammatical rules are defined as: an integer literal is a sequence of digits; a boolean literal is one of true or false; a keyword is one of if, while, or the boolean literals; a variable is a string that starts with a letter and is followed by…
Emigsfd
  • 41
  • 5
0
votes
0 answers

Is there an automatic way to simplify EBNF grammars?

I want to handle the Scala grammar in order to create a data structure and I want to create a graph to model it. The problem that I have is that I want to get rid of some syntax sugar of the EBNF grammar in order to parse it in an efficient way. For…
GioAgu
  • 59
  • 6
0
votes
0 answers

How to read EBNF grammar rules from a file?

I think my question is very stupid but I didn't find an answer to my problem yet. I have a file .txt with EBNF grammar rules, and I want to read them in such a way to encode them in a graph. Is there an algorithm that can understand the notation of…
GioAgu
  • 59
  • 6
0
votes
0 answers

Formal definition for strings

I was looking for a good formal structure for strings in a language, but I can't find one. The EBNF for C just has a class called string, and from python it has a const STRING as far as I've seen. So I was wondering if anyone had a good EBNF or…
Hovestar
  • 1,544
  • 4
  • 18
  • 26
0
votes
0 answers

Stopping recursive grammar rules from looping

I've a grammar that contains mutually recursive rules. For example: S -> A A -> B | C | "d" B -> "e" | A C -> A | C | "f" I want to generate random strings from this grammar by recurisvely following its rules. When I encounter an alternative, I…
Paul Smith
  • 103
  • 3
0
votes
1 answer

Meaning of => in EBNF notation

In EBNF notation I see many => but cannot find a description. I googled and read some PDF and Wikipedia, but still no clue. assignmentExpression: (leftHandSideExpression assignmentOperator) => leftHandSideExpression assignmentOperator…
exebook
  • 32,014
  • 33
  • 141
  • 226
0
votes
2 answers

Solving shift/reduce conflicts

I'm using PLY to parse this grammar. I implemented a metagrammar for EBNF used in the linked spec, but PLY reports multiple shift/reduce conflicts. Grammar: Rule 0 S' -> grammar Rule 1 grammar -> prod_list Rule 2 grammar -> empty Rule 3 …
Paul Smith
  • 103
  • 3
0
votes
1 answer

Bison/EBNF parse list with at least two elements

I am currently trying to parse a comma seperated list with at least two elements using bison. I know how to parse a list using this: list : list "," element | element but how can I make sure that the list has at least two elements?
Exagon
  • 4,798
  • 6
  • 25
  • 53
0
votes
1 answer

Preferred way of removing left recursion of EBNF

Many textbooks propose different techniques of removing left recursion. Some of them alter the associativity, which is something I would like to avoid. What is the most straightforward way to remove left recursion in the following (example)…
Leandros
  • 16,805
  • 9
  • 69
  • 108
0
votes
1 answer

What's the difference of EBNF rules between "starred_list" and "starred_expression"?

Here is the documented contents: starred_list ::= starred_item ( "," starred_item )* [","] starred_expression ::= expression | ( starred_item "," )* [starred_item] I can't tell the difference between them, aren't they equivalent…
wow yoo
  • 855
  • 8
  • 26
0
votes
1 answer

How will I parse a tag with space in its value using antlr?

I have the following grammer. meta : '<' NAME '>' TEXT '' | '<' NAME S* attribute* '>'; dl : '<' NAME '><' TEXT '>' dt* '<' TEXT '>'; dt : '<' NAME '><' NAME S* attribute* S* '>' TEXT ''; attribute :…
user235273
0
votes
1 answer

How to parse repeated attributes with antlr?

I have the following grammar. meta : '<' TAG attribute* '>'; attribute : NAME '=' VAL; TAG : [A-Z0-9]+; NAME : [A-Z_-]+; VAL : '"'.*?'"'; I want to match the below string. But…
user235273
0
votes
1 answer

Can all small EBNF rules in Python be composed into a larger correct one?

I found this rule here,i just didn't figure out how "*" or_expr is equivalent as starred_item .If there is nothing wrong, what is it the problem that caused my code a = 8;b = 2; *(a >> b), = (1,2,3) to raise a exception,which said "SyntaxError:…
wow yoo
  • 855
  • 8
  • 26
0
votes
1 answer

grammar from RFC 2812

I've got a grammar for the IRC-protocol from RFC 2812: message = [ ":" prefix SPACE ] command [ params ] crlf prefix = servername / ( nickname [ [ "!" user ] "@" host ] ) command = 1*letter / 3digit params = *14( SPACE middle ) […
Bonita Montero
  • 2,817
  • 9
  • 22
0
votes
1 answer

ANTLR - Period character not matched when matching "anything"

I have a simple rule like so: ifClause: 'if' '(' condition ')' '{' (structField)+ '}' ; condition: .*?; This works for parsing: if (abc == def) { } But errors out on: if (abc.xyz == def) { } with the error: line…
shikhanshu
  • 1,466
  • 2
  • 16
  • 32