LR1 Parser and Epsilon

前端 未结 1 696
故里飘歌
故里飘歌 2021-01-13 05:01

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:



        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 05:24

    Yes, exactly (think of the epsilon as empty space, where there aren't two places for the dot at the sides).

    In an LR(0) automaton, you would make the state accepting and reduce to A. However, due to the A->a A a production, there'd be a shift/reduce conflict.

    In a LR(1) automaton, you would determine whether to shift or reduce using lookahead (a -> shift, anything in FOLLOW(A) -> reduce)

    See the Wikipedia article

    0 讨论(0)
提交回复
热议问题