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

Solve ambiguity in my grammar with LALR parser

I'm using whittle to parse a grammar, but I'm running into the classical LALR ambiguity problem. My grammar looks like this (simplified): ::= '{' '}' # string enclosed in braces ::= '[' ']' #…
tobiasvl
  • 570
  • 4
  • 20
0
votes
1 answer

How to write the BNF for this tree-related operation?

We have a tree like this: We can convert it to a dotstring representation, i.e., Such a tree can be represented by the preorder sequence of its nodes in which dots (.) are inserted where an empty subtree (nil) is encountered during the tree…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
0
votes
0 answers

JavaCC Parser Issue

I am trying to read a text but running into issue. Please note I just got started with JavaCC. "token1 /path1/*/path /token2" TOKEN:{ token1: ("token1") :someState } someStateTOKEN : { token: ("/token")? } The error: Encountered " "…
0
votes
1 answer

Why is Backus naur form better than english?

I was a quiz and I know one question that will be asked for sure but I have no idea how to answer it if anyone can help me please Why is BNF better than English?
0
votes
2 answers

Issues with Erlang's Yecc precedences

I’m trying to write an Erlang parser with Yecc, but I’m having some troubles with the precedence of the semantic rules. In my case I defined the grammar, the terminal and non-terminal symbols, the rules and the associated code. This is what I wrote…
ccamacho
  • 707
  • 8
  • 22
0
votes
1 answer

Scala rep() and associativity

I want to express this grammar in scala StdTokenParsers: expr -> expr ("+"|"-") ~ muldivexpr | muldivexpr "+" and "-" is left associative. The grammar is left recursive so it caused infinite recursions. I can rewrite to remove left recursion, but…
minhnhat93
  • 141
  • 1
  • 2
  • 13
0
votes
1 answer

writing antlr4 grammar and would like to count the number of tokens inside a rule

I have a grammar with the following rule - > verb and verb has 3 token values get, put change see below . if i was to read a file that has more than 3 verbs (get,put and change ) I would like the parser to print an error message . Would it be best…
killio
  • 21
  • 1
  • 4
0
votes
1 answer

BNF recursion in EpochX framework

Hopefully there are a few experts in the EpochX framework around here...I'm not sure that the user group is still active. I am attempting to implement simple recursion within their represention of a BNF grammar and have fun into the following…
erik
  • 3,810
  • 6
  • 32
  • 63
0
votes
0 answers

formalizing the following format in Context Free Grammar / BNF?

i have a file format that looks like the following: fileformat : each flag is 1 bit, and each field is 1 byte. when the flag is '1', the respective field will be present. when the flag…
0
votes
1 answer

What is meant by a token in the context of rail-road diagrams?

From Douglas Crockford's JavaScript: The Good Parts, Chapter 2 Grammar This chapter introduces the grammar of the good parts of JavaScript, presenting a quick overview of how the language is structured. We will represent the grammar with…
Geek
  • 26,489
  • 43
  • 149
  • 227
0
votes
1 answer

How can I remove some terms when parsing this BNF?

I am attempting to parse a boolean expression using the Happy library. The problem is that the result is not as good as I would want it when I introduce parentheses. I have made the following grammar. Query : Expr { $1 } Expr …
PetaPetaPeta
  • 97
  • 1
  • 12
0
votes
2 answers

Dynamic parser - read tokens from a separate file

Let's say I want to parse my new language that looks like this: main.mylang import "tags.mylang" cat dog bacon And there's another file tags.mylang that looks like this: cat "meow" dog "woof" bacon "sizzle" Running main.mylang would output meow…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
0
votes
0 answers

In Computer Science(especially in metalanguages using EBNF) , do the symbols -> and <- have specific meaning?

My apologies if this is not in SO's domain - it's a bit high-level/theoretical. I'm studying a custom Language Specification(called ACELandic if you interested). And it is based of of Extended Backus–Naur Form(EBNF ). I see symbols like <-…
Caffeinated
  • 11,982
  • 40
  • 122
  • 216
0
votes
1 answer

Is this grammar ambiguous?

I'm trying to define a language using Jison with very little punctuation for delimitation - like CoffeeScript but without the indentation. This is sort of what I want to achieve: # Definition object1, object2 property1 = value1, property2 =…
Daniel Buckmaster
  • 7,108
  • 6
  • 39
  • 57