Questions tagged [ll-grammar]

LL(k) grammars are grammars that can be parsed from left-to-right, creating a leftmost derivation, using k tokens of lookahead.

209 questions
0
votes
1 answer

PEGjs grammar star (*) not matching as expected

I have this lexeme: a().length() And this PEGjs grammar: start = func_call func_call = header "(" ")" header = "a" suffix* suffix = "(" ")" ("." "length") In the grammar, I'm parsing a function call. This currently parses, as you can try online…
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
0
votes
1 answer

How to disprove grammar of being LL(3)?

I have the following grammar I made up: S -> a a a t | a a a a I'm trying to prove that it's not LL(3). I found that First(S)={a} and Follow(S)={$} but I can't seem to figure out what I need to do to disprove it being LL(3). It's a small grammar I…
vesii
  • 2,760
  • 4
  • 25
  • 71
0
votes
0 answers

Calculating First and Follow of a grammar

I'm trying to calculate First and Follow of the following grammar: S -> A B C D E A -> a A -> EPSILON B -> b B -> EPSILON C -> c D -> d D -> EPSILON E -> e E -> EPSILON I calculated them and got First(S)={a,b,c}. But using this tools, says:…
vesii
  • 2,760
  • 4
  • 25
  • 71
0
votes
1 answer

How does FOLLOW work for the following CFG?

The original cfg is S -> S + S | SS | (S) | S* | a After refactoring and eliminating left recursion, I arrive at the following reduction: S -> TB B -> AB | e A -> +S | TB | * T -> (S) | a When calculating follow(B), online sources that I can find…
0
votes
0 answers

Turn a particular grammar into LL 1 grammar

Suppose we have the following CFG: A → Bd B → dA|a|ɛ Now if I try to calculate FIRST and FOLLOW sets, I think I can get it done as follows: First(A) = { d, a } First(B) = { d, a, ɛ } FOLLOW(A) = { d, $ } FOLLOW(B) = { d } And the parser table…
0
votes
1 answer

How to solve "The following sets of rules are mutually left-recursive" ANTLR error

The following sets of rules are mutually left-recursive [valeurBooleene, valeur] I know that ANTLR handle well left-recursive rules but only in one rule, not between rules. I have to rewrite my rules to solve the mutually left-recursive problem…
Aubin
  • 14,617
  • 9
  • 61
  • 84
0
votes
1 answer

How do you construct a parse tree during LL(1) parsing?

I was wondering if there is a way to construct a parse tree during LL(1) parsing. I've been trying for days, but have been unable to find a solution. This question is similar, but it doesn't provide enough implementation details, and it is for the…
0
votes
1 answer

Unable calculate to get follow set

I've been trying to calculate the follow set of a grammar for some time now, and have run into yet another problem. Here is my follow set calculator: def gen_follow_set(grammar, start_sym, first_sets): follow_sets = {nterm: set() for nterm in…
xilpex
  • 3,097
  • 2
  • 14
  • 45
0
votes
0 answers

Why is this grammar not LL(1)?

I am doing some homework, and was asked to show that the grammar A -> aAa | ε is not LL(1). From everything that I have seen, the answer I have so far is that since the First and the Follow sets of A contain a. Is this correct or am I thinking about…
user29451
  • 25
  • 5
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
0 answers

how to resolve FIRST-FOLLOW conflict in rule with right recursion

I have a grammar that looks like this G = ({A, B, C},{a, c},P, A), P = { 1. A → BaC, 2. B → aB 3. B → ε, 4. C→c } and I want to resolve the FIRST(2.) = {a} FOLLOW(B) = {a} conflict. But with every attempt I fail because I am not able to use the…
eja08
  • 4,600
  • 3
  • 13
  • 19
0
votes
0 answers

LL(1) parser conflict when parsing C language BNF

I'v calculated all the first sets of each production according to https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm, but I found the first sets is highly conflicted. For example, code like…
user2269707
0
votes
1 answer

making a grammar ll(1) and unambiguous

I have a CFG in the form PB := PB | R | R R := s I have tried to make it ll(1) by removing the left recursion resulting in PB := R PB' | R PB' PB' := PB'| ϵ R := s However, I believe, removing the left recursion is making the grammar now…
Kneelac
  • 15
  • 1
  • 5
0
votes
1 answer

Tokenize abstract terminals in LL grammar

I am currently writing a basic parser for an XML flavor. As an exercise, I am implementing an LL table-driven parser. This is my example of BNF grammar: %token name data string %% /* LL(1) */ doc : elem elem : "<"…
explogx
  • 1,159
  • 13
  • 28
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…