How do Java, C++, C#, etc. get around this particular syntactic ambiguity with < and>?

后端 未结 2 1249
谎友^
谎友^ 2021-01-31 03:50

I used to think C++ was the \"weird\" one with all the ambiguities with < and >, but after trying to implement a parser I think I found an exampl

2条回答
  •  情书的邮戳
    2021-01-31 04:25

    I just can't imagine any non-hacky/context-free way of dealing with this, and I'm baffled at how any such language can be context-free, let alone LALR(1)-parsable...

    The answer is that they aren't (at least not Java and C++; I know very little about C#). The Java grammar that you link to dates back to 1996, way before generics have been introduced.

    For further discussion, see Are C# and Java Grammars LALR(x)?

提交回复
热议问题