Are C# and Java Grammars LALR(x)?

后端 未结 3 1224
盖世英雄少女心
盖世英雄少女心 2020-12-05 14:53

I wonder if C# and Java grammars are LALR(x)? If yes, what\'s the value of x?

Edit:

After accepting the true answer, I think it is better t

3条回答
  •  庸人自扰
    2020-12-05 15:10

    The Java grammar (version 1.0) is known to be LALR(1); this site provides a grammar and begins with the notice that

    The grammar has been mechanically checked to insure that it is LALR(1).

    I am not sure whether C# is LALR(1), but there is a C# parser written in bison available here, which suggests that it's probably LALR(1) (assuming that you allow for precedence declarations).

    For what it's worth, typically LALR(1) is the only LALR parser used. If you need to use something like LALR(2) for a grammar, it is typically a better idea to use a LALR(1) parser with explicit precedence disambiguation, or a more powerful parser like a GLR parser.

    Hope this helps!

提交回复
热议问题