1
$\begingroup$

Consider the following grammar:

Stmts -> Stmt | Stmts;Stmt

Stmt -> Var =E

Var ->id[E] | id

E-> id | (E)

in accepting state we get

S' -> stmts .

stmts -> stmts . ;stmt

isn't it a conflict ?

$\endgroup$
1
$\begingroup$

I don't think there is a real conflict here.

It does look like a shift/reduce conflict but if you are at the end of the input there is no ";" symbol that can be shifted so only reduction to S' applies.

There are ways you can deal with things that look like conflicts near the accepting state.

One is to have a pseudo token for end of input. This distinguishes a parse where you consume all the input from one where you have unconsumed tokens (garbage) remaining.

If you have a choice between which rules to apply you can have a preference for a reduction to the start symbol and thus to accepting rather than applying further rules.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.