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

Why can't a left-recursive, non-deterministic, or ambiguous grammar be LL(1)?

I've learned from several sources that an LL(1) grammar is: unambiguous, not left-recursive, and, deterministic (left-factorized). What I can't fully understand is why the above is true for any LL(1) grammar. I know the LL(1) parsing table will…
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
2
votes
1 answer

How to parse this simple grammar? Is it ambiguous?

I'm delving deeper into parsing and came across an issue I don't quite understand. I made up the following grammar: S = R | aSc R = b | RbR where S is the start symbol. It is possible to show that abbbc is a valid sentence based on this grammar,…
rhody
  • 2,274
  • 2
  • 22
  • 40
2
votes
1 answer

Convert LALR to LL

I have this (working) LALR grammar for SABLECC: Package org.univpm.grail.sable; Helpers digit = [ '0' .. '9' ]; letter = [ [ 'a' .. 'z' ] + [ 'A' .. 'Z' ] ]; any_character = [ 0 .. 0xfffff ] ; States normal, complex; Tokens …
dierre
  • 7,140
  • 12
  • 75
  • 120
2
votes
0 answers

Removing first and follow set intersections for LL(1)

I'm currently working on a compiler construction for a project and I'm at the point in which I'm making my grammar LL(1) compliant. I've managed to replace the EBNF notation just fine, removed left recursions and did some factoring, but I seem to be…
Dimitre Bogdanov
  • 395
  • 1
  • 5
  • 18
2
votes
2 answers

Removing Ambiguity Caused By Dangling Else For LL(1) Grammars

In the case of the dangling else problem for compiler design, is there a reason to left factor it before removing ambiguity? We are transforming a CFG into an LL(1) grammar so my professor is asking us to first eliminate recursion, then left factor,…
2
votes
1 answer

LL grammar and FIRST

Suppose a chunk of LL grammar STATEMENT ::= ε | R R :: = print (variable) And I try to find the FIRST(Statement) FIRST(STATEMENT) = FIRST(ε) + FIRST(R) FIRST(R) = { print (variable) } My question is. Is the FIRST(R) correct ? Or the…
2
votes
1 answer

How does an LL parser evaluate this expression?

Considering this expression: 3 + 2 + 2 * 2 = ? Would it be 14?
user457942
  • 77
  • 2
  • 6
2
votes
1 answer

LL(1) Parse table for S → a | ba | c

I'm new to LL(1) parsing and am currently trying to figure out how to create a parse table for the language: S → Saa|b and S-> A|B A-> aa B-> bb and S → AB A → aa B → bb
2
votes
1 answer

"one or more" with LL parser

Let's say my grammar is: file = line, {line} line = ..., "\n" If I want to build a LL parser for that grammar, how should I implement the "one or more line"? I was thinking about changing the grammar to this: file = line line = ..., "\n", nl nl =…
user1361491
2
votes
1 answer

Why look ahead at most 1 input token?

I'm currently trying to implement LL parser but I have a question. Need I to look ahead at most 1 input token for verify if the user's input is syntactically correct or it's for another reason?
S7_0
  • 1,165
  • 3
  • 19
  • 32
2
votes
1 answer

How to convert this grammar to LL(1)?

S → Y | 1X X → 1X | 0 Y → Y 0 | 1X1 | 2X2 I do not understand how to do factoring or substitution when there are more than one of the same symbol. Thanking you.
ddudz
  • 23
  • 4
2
votes
1 answer

LL(1): non-ambiguous grammars and First/Follow Conflicts

I have an impression but I am not entirely sure it is right. If a grammar is not ambiguous, can it have First/Follow conflicts? I am fairly sure it can't, but I would like to have some confirmation. Thank you.
2
votes
2 answers

Parsing special cases

If I understand correctly, parsing turns a sequence of symbols into a tree. My question is, is it possible to use some standard procedure (LR, LL, PEG, ..?) to parse the following two examples or is it necessary to write a specialized parser by…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
2
votes
1 answer

ANTLR4 force LL(1)

How do I force ANTLR4 to accept LL(1) grammars only? As an academic exercise, we have to make an LL(1) grammar. However, ANTLR4 just accepts LL(*) grammars without warning that it's not LL(1). I understand that usually, LL(*) is preferable, but…
bcleenders
  • 43
  • 5
2
votes
1 answer

Removing Cyclic Recursion from a Context Free Grammar

I'm trying to solve the problem to write this CFG into an LL(1) parse table. However, the problem is that it has cyclic left recursion between L/A and I can't find any resources that explain how to do this. Here is the CFG in question: L -> Aa |…