Questions tagged [left-recursion]

A special kind of recursion, defined through a particular grammar property: grammar is left-recursive if we can find some non-terminal A which will eventually derive a sentential form with itself as the left-symbol.

Left-recursive grammar can be immediate or indirect:

Immediate left recursion

Immediate left recursion occurs in rules of the form

A → Aa | b

where a and b are sequences of nonterminals and terminals, and b doesn't start with A. For example, the rule

Expr → Expr + Term

is immediately left-recursive.

Indirect left recursion

Indirect left recursion in its simplest form could be defined as:

A → Ba | C
B → Ab | D

possibly giving the derivation A ⇒ Ba ⇒ Aba ⇒ ...

More generally, for the nonterminals A0, A1, ..., An, indirect left recursion can be defined as being of the form:

A0 → A1a_1 | ...
A1 → A2a_2 | ...
...
An → A0a_n+1 | ...

where a_1, a_2, ..., a_n are sequences of nonterminals and terminals.

Source: Wikipedia

179 questions
0
votes
1 answer

how to make a context free grammar with no left recursion to include a left recursion (without changing the language of the grammar)?

assume we have a context free grammar , if it is in LL[1] , then it has only right Associative ! but let's say i want to make this context free grammar have a left Associative , then it will not stay in LL[1] , (which is okay) i figured that in…
mmolaan
  • 1
  • 3
0
votes
1 answer

Antlr weird parentheses syntax

Cant understand this round bracket meaning. Its not necessary to write it, but sometimes it can produce left-recursion error. Where should we use it in grammar rules?
0
votes
1 answer

Extracting text in excel

I have some text which I receive daily that I need to seperate. I have hundreds of lines similar to the extract below: COMMODITY PRICE DIFFERENTIAL: FEB50-FEB40 (APR): COMPANY A OFFERS 1000KB AT $0.40 I need to extract individual snippets from this…
Anthony
  • 123
  • 2
  • 9
0
votes
1 answer

How do I write a predicate that takes as input a list, and appends all list-typed entries from this list to a new list using Prolog?

It should be done in a left-recursive way. Right now we have this: listsFromList([],[]) . listsFromList([Head|Tail], LL):- listsFromList(Tail,LL), is_list(Head), append(Head,LL, Newlist), LL is Newlist. listsFromList([Head|Tail], LL):- …
user14670682
0
votes
0 answers

How do parsers for functional languages parse application (expr expr)?

I've recently taken to reading some literature on the compilation of functional languages and I would like some insight into how the parsing of the commonly-given EBNF grammar for, say, expressions is actually resolved. For example, in a simple…
oldjohn1994
  • 359
  • 4
  • 12
0
votes
0 answers

Eliminate Left Recursion in a Context Free Grammar

I understood Left Recursive Grammar (LRG) and how to remove it. But i dont know how to remove recursive grammar which combine both left and right recursive: A -> aAb | c The full question is construct parsing table of LL(1) grammar of this: S ->…
0
votes
0 answers

vaadin gui ,check box caption showing on left in formfieldfactory need to show on right

Create Field to add all required field need to add a check box "cb2" as well but the caption showing on right but I need to show it on left. public Field createField(Item item, Object property, Component uiContext) { String pid = (String)…
0
votes
0 answers

Not able to find first() and follow() for non LR grammer

I have removed left recursion from the given grammar. But, now I have to find out first and follow to create a parse table. Original : S -> aSb | bSa | SS | epsilon New: After removing left recursion : S -> aSbSS' | bSaSS' | S' and …
P H
  • 294
  • 1
  • 3
  • 16
0
votes
1 answer

Parser combinator for propositional logic

I'd like to design a combinator to parse Propositional Logic. Here's a simple BNF: ::= | ::= True | False | P | Q | R ::= () |…
Brian Berns
  • 15,499
  • 2
  • 30
  • 40
0
votes
1 answer

How to fix the error in left-recursion used with semantic predicates?

I would like to parse two type of expression with boolean : - the first would be an init expression with boolean like : init : false - and the last one would be a derive expression with boolean like : derive : !express or (express and (amount >=…
talohsa
  • 37
  • 6
0
votes
1 answer

How Do I left factor and eliminate left recursion?

My Production rules are as follows: S → id = Exp S → id (Arglist) Arglist → Arglist , Exp Arglist → Exp Exp → id (Arglist) Exp → id This is my first attempt: S -> id S' S' -> ϵ | = EXP | (Arglist) Arglist -> Arglist' Arglist' -> ϵ | ,Exp…
0
votes
0 answers

How to remove indirect left recursion in Antlr grammar

I've a grammar as follow: expression : scalar | vector; scalar : | vector[scalar] #VectorIndex ; vector : | scalar ('*' | '+' | '-') vector ; Is there any possibility to…
daycoder
  • 21
  • 3
0
votes
1 answer

compiler design - need help to eliminate indirect left recursion from a CFG

I have the following grammar which handles mathematical and logical expression: A ==> B A' A' ==> | B A' A' ==> epsilon B ==> C B' B' ==> ^ C B' B' ==> epsilon C ==> D C' C' ==> & D C' C' ==> epsilon D ==> E D' D' ==> << E D' | >> E D' D' ==>…
0
votes
1 answer

JavaCC left recursion parsing question about legality of breaking down a grammar

I'm attemping to do compilers on javacc but I'm not sure if the following is legal when removing left recursion: A = B AP APP | C AP APP AP = A AP | {} APP = (D AP) APP | {}
user7302428
0
votes
1 answer

left recursion with xtext

I'm having a big problem with xtext and I don't really know how to solve it, so there's a small part of the grammar I'm working with: typename: IDENTIFIER=IDENTIFIER | qualified_ident=qualified_ident ; qualified_ident: packagename "."…
Erick
  • 147
  • 2
  • 7