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

Hashtable in Ocaml where key is a tuple

I am trying to construct a LL1 parse table in ocaml. I'd like for the key to be a Nonterminal, input_symbol tuple. Is this possible? I know you can do a stack of tuples: let (k : (string*string) Stack.t) = Stack.create ();; Thank you in advance!!
maddie
  • 1,854
  • 4
  • 30
  • 66
0
votes
0 answers

How to make a grammar LL(1)?

I have this grammar that has to be transformed to LL(1) grammar: S->A A->BC|DBC B->Bb|epsilon C->c|epsilon D->a|b|d After applying left recursion and left factoring to it, I get the grammar as below: S->A A->BCA'|epsilon A'->D |…
eri
  • 109
  • 3
  • 9
0
votes
1 answer

Why is this grammar LL(1) even though all the FIRST sets are the same?

Consider the following CFG: S := AbC A := aA | epsilon C := Ac Here, FIRST(A) = FIRST(B) = FIRST(C) = {a, ε}, so all the FIRST sets are the same. However, this grammar is supposedly LL(1). How is that possible? Wouldn't that mean that there would…
hanie
  • 318
  • 5
  • 19
0
votes
1 answer

How to determine if the language is LL(1)?

P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal 0 (zero)) T → a | b | c | d For the above…
유승기
  • 21
  • 1
  • 6
0
votes
1 answer

Compilation - LL1 Grammar

I am studying the magic of compilers and I don't understand a result. Here is the grammar : S -> A # A -> B G D E B -> + | - | EPSILON C -> c C | EPSILON G -> c C D -> . C | EPSILON E -> e B G | EPSILON When I try to find the "first" and "follow"…
0
votes
1 answer

Computing the FOLLOW sets

My task is to calculate FIRST and FOLLOW sets for the following grammar: P ::= S CS . S ::= ( int , int ) CS ::= C CS | epsilon C ::= left int | right int | low C I got the following first sets: FIRST(S) = {'('} FIRST(C) =…
Luki
  • 409
  • 11
  • 25
0
votes
1 answer

How to make a parse tree from Follow() set in LL parsing?

I was given the question for test: Show the parse tree of a string proving that b is in the follow of T. S=> ET T=>bSc | d E=>aTE| ε I solved the First set : First(S)=>First(E)=>{a} U First(T)=> {a,b,d} First(T)=>{b,d} First(E)=>{a,ε} And the…
Nikul Vyas
  • 363
  • 3
  • 7
  • 30
0
votes
1 answer

First sets of LL(1) parser

I have some problems understanding the following rules applied for first sets of LL(1) parser: b) Else X1 is a nonterminal, so add First(X1) - ε to First(u).   a. If X1 is a nullable nonterminal, i.e., X1 =>* ε,  add First(X2) - …
0
votes
1 answer

Ilustrate the left-most derivation on a token stream

I am trying to understand the left-most derivation in the context of LL parsing algorithm. This link explains it from the generative perspective. i.e. It shows how to follow left-most derivation to generate a specific token sequence from a set of…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
0
votes
0 answers

LL(1) grammar for boolean expression

I have a Boolean expression for example (var1 = 10 and var2 > 5) or var3 < 100. I want to write an algorithm for syntax checking but I need to build the grammar first and then I need to construct a parse table. Can anyone please give a clue on the…
deb
  • 21
  • 1
0
votes
0 answers

turning grammar to LL(1)

can somebody please help me turn the following grammar to LL(1), and explain how he did it please? B → B and B | not B | ( B ) | id i need the not operator to have precedence over the and operator. thank you! edit: my results so far: B - > Eb' B'…
mike
  • 767
  • 2
  • 10
  • 18
0
votes
1 answer

Manipulate following grammar to be LL(1)

Suppose I was given the following grammar: start -> statement //cannot change statement -> assignment SEMICOLON statement -> function_call SEMICOLON assignment -> IDENTIFIER EQUAL expression function_call -> IDENTIFIER LPAREN parameters…
Jebathon
  • 4,310
  • 14
  • 57
  • 108
0
votes
1 answer

Is this grammar LL(1)

I have been asked to convert: S → Sa | bSb | bc to LL(1) so far I have: S → bY Y → SbF | cF F → aF | ε Is this LL(1)? If not would this be LL(1): S → bY Y → bYbF | cF F → aF | ε if neither of these would somebody please give me the correct…
vezbea
  • 1
  • 1
0
votes
1 answer

How to determine the k value of an LL(k) grammar

Suppose I'm given the grammar Z-> X X-> Y -> b Y a Y-> c -> c a The grammar is LL(K) What is the K value? All I know is its not LL(1) since there is a predict set conflict on Y and LL(1) grammar predict set must be disjoint.
RandomGuy
  • 4,949
  • 4
  • 16
  • 15
0
votes
1 answer

XText Dangling Else - The Other Option

So I've been using X-Text and playing with Syntactic Predicates. The classic example is the dangling else problem, where the solution given is to greedily parse the else statement, i.e. don't terminate the inner expression, like so: IfStatement: …
alexp82539
  • 77
  • 1
  • 5