Questions tagged [bnf]

BNF stands for Backus-Naur Form, or Backus Normal Form. It is a form of notation for context-free grammars and is often used for (but is not restricted to) the description of the syntax of programming languages. In addition to programming languages, it is also used to describe communication protocols and document formats.

A BNF specification is a set of derivation rules, written as

<symbol> ::= __expression__

where <symbol> is a nonterminal, and the __expression__ consists of one or more sequences of symbols; more sequences are separated by | indicating a choice, the whole being a possible substitution for the symbol on the left. Symbols that never appear on a left side are terminals. On the other hand, symbols that appear on a left side are non-terminals and are always enclosed between the pair <>. The ::= means that the symbol on the left must be replaced with the expression on the right.

561 questions
-2
votes
1 answer

BNF grammar specification

Write a BNF specification where each string in the language starts with x’s followed by y’s followed by z’s, with the following constraint: number of occurrences of y is greater than the number of occurrences of x and z (|y| > |x|+|z|).
-2
votes
1 answer

How can I use a stack to validate if an expression or assignment with BNF in C++?

I have tokenized with a space delimiter into a vector and then I have made it into stack. I want to use the stack to validate whether the expression or assignment is correct. assignment shall have the form: id = exp; expression shall have the…
-2
votes
1 answer

Parsing a String with a specified grammar

How do I parse a String in Java with a specified grammar? Let's say I have this eBNF grammar: object = "O:", natural_number, ":", value, ":", natural_number, ":{", { element }, "}"; value = '"' , character , { character } , '"'; element = string |…
Davio
  • 4,609
  • 2
  • 31
  • 58
-2
votes
1 answer

Looking for a BNF to DFA conversion tool

Is there a tool that can receive BNF grammar as input and produce a DFA from it? I have already found the 'hackingoff' tool in here: http://hackingoff.com/ But it is more of a testing tool and does not work on large grammars.
Vahid
  • 257
  • 4
  • 14
-4
votes
1 answer

What is the difference between := and ::= in Python?

I see Python examples with := and ::=. I've got a good understanding of the walrus operator from an article on RealPython(The Walrus Operator: Python 3.8 Assignment Expressions). I also went through the BNF document in Wikipedia (Backus–Naur form).…
sol1000
  • 141
  • 1
  • 6
-4
votes
3 answers

In C BNF, UnaryOperator ::= ( "&" | "*" | "+" | "-" | "~" | "!" ). Why / and % are excluded in UnaryOperator?

In C BNF, MultiplicativeExpression and UnaryOperator are defined like the following: MultiplicativeExpression ::= CastExpression ( ( "*" | "/" | "%" ) MultiplicativeExpression )? UnaryOperator ::= ( "&" | "*" | "+" | "-" | "~" | "!" ) Are / and %…
aheh
  • 57
  • 1
  • 6
1 2 3
37
38