Question

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: the program prompts for input twice, so for example when i enter "qwerty" it prompt for a second input,when i try to debug it i get this:

Starting parse

Entering state 0

Reading a token: qwerty

Next token is token WORD

Shifting token WORD

Entering state 1

Reducing stack by rule 3 (line 20):

   $1 = token WORD ()

-> $$ = nterm cmd ()

Stack now 0

Entering state 3

Reading a token: 

(asks for input a second time)
Was it helpful?

Solution

How will it know which rule for s to employ until it tries to read SOMETHING and either succeeds (second rule) or fails (first rule)? Which means it HAS to ask for the second input.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top