Questions tagged [shift-reduce]
25 questions
7
votes
1 answer
Difference between shifting and look-ahead
Given a simple grammar, like
rule1
:= token1 token2 token3 token4
|| token1 token2 token3 token3;
What's the difference between shifting the first three tokens, then looking at the fourth to see which rule to reduce, and simply performing a…

Puppy
- 144,682
- 38
- 256
- 465
6
votes
1 answer
Solving parsing conflicts in a tiny Lemon grammar
I'm trying to learn basics of the Lemon parser generator, but I stuck quickly.
Here's a tiny grammar:
%right PLUS_PLUS.
%left DOT.
program ::= expr.
member_expr ::= expr DOT IDENTIFIER.
lhs_expr ::= member_expr.
expr ::= lhs_expr.
expr ::=…

Dmitry Frank
- 10,417
- 10
- 64
- 114
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
5
votes
2 answers
Shift-reduce: when to stop reducing?
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using recursive rules that enforce order of operations, inspired by the ANSI C Yacc grammar:
S: A;
P
: NUMBER
| '(' S ')'
;
M
: P
| M '*'…

Joey Adams
- 41,996
- 18
- 86
- 115
3
votes
1 answer
Shift/reduce conflict in yacc due to look-ahead token limitation?
I've been trying to tackle a seemingly simple shift/reduce conflict with no avail. Naturally, the parser works fine if I just ignore the conflict, but I'd feel much safer if I reorganized my rules. Here, I've simplified a relatively complex grammar…

Skyler
- 612
- 6
- 12
2
votes
0 answers
Context Free Grammar using Shift Reduce Parser
I am trying to use the Shift Reduce Parser for the following sentence:
He eats pasta with some anchovies in the restaurant
I have created some code and grammar BUT the grammar only works up to:
He eats pasta with some anchovies
import nltk
from…

ScuffedCoder
- 376
- 1
- 5
- 21
2
votes
2 answers
if-else statement in bison
I'm trying to do the if-then statement in bison. The problem is that im working on a solution that everyone says that is working, but it doesnt :( my code is:
statement : matchedstmt
| unmatchedstmt
;
matchedstmt : if '(' expression ')'…

Marilenhh Xd
- 21
- 1
- 2
1
vote
1 answer
How does a shift reduce parser know what rule to apply?
When writing a shift reduce parser, how does a shift reduce figure out what rule to apply efficiently? For example, if I have the following rules
S –> S + S
S –> id
How would the parser quickly determine the rule to apply in the following parse…

Yogesh Thambidurai
- 222
- 4
- 10
1
vote
0 answers
Missing shifted value in Shift-Reduce Parsers
I'm using the code for Shift-Reduce Parsers from geeksforgeeks and changed a few rules and my rule are:
P->E,
E->E + T
T->T*F | F
F->( E ) | id
void check()
{
// Coping string to be printed as action
strcpy(ac,"REDUCE TO…

lht_18018
- 64
- 6
1
vote
0 answers
Training Stanford RSS and Shift Reduce parsers for a new language
I would like to train the constituency based Stanford Parsers (RSS and Shift Reduce) with an existing treebank, but cannot find enough information online to be able to do so. Two key questions:
In what format should I export my treebank to be able…

player.mdl
- 113
- 4
1
vote
2 answers
How to overcome shift-reduce conflict in LALR grammar
I am trying to parse positive and negative decimals.
number(N) ::= pnumber(N1).
number(N) ::= nnumber(N1).
number(N) ::= pnumber(N1) DOT pnumber(N2).
number(N) ::= nnumber(N1) DOT pnumber(N2).
pnumber(N) ::= NUMBER(N1).
nnumber(N) ::= MINUS…

Pdksock
- 1,042
- 2
- 13
- 26
1
vote
1 answer
C - Process exited with error code 3221225477
I'm doing a shift-reduce algorithm for our compiler design subject. This is the code.
void shiftReduce(char str[MAX_CHAR], int prodNum, int line)
{
int limit = 5, y=0;
int substrFlag = 1; //0 true 1 false
int ctr,x, counter;
int…

Kenneth Sumang
- 61
- 1
- 1
- 11
1
vote
1 answer
NLP Shift reduce parser is throwing null pointer Exception for Sentiment calculation
I am trying to analyze sentiment using nlp. The version of stanford-nlp I am using is 3.4.1. I have some junk data to process and it looks like it takes around 45 seconds to process using default PCFG file.
Here is the example:
String text = "Nm…

user2052854
- 89
- 10
0
votes
1 answer
Bison Shift/Reduce conficts
//parserr.y
//tokens
---------
/* precedences */
%left T_LPAREN T_RPAREN
%left T_MULOP T_DIVOP
%left T_ADDOP
%left T_ANDOP
%left T_OROP
%left T_NOTOP
%right T_POWEROP
%right T_ASSIGN
…

thebaby
- 95
- 1
- 7
0
votes
1 answer
Solving a parsing conflict in SQLite grammar
I'm trying to extent the SQL language of SQLite at one point (file parse.y). I have a parsing conflict, however the lemon parser does not show anything besides a random "1 parsing conflicts." error message.
The problem is located where create_table…

benjist
- 2,740
- 3
- 31
- 58