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

What other tools can help me create a small language targeting JVM, besides ANTLR?

(I started my language adventure with ANTLR several days ago. My knowledge about language theory and compiler construction is very limited. Excuse me if this is not a valid question.) ANTLR is a parser generator, and specifically, an ALL(*) parser.…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
3
votes
1 answer

How many ways are there to build a parser?

I am learning about the ANTLR v4, which is a parser generator based on so-called Adaptive LL(*) algorithm. It claims to be a big improvement over LL(*) algorithm, but I also heard about some algorithm like LR. What's the advantage/limitation of…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
3
votes
2 answers

Is it possible to write a recursive-descent parser for this grammar?

From this question, a grammar for expressions involving binary operators (+ - * /) which disallows outer parentheses: top_level : expression PLUS term | expression MINUS term | term TIMES factor | term DIVIDE…
user200783
  • 13,722
  • 12
  • 69
  • 135
3
votes
1 answer

Why this is not grammar LL(1)

I have been given a task to transform this grammar to LL(1) E → E+E | E-E | E*E | E/E | E^E | -E | (E)| id | num So for first step I eliminated ambiguity and got this: E → E+T | E-T | T T → T*P | T/P | P P → P ^ F | F F → id | num | -E | (E) And…
clzola
  • 1,925
  • 3
  • 30
  • 49
3
votes
1 answer

How to transform a grammar into a top-down parsable grammar

I have this part of a grammar S ‐> S a | S b a | a | S b c S | S b c b | c S | c b and I need to use it in order to create some SD sets and later on a parse table. But, before doing that, I should convert this into a top-down parsable grammar. My…
3
votes
0 answers

ANTLR4 generated parse trees using the C.g4 grammar have long repetitive structure

Due to the nature of top down parsing, ANTLR generates parse trees with some long repetitive structures with a lot of superfluous nodes before reaching a leaf inside expressions. For example, using the C.g4 grammar…
np20
  • 1,935
  • 3
  • 16
  • 24
3
votes
1 answer

Verify that a grammar is LL(1)

I want to verify that my ANTLR 4 grammar is LL(1). There is an option to do just that in older versions of ANTLR. Is there something similar in ANTLR 4? I looked through through the documentation, but didn't find anything. Though especially the page…
svick
  • 236,525
  • 50
  • 385
  • 514
3
votes
1 answer

Converting a context free grammar into a LL(1)

I have the following grammar: S -> S+S|SS|S*|(S)|a How do I convert it into a LL(1) grammar? I tried to eliminate left recursion so I got S->(S)S'|aS' S'->+SS'|SS'|*S'|epsilon I also tried to do left factoring first and then eliminate left…
arpat
  • 41
  • 3
3
votes
1 answer

Make the Grammar LL

I already wasted two much time on converting it, but I always get up getting common prefix ID. Can anyone explain it to me? as I am trying to do it for a very large grammar and need my basics clear. A, B, C, D are the only Non-Terminals. A : ‘(‘ B…
3
votes
1 answer

Markdown blockquote parsing with ANTLR

This has been something that's been bothering me for a while. How does one go about parsing the following text into the HTML below using ANTLR? I can't seem to wrap my head around this at all. Any Ideas? Markdown: > first line > second line > >…
Scott
  • 10,407
  • 13
  • 37
  • 35
2
votes
1 answer

Epsilon(ε) productions and LR(0) grammars and LL(1) grammars

At many places (for example in this answer here), I have seen it is written that an LR(0) grammar cannot contain ε productions. Also in Wikipedia I have seen statements like: An ε free LL(1) grammar is also SLR(1). Now the problem which I am facing…
Abhishek Ghosh
  • 597
  • 7
  • 18
2
votes
1 answer

How to have shortest match first when implementing mark down text styling operators in an antlr4 grammar?

I found the following (simplified) grammar on the internet as I was looking for a solution to a problem where I had to parse syntax similar to Markdown. grammar Markdown; parse : stat+; stat : bold | text | WS …
Tobias Marschall
  • 2,355
  • 3
  • 22
  • 40
2
votes
1 answer

Why are all LL(1) grammars LR(1)?

It's a widely-known fact that any LL(1) grammar is also LR(1), but I can't seem to find a rigorous proof of this anywhere. I've heard some high-level overviews of the proof (for example, that since an LL(1) grammar has its productions determined…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
2
votes
0 answers

Is it possible to deal with left recursion in LL by checking the length of the sentential form and discarding infinitely ambiguous grammars?

I understand that an LL parser (no lookahead) cannot deal with left recursive rules due to the fact it will keep on predicting the left recursive non terminal over and over again and would never be able to match. But what if we adopted the…
2
votes
0 answers

How to rewrite this grammar for LL(1) parsing?

I am trying to write a top-down recursive-descent parser for a small language, and I am facing some issues with the assignment statements. Here is the grammar from the language specifications: ::= ":="
Touloudou
  • 2,079
  • 1
  • 17
  • 28