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
0
votes
2 answers

BNF Grammar for propositional logic ANTLR

I'm trying to create a BNF Grammar in Antlr for propositional logic but I keep getting the error: java.lang.NoSuchFieldError: offendingToken As there is no line number displayed, I don't know where the error is. The build is successful, but when I…
Charlie
  • 1
  • 2
0
votes
4 answers

java: calculator, BNF, AST adding & subtracting

I'm trying to write a method that does addition, and subtraction using indexOf() , lastIndexOf() for example string s = "3 + 3" I want to break this string into two substrings then do certain operation. // for addition String s = "3 + 3"; int…
hibc
  • 267
  • 1
  • 5
  • 12
0
votes
1 answer

Defining Function Signatures in a Simple Language Grammar

I am currently learning how to create a simple expression language using Irony. I'm having a little bit of trouble figuring out the best way to define function signatures, and determining whose responsibility it is to validate the input to those…
mclark1129
  • 7,532
  • 5
  • 48
  • 84
0
votes
1 answer

Is the grammar infinite or finite?

S ::= N N ::= A B C X | D E F X A ::= edith | simone B ::= de | ε C ::= wharton | beauvoir D ::= percy E ::= bysshe | ε F ::= shelley X ::= and S | ε It seems you could go on forever if you keep replacing X with and S, but if it is…
atkayla
  • 8,143
  • 17
  • 72
  • 132
0
votes
2 answers

Bug in Gold Parser? LALR

Here is a piece of my bnf grammer. //this works ::= '?' ':' //this gets an error ::= '?' ':' ::= This seems insane, shouldnt the second be EXACTLY…
user34537
0
votes
3 answers

"threadsafe" modifier in JAVA?

I just came across a BNF Grammar for JAVA. In it, "modifier" has a terminal symbol called "threadsafe". However, I have never seen it before and have not been able to locate that modifier in The Java Language Specification, Java SE 7 Edition…
KoenigGunther
  • 130
  • 1
  • 8
0
votes
1 answer

Parser description with repetition "meta-token"

Is there a well-known parser description language (like Backus-Naur) that allows for repetitions where the number of repetitions is extracted from the token stream? For bonus points, are there any C++ libraries that support this…
tgoodhart
  • 3,111
  • 26
  • 37
-1
votes
1 answer

[af]?lex regular expression difference

I don't know how to do this, and I've found no good resources online for how to perform this operation[.] I'm trying to take an annotated EBNF production rule which is a difference between two regular expressions and turn it into a(n a| f?)lex…
-1
votes
1 answer

How to implement this kind of EBNF grammar (lookahead)?

I am trying to parse the string "###" using an EBNF grammar in TatSu (grako) of this kind: grammar = """mask = | ['()'] ['$'] {'#'} '#' | ['()'] {'#'} '#%' | ['()'] ['$'] {'#'} {'0'} '0' '.#'…
MadInc
  • 1
  • 3
-1
votes
2 answers

Elegant way of extracting substrings matching regex?

Is there a nice way in Python to do: Check a String matches a set of regular expressions If yes: get the matching parts back as tuples. So essentially I want a simple way to enter simple parser/scanner grammars, and simply extract all matching in…
robert
  • 1,921
  • 2
  • 17
  • 27
-1
votes
1 answer

yacc fails to parse simpe shell grammar

I am writing a simple grammar for a shell using yacc/lex. I want my grammar to recognize pipelines, which have the following form: command1 | command2 | ... | commandn. I am able to regonize a single command, with the simple_command rule as the…
joenatech7
  • 13
  • 1
  • 4
-1
votes
1 answer

LR(1) items and LALR(1) Parsing table how to do this?

From the grammar given below create LR(1) items and merge the sets of items having give the set of LALR(1) items. I am not sure how to construct from this grammar B -> id | id ( B ) | B . id | B [ B ] | B . id ( B ) Answer so far: i0- B' -> .B, $ |…
dan123
  • 1
-1
votes
1 answer

Issues understanding BNF grammar form

I am learning how BNF grammar works and I have been given the following example of some BNF grammar rules. I'm just trying to understand what this means and I'm having trouble: ::= ‘(‘ ‘)’ ::= ‘[‘ ‘]’ |…
Vandexel
  • 609
  • 2
  • 7
  • 17
-1
votes
1 answer

Way to check if a string satisfies a BNF

I have created a BNF for a certain language and want to check if a certain input is valid for that BNF. For instance, if I have a BNF like ::= a a | b b | c c | d d |…
Joe
  • 49
  • 1
  • 9
-1
votes
1 answer

BNF to EBNF conversion

I've trying to convert a given BNF list to EBNF and im completely clueless how. Can anyone help? The BNF is: :== :== :==
:==…
1 2 3
37
38