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

Precedence of shell operator

I'm currently trying to re-code a shell in C using a BNF and LL parser. Otherwise, I need to know what is the precedence of shell operator of |, <<, ,, <, >>, >, &, ;? Is there anyone who can provide me it ? Thank you
S7_0
  • 1,165
  • 3
  • 19
  • 32
7
votes
3 answers

Compiler compiler that consumes BNF

Is there any reason why there are no parser generators that consume straight BNF? I'm familiar with JavaCC and Antlr, and recently came across Parse2. It seems that each has its own notation. BNF is really easy to read and the other notations…
ccleve
  • 15,239
  • 27
  • 91
  • 157
7
votes
2 answers

How to correctly formalize the command line usage of GNU/Linux commands?

I'd like to write down a BNF-like formal grammar for describing the command line usage of some GNU/Linux tools. For example I can describe the usage of the cat command as: (cat-command) : 'cat' (arguments-list) (arguments-list) :…
Francesco Turco
  • 219
  • 1
  • 4
7
votes
1 answer

BNF grammar definition for file path wildcard (glob)

I'm searching for some widely extended dialect (like this one https://github.com/vmeurisse/wildmatch + globstar **) described with BFN rules. In any format or language. OMeta or PEG would be great.
Ev_genus
  • 135
  • 11
7
votes
5 answers

Grammars, Scala Parsing Combinators and Orderless Sets

I'm writing an application that will take in various "command" strings. I've been looking at the Scala combinator library to tokenize the commands. I find in a lot of cases I want to say: "These tokens are an orderless set, and so they can appear in…
BefittingTheorem
  • 10,459
  • 15
  • 69
  • 96
7
votes
2 answers

BNF grammar for left-associative operators

I have the following EBNF grammar for simple arithmetic expressions with left-associative operators: expression: term {+ term} term: factor {* factor} factor: number ( expression ) How can I convert this into a BNF grammar…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
7
votes
2 answers

Extracting information using BNF grammars

I would like to extract information from a body of text and be able to query it. The structure of this body of text would be specified by a BNF grammar (or variant), and the information to extract would be specified at runtime (the syntax of the…
Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
7
votes
1 answer

How can I define an INI file grammar using the BNFC?

http://www.cs.chalmers.se/Cs/Research/Language-technology/BNFC/ how should I write my labeled BNF to get BNFC to generate a INI parser for me? I have only gotten so far o__O! entrypoints File ; comment "#" ; token ID ( letter | digit | ["-_'"] )+…
Cetin Sert
  • 4,497
  • 5
  • 38
  • 76
6
votes
4 answers

How to convert a regular grammar to regular expression?

Is there an algorithm or tool to convert regular grammar to regular expression?
dalibocai
  • 2,289
  • 5
  • 29
  • 45
6
votes
2 answers

why is `int test {}` a function definition in C language BNF

I'm interested in the famous The syntax of C in Backus-Naur Form and studied for a while, what confuse me is that some syntax looks wrong to me but is considered right according to the BNF. For example, int test {}, what's this? I think this is a…
user2269707
6
votes
2 answers

How to generate random programs from BNF

I know my question sounds a little vague, but I could not find any tutorials online. I am not asking for an answer, but for more of an explanation. An example of the BNF: ::= “int main() { return 0; }” ::=
John Doee
  • 207
  • 4
  • 15
6
votes
1 answer

Grammar for Unix command line options

This is a homework question. I would like to write a simple parser for Unix command line options. First, I would like to define a grammar with BNF. Options = Option | Options, space, Option; Option = OptionName | OptionName, OptionArguments;…
Michael
  • 41,026
  • 70
  • 193
  • 341
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
4 answers

Grammar Syntax and Linguistics

I REALLY need a description of the english sentence structure in a way that can be translated by machine and is strictly rule based(no statistical stuff), it doesn't have to be a context-free grammar but that would be preferable(as it can't be and…
Sweating
  • 61
  • 2