182 questions
1
vote
1
answer
96
views
Is LR(0) GOTO different from LR(1) GOTO?
I'm writing an LALR(1) parser generator, and am getting a bit confused about the use of the GOTO function in creating the parsing table. I've been following the dragon book. The grammar I have been ...
0
votes
0
answers
32
views
Why does this LALR grammar rule have a Reduce/Reduce conflict? How to resolve it?
My grammar file looks like this: https://github.com/EmptyDreams/php-parser/blob/master/src/main/resources/php.cup
When I build it using java-cup, I encounter a Reduce/Reduce conflict:
Warning : *** ...
1
vote
0
answers
53
views
LALR Parser Shift/Reduce Conflict
I am writing a microJava compiler and I am currently implementing class logic. So far I have implemented field logic but I am struggling with method access. The code bellow is working properly (for ...
1
vote
1
answer
245
views
Construct the SLR parsing table for the following Grammar
S → 0S0
S → 1S1
S → 10
found 2 possible paths on canonical item i3 for 0 input.
in my solution:
I0 was
S'-> .S
S → .0S0
S → .1S1
S → .10
I1 was(S input from I0)
S'-> S.(accept)
I2 ...
1
vote
1
answer
535
views
What do reduce/reduce and shift/reduce conflicts mean in terms of the grammar structure? [closed]
I have to construct LR(0) table to know if there are any sort of conflicts? Is there a way to look at the grammar and tell if there's a conflict without constructing the table? So yeah, the question ...
0
votes
1
answer
36
views
How can I solve this Shift/Reduce conflict?
I am getting shift/reduce conflict
The following is my .cup specification:
terminal PROG, SEMI, RANGE, VOID;
terminal PP, MM, READ, LPAREN, RPAREN, DCOL; terminal
MUL, DIV, MOD, ...
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 ...
2
votes
0
answers
129
views
Time complexity of LALR construction
According to the dragon book, the algorithm for LR(1) state machine is:
initialize C to Closure([S` -> .S, $])
repeat
for each state in C
for each grammar symbol X
if Goto(...
-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
54
views
Can the grammar of the concatenation of two lists with common elements be written as an LALR grammar without any collisions
Can the following ABNF rules be written as a bison LALR grammar without any conflicts (shift/reduce or reduce/reduce)?
Among them, lowercase letters are non-terminal symbols, and uppercase letters are ...
0
votes
1
answer
83
views
can't understand this LALR(1) parsing algorithm in aho & Ullman book
The algorithm for computing the lookaheads](https://i.sstatic.net/T3Yzb.jpg)](https://i.sstatic.net/T3Yzb.jpg)
The algorithm says to compute $CLOSURE( { [A \rightarrow \alpha . \beta , # ]}) $
In the ...
0
votes
2
answers
105
views
Accept an optional substring with Lark's LALR(1) parser
I would like to use Lark to generate a standalone parser for a small rational language of mine. This needs to be a LALR(1) parser.
It should accept the following input:
(lorem) consectetur adipiscing ...
0
votes
1
answer
148
views
LALR(1) Parser DFA Lookahead Core Question
I am having trouble understanding what the rules are for adding a lookahead to a core production during the construction of the DFA. To illustrate my confusion, I will be using an online parser ...
0
votes
1
answer
112
views
How to turn a Grammar to LR(0)
Is there a general algorithm that turns a given grammar into LR(0) grammar?
I tried turning the grammar into CNF but even when I succeeded it didnt work out to be LR0
0
votes
1
answer
388
views
How can I resolve this shift-reduce conflict?
I'm following Appel's book Modern Compiler Implementation in ML and am trying to write a grammar for Tiger. Here's my first attempt:
%%
%term
EOF
| ID of string
| INT of int | STRING of ...
0
votes
1
answer
72
views
How to understand Example-4.64 of the syntax analysis chapter in Dragon Book?
everybody!
When I learn dragon book, I encountered some trouble. I can't understand the first step in Eaxmple-4.64, which appears in subsection 4.7.5 and page 273.
Problem
At first, Eaxmple-4.61 gives ...
1
vote
1
answer
164
views
LALR, LR(1) and SLR
Since LR (1) grammars are broader than LALR or SLR grammars, I have doubts regarding the proof of LR grammars. If a grammar is SLR or LALR, then does that mean that the grammar is also LR (1)?
In fact,...
0
votes
1
answer
132
views
How to resolve a shift/reduce conflict for nested lists using the same separator in JFLEX/CUP?
I'm trying to implement a parser in JFLEX/CUP (JFlex 1.8.2, Cup 0.11b) for a language in which lists containing different kinds of elements can be nested (e.g. lists of statements and statements ...
0
votes
0
answers
135
views
LALR Grammar desambiguation for function calls statements (as in Python grammar)
I'm trying to write a simple LALR parser for a custom DSL. My grammar looks like this :
main : stmts
stmts : expr stmts
|
expr : arithmetics
| function_call
| VARNAME
| INT
...
1
vote
1
answer
145
views
Should a merge failure stop the LR(1) to LALR(1) conversion
Let's say I have got a set of LR(1) states and I want to try to convert it to LALR(1).
I did the first step of finding states that have got the same LR(0) core and now I'm doing the merge process. ...
0
votes
0
answers
111
views
How to handle operator precedence in LALR(1) parser
I was writing an LALR(1) parser for a simple arithmetic grammar
E -> E ('+' | '-') T
E -> T
T -> T ('*' | '/') F
T -> F
F -> '( E ')'
F -> int
How would I handle operator precedence ...
0
votes
0
answers
166
views
Python LARK: terminal character inside text confusion
I'm trying to parse using Python Lark the output of a plan from a database. Here's my grammar:
start: op
op: command "(" op ")" "[" text "]"
| command &...
0
votes
1
answer
153
views
yacc parser reduces before left recursion suffix
I wrote a pretty simple left-recursive grammar in yacc, based on data types for a simple C-like language. The generated yacc parser reduces before the left recursion suffix, and I have no clue why.
...
-1
votes
1
answer
92
views
LALR(1) Parser Not Parsing The Text At All
I have to admit I'm an absolute newbie in this and might not even understand what I am doing.
I am trying to make a grammar that at least contains grammar from BABA IS YOU, and if possible expands on ...
0
votes
0
answers
103
views
Shift/reduce conflict with LALR grammar
I am writing a grammar where I'd like certain functions to be only at the top-level of the expression while arithmetic operations can be anywhere. E.g. 4 + (5 * 9) is correct, FUNC(2 + 4) * 8 - FUNC(4)...
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
1
vote
1
answer
371
views
Grammar rules for parsing optional keywords from list of words with LALR
I have strings with words like this:
"ABC Some other stuff" (normaly there is a short letter combination at the beginning)
"Some other stuff" (sometimes there is nothing ...
1
vote
1
answer
877
views
What is the shift/reduce conflict in this SLY program?
I'm porting a code from pyparsing to SLY, it's a lambda calc grammar. I have this rule
from sly import Lexer, Parser
class Lex(Lexer):
tokens = {ID, LAMB, DOT, LPAR, RPAR}
ID = r"[a-z]&...
0
votes
0
answers
100
views
How to remove ambiguity in grammar using CUP?
I have this grammar
S-> Stat
Stat -> Exprs WRITE
Stat -> Vars READ
Vars -> ID COMMA Vars
Vars -> ID
Exprs -> Expr COMMA Exprs
Exprs -> Expr
Expr -> ID
Expr -> ...
...
(You ...
0
votes
1
answer
224
views
Beaver parser generator shift-reduce conflicts connected to dangling else
I am feeding a (generated) grammar to Beaver parser generator. Multiple shift-reduce conflicts are caused by it seems like the dangling else problem in this rules:
Condition
= IF LPAR Expression....
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 ...
0
votes
2
answers
1k
views
Can LR(1) parsing table size be the same as LALR(1) parsing table for some grammar?
I know that LALR(1) grammars are a subset of LR(1) grammars and most of the time LALR(1) parsing table is much smaller than LR(1) parsing table for the same grammar. But I couldn't find the answer on ...
1
vote
1
answer
939
views
Parse trailing line comments with lark and LALR
Given are the following lark grammar and Python source code:
start: (TEXT _NEWLINE)+
TEXT: /[^\n]+/
COMMENT: /\/\/[^\n]*/ _NEWLINE
%ignore COMMENT
_NEWLINE: (" "* "\n")+
from lark import Lark
...
1
vote
1
answer
381
views
Ply shift/reduce conflicts: dangling else and empty productions
I had lots of conflicts, most of them were due to operators and relational operators which had different precedences. But I still face some conflicts that I don't really know how to tackle them. some ...
0
votes
1
answer
2k
views
Resolving shift/reduce conflicts in ply yacc
Ply is reporting that the it has encountered numerous shift/reduce conflicts while using the grammar I've entered to build a LALR parser.
Right now I'm trying to resolve these conflicts but whatever ...
2
votes
0
answers
514
views
Parsing Implicit Multiplication
I've been trying to set up a rather simple math parser, and it's been working fine. Only I can't figure out how to put in implied multiplication.
I've been using lark as an lalr(1) parser.
Here's ...
2
votes
2
answers
259
views
Why is my parser generating reporting that this LALR(1) grammar is not LALR(1)?
OK, my adventures with my parser generator continued. This time I got my hands on a classic grammar, which is said to be a LALR grammar:
start -> a a
a -> "A" a
a -> "B"
When I put it into ...
0
votes
2
answers
156
views
LALR(1) shift/reduce error using % for both percent and mod
I started a project with a grammar that used % (and the word mod) for modulus operators, and now I would like to add % as a trailing unary operator to divide by 100.
A few notes, I don't work with a ...
0
votes
0
answers
393
views
LALR parser being slower than recursive descent parser
Recently I wrote a (highly optimized) LALR(1) parser (that could handle ambiguous grammars) and supplied it a very ambiguous grammar. After that, I wrote a recursive descent parser for the same ...
1
vote
1
answer
103
views
Why a rule for each operation in Bison
While searching for Bison grammars, i found this example of C grammar:
https://www.lysator.liu.se/c/ANSI-C-grammar-y.html
logical_and_expression
: inclusive_or_expression
| ...
0
votes
1
answer
254
views
Can yacc be used to generate three address code for Java 1?
I have read that yacc generates bottom up parser for LALR(1) grammars. I have a grammar for Java 1 that can be used for generating three address code and is strictly LALR(1), but the translation ...
0
votes
1
answer
146
views
Solving small shift reduce conflict
I have had a shift-reduce conflict and reduced it to a couple of lines:
start : instruction_A;
instruction_A : instruction_A instruction
|
...
1
vote
1
answer
182
views
Meaning of YACC expression using yysindex and yyrindex
In a yacc-based project I've encountered a complex expression which I don't understand what it does. The expression is repeated multiple times, so it looks like copy-and-paste. In fact the same exact ...
1
vote
1
answer
167
views
SR conflict in a grammar - how to resolve it? (Lemon/yacc)
I have put together a grammar in Lemon (which is similar to YACC) but it is producing an S/R conflict.
I am not used to LALR parsing and don't understand what the problem is, nor how to resolve it.
...
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 */
...
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
801
views
Is it possible that going from LR(1) to LALR(1) introduces shift/reduce conflicts?
I am studying for a final in Language Theory and one question asks the following:
If you have a parsing table T in LR(1) and a parsing table T' in LALR(1) for the same grammar. Is it possible that T' ...
0
votes
1
answer
71
views
What is the problem in this yacc grammar?
I have a yacc parser in which commands like "abc=123" (VAR=VAR),
abc=[1 2 3] (VAR=value_series/string) and abc=[[123]] can be parsed.
I need to parse abc=[xyz=[1 2 3] jkl=[3 4 5]].This grammar is ...
7
votes
2
answers
1k
views
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 ...