LL(k) grammars are grammars that can be parsed from left-to-right, creating a leftmost derivation, using k tokens of lookahead.
Questions tagged [ll-grammar]
209 questions
13
votes
1 answer
How to construct parsing table for LL(k>1)?
On the web, there is a lot of examples showing how to construct parsing tables for a context-free grammar from first/follow sets for LL(1) parser.
But I haven't found anything useful related to k>1 cases. Even wikipedia gives no info about this.
I…

Petr Kozelka
- 7,670
- 2
- 29
- 44
9
votes
2 answers
How to manually construct an AST?
I'm currently learning about parsing but i'm a bit confused as how to generate an AST. I have written a parser that correctly verifies whether an expressions conforms to a grammar (it is silent when the expression conforms and raises an exception…

horseyguy
- 29,455
- 20
- 103
- 145
8
votes
1 answer
Relationship between LR(0), LL(0), LALR(1), etc?
I'm really struggling to unterstand the relationship between:
LR(0)
LL(0)
LALR(1)
SLR(1)
LR(1)
LL(1)
I'm pretty sure LALR(1) and SLR(1) are subsets of LR(1), but I'm lost about the others. Are they all exclusive? Is LL(0) a subset of…

Ahmed Elbannan
- 101
- 1
- 1
- 5
8
votes
2 answers
LL(1) parser implemented with stack: how to build AST?
I am currently building a parser by hand. It is a LL(1) parser. At the moment, it is a great recognizer: its function parse(List tokens) decides whether or not tokens is a member of the language or not.
Now, I want to build the corresponding AST for…

user1553136
- 328
- 5
- 17
8
votes
2 answers
Algorithm for computing FIRST and FOLLOW sets for context-free grammars
I need an algorithm to computing FIRST and FOLLOW sets for a grammar.
Is there a simple algorithm or simple code for computing these?

Vahid Kharazi
- 5,723
- 17
- 60
- 103
8
votes
1 answer
Making a Grammar LL(1)
I have the following grammar:
S → a S b S | b S a S | ε
Since I'm trying to write a small compiler for it, I'd like to make it LL(1). I see that there seems to be a FIRST/FOLLOW conflict here, and I know I have to use substitution to resolve it, but…

John Roberts
- 5,885
- 21
- 70
- 124
7
votes
1 answer
Finding a language that is not LL(1)?
I've been playing around with a lot of grammars that are not LL(1) recently, and many of them can be transformed into grammars that are LL(1).
However, I have never seen an example of an unambiguous language that is not LL(1). In other words, a…

templatetypedef
- 362,284
- 104
- 897
- 1,065
7
votes
1 answer
Precedence of shell operator
I'm currently trying to re-code a shell in C using a BNF and LL parser.
Otherwise, I need to know what is the precedence of shell operator of
|, <<, ,, <, >>, >, &, ;?
Is there anyone who can provide me it ?
Thank you

S7_0
- 1,165
- 3
- 19
- 32
7
votes
2 answers
ANTLR: Difference between backtrack and look-ahead?
I relative new to ANTLR. I have an very easy grammar:
start :
('A' 'B' 'C' '1'
|'A' 'B' 'C' '2'
|'A' 'B' 'C' '3'
)
;
I think that I already understand the basics of the concept of look ahead and backtracking (which works with syntactic…

Veilchen4ever
- 357
- 7
- 16
6
votes
2 answers
Is there any example of language grammar that possible for Yacc to express but impossible for Antlr4?
I try to learn about language parser recently and always seen the review about difference in Yacc and Antlr (about LALR and LL). It was always some concluded wording like "LALR is more powerful". But I can't understand what its really means
So could…

Thaina Yu
- 1,372
- 2
- 16
- 27
6
votes
1 answer
Isn't an LR(0) parser using lookaheads as well?
An LL(1)-parser needs a lookahead-symbol for being able to decide which production to use. This is the reason why I always thought the term "lookahead" is used, when a parser looks at the next input token without "consuming" it (i.e. it can still be…

fishbone
- 3,140
- 2
- 37
- 50
6
votes
2 answers
How to prove left-recursive grammar is not in LL(1) using parsing table
I have a grammar and would like to prove that it is not in LL(1):
S->SA|A
A->a
As it is a left-recursive grammarm, to find the first and follow sets I eliminated the left recursion and got:
S->AS'
S'->AS'|Empty
A->a
first of A={a} follow of…

rajkumar
- 365
- 5
- 10
6
votes
2 answers
Can a table-based LL parser handle repetition without right-recursion?
I understand how an LL recursive descent parser can handle rules of this form:
A = B*;
with a simple loop that checks whether to continue looping or not based on whether the lookahead token matches a terminal in the FIRST set of B. However, I'm…

chbaker0
- 1,758
- 2
- 13
- 27
5
votes
1 answer
How to left factor a context-free grammar?
As I understand, in the following case left factoring is required to build top-down parser.
But it's hard to understand how to do that? Can someone help me here? Thanks.
s = a | b
b = c d
c = (e | f) g
e = a | h

Bee
- 12,251
- 11
- 46
- 73
5
votes
1 answer
John Hughes' Deterministic LL(1) parsing with Arrow and errors
I wanted to write a parser based on John Hughes' paper Generalizing Monads to Arrows. When reading through and trying to reimplement his code I realized there were some things that didn't quite make sense. In one section he lays out a parser…

Ace shinigami
- 1,374
- 2
- 12
- 25