34 questions
2
votes
2
answers
284
views
Failure to parse in LALRPOP
I have the following grammar expressed in Lalrpop:
use crate::ast::Expr;
grammar;
Id: String = <id:r"[a-z]+"> => id.to_owned();
pub ExprTy: Expr = {
#[precedence(level="2&...
2
votes
1
answer
45
views
how to check if two LR(1) parsing tables are identical in function?
I'm making an LR(1) parser generator, and want to validate it. My parser generator sorts the stuff differently so some states are identical to the reference output, but some are assigned to different ...
0
votes
1
answer
96
views
How to find the FOLLOW set of an LR0 Item?
I'm trying to implement an LR1 Parser, using the help in this wikipedia article. I have made a closure function for the LR0 Items, and when trying to make a closure for the LR1 items (the part about ...
-1
votes
2
answers
658
views
Is this grammar LALR(1)?
I have the following grammar:
S -> aSb
S -> c
It can be used for LR(1) parsers are there is no conflict. However, when I combine states with same LR(0) items and different lookaheads, I get a ...
1
vote
0
answers
150
views
Does Golang have LR(1) grammar?
Does Golang have LR(1) grammar? In other words, can any Golang code be parsed by LR(1) parser? If yes, can we get this grammar rules?
The question is about the latest Go versions 1.20+
I have tried to ...
2
votes
1
answer
990
views
LR(1) item sets for left recursive grammar
I read several papers about creating LR(1) item sets, but none of them pertained to left recursive grammars, such as those used for parsing expressions. If I had the following grammar,
E -> E + T | ...
0
votes
1
answer
357
views
Adding rule to Treesitter LR1 grammar changes precedence
I am trying to get operator precedence correct in a Treesitter grammar. Treesitter is a LR1 parser generator.
I have a straightforward artithmetic grammar, which partially looks like this:
...
1
vote
1
answer
426
views
Show that an LR(1) grammar that is not LALR(1) must have only reduce/reduce conflicts
Can someone please explain to me why an LR(1) grammar that is not LALR(1) must have only reduce/reduce conflicts
0
votes
1
answer
427
views
Why does this Grammar work in LALR(1) but not LR(1)
By all accounts, LR(1) should be more powerful in every way compared to LALR(1) since LR(1) builds a canonical collection of LR(1) items, and LALR(1) is just a better SLR(1) parser.
Then why does this ...
1
vote
1
answer
323
views
LR(1) Parser: Why adding an epsilon production makes r/r or s/r conflicts
I wanted to make a reader which reads configuration files similar to INI files for mswin.
It is for exercise to teach myself using a lexer/parser generator which I made.
The grammar is:
%lexer
...
2
votes
1
answer
369
views
Is QML Grammar LALR(1)?
Here is a QML grammar (extracted from https://github.com/kropp/intellij-qml/blob/master/grammars/qml.bnf):
/* identifier, value, integer and float are terminals */
qml ::= object /* Simplified */
...
1
vote
1
answer
317
views
Computing the FIRST & FOLLOW sets of a grammar
I have the following grammar:
S -> aXab
S -> Y
X -> bYa
X -> epsilon
Y -> Sc
I have computed the first and follow sets for this grammar and I would like to know if it is correct. Here ...
0
votes
0
answers
260
views
LR(1) parsing, problem with look ahead symbols
I understand the concept of LR(1) parsing and lookahead symbols. I have the solution to the exercise and it does not agree with my solution.
I'm trying to fill the LR(1) parsing table for the grammar ...
0
votes
1
answer
403
views
LR(1) table construction confusion
I'm confused on how to parse this grammar using LR(1):
S -> A
A -> A(A) | empty
I'm aware there is left recursion but I was told it isn't necessary to remove it for LR(1).
My item sets look ...
0
votes
1
answer
182
views
How to Parse a given LALR(1) Grammar
I'm having trouble parsing the following grammar using the LALR method.
s -> y
y -> dX | ydX
X -> e | Zd
z -> F | epsilon
I'm ok at the beginning, here is item state 0: (the , seperates ...
1
vote
1
answer
1k
views
Can a grammar ever be parsed by LL(1) but not with LR(1)?
For homework, I was given the following grammar:
S: D
D: AbBb | BaAb
A: ε
B: ε
I computed it using LL(1) just fine. The first sets were:
S: a, b
D: a,b
A: ε
B: ε
The follow sets were:
S: $
D: $
A:...
0
votes
1
answer
69
views
Which productions are considered in LR(1) lookahead?
I'm currently looking at two closure calculation examples using the tool at
http://jsmachines.sourceforge.net/machines/lr1.html
Example 1
S -> A c
A -> b B
B -> A b
Here, in the initial ...
2
votes
1
answer
487
views
LR(1) Shift/Reduce Disambiguation
Given input with repeating BLOCKs, where each block has repeating BEGIN EVENT and END EVENT entries (END EVENT always follows a BEGIN EVENT):
[TIMESTAMP] BLOCK
[TIMESTAMP] BEGIN EVENT
[TIMESTAMP] END ...
6
votes
1
answer
3k
views
LR(1) parsing table with epsilon productions
I'm having trouble building the collection of sets of items for LR(1) parsers with a grammar containing epsilon productions. For example, given the following grammar (where eps stands for epsilon)
S -...
0
votes
0
answers
75
views
Bison : shift-reduce conflicts even though %left %right directive [duplicate]
I know that most of the shift/reduce conflicts can be solved by using %left or %right directives. But even with that, I am getting conflicts. Following is a block of my grammar:
expression: ...
-1
votes
1
answer
295
views
LR(1) items and LALR(1) Parsing table how to do this?
From the grammar given below create LR(1) items and merge the sets of items having give the set of LALR(1) items. I am not sure how to construct from this grammar
B -> id | id ( B ) | B . id | B [ B ]...
0
votes
0
answers
114
views
LR(1) Automata: difference between items
I have a doubt regarding the LR(1) automata construction:
Is the state with the kernel [A->b., x] (state_1) equivalent to the state with the kernel [A->b.,x/y] (state_2)?
Like, if I'm on the state [...
1
vote
0
answers
303
views
Given a grammar, generate the LR(1) items
I am working on LR(1) items and I am having a bit of doubt and hoping someone can clarify for me. Given the following grammar, I must generate the LR(1) items. I generated the first item but am unsure ...
1
vote
1
answer
133
views
This parser generator says that this grammar isn't LR(1) but I have my doubts
I've written a parser generator in Java, after a few bumps (an early version didn't particularly like left recursion for example), I managed to make it work with some simple grammars (so i can verify ...
2
votes
1
answer
619
views
How do I translate LR(1) Parse into a Abstract syntax tree?
I have coded a table driven LR(1) parser and it is working very well however I am having a bit of a disconnect on the stage of turing a parse into a syntax tree/abstract syntax tree. This is a project ...
0
votes
0
answers
755
views
How to create Lr(1) parser for very simple programming language
I need to create the parser for code with variables, simple conditions, cycles and functions, something like:
f=1;
i=1;
while(i<10){
f=f*i;
i=i+1;
}
print(f);
I read a lot of theory, but I ...
0
votes
1
answer
723
views
How do I rewrite a context free grammar so that it is LR(1)?
For the given context free grammar:
S -> G $
G -> PG | P
P -> id : R
R -> id R | epsilon
How do I rewrite the grammar so that it is LR(1)?
The current grammar has shift/reduce conflicts ...
0
votes
0
answers
123
views
LR(1) - How to compute Lookaheads
I have trouble understanding how to compute the lookaheads.
Lets say that I have this extend grammar:
S'-> S
S -> L=R | R
L -> *R | i
R -> L
I wrote the State 0 so:
S'-> .S, {$}
S -&...
0
votes
1
answer
361
views
printing parse Tree as a dynamic list in c language
I have written a code in C to implement LR(1) parse table, however now I am facing a problem in printing the parse tree. How do we do that in C? The tree can have variable children and since the ...
2
votes
2
answers
2k
views
LR(1) grammar: how to tell? examples for/against?
I'm currently having a look at GNU Bison to parse program code (or actually to extend a program that uses Bison for doing that). I understand that Bison can only (or: best) handle LR(1) grammars, i.e. ...
1
vote
2
answers
3k
views
Where can I find a _simple_, easy to understand implementation of an LR(1) parser generator?
Where can I find a simple (as much as possible, but no simpler!) implementation of an LR(1) parser generator?
I'm not looking for performance, just the ability to generate the LR(1) states (item sets)...
0
votes
1
answer
107
views
what's the matter with this grammar
s : cmd
| cmd SOMETHING
cmd :WORD
WORD and SOMETHING are non null terminals
it's an LR1 grammar so bison should parse it without problems.
however i faced an unexpected problem in runtime:
...
0
votes
1
answer
251
views
Dealing with infinite loops when constructing states for LR(1) parsing
I'm currently constructing LR(1) states from the following grammar.
S->AS
S->c
A->aA
A->b
where A,S are nonterminals and a,b,c are terminals.
This is the construction of I0
I0: S' -> ...
8
votes
2
answers
7k
views
LR1 Parser and Epsilon
I'm trying to understand how LR1 Parsers work but I came up with a strange problem: What if the grammar contains Epsilons? For instance: if I have the grammar:
S -> A
A -> a A | B
B -> a
It'...