1

I'm recently interested in writing a parser for Java language. My reference is newly released Java SE 16 spec. On 3.2. Lexical Translations, I come across this sentence but I'm not sure whether I get it:

... There is one exception: if lexical translation occurs in a type context (§4.11) and the input stream has two or more consecutive > characters that are followed by a non-> character ...

What I don't understand is how to tell whether it is a "type context" when the lexical analysis is not even done? (§4.11 would probably provide an answer but it's too long so I haven't bother to read it at full) Is the trick here to seperate each > character as individual tokens and disambiguate it later when it comes to parsing stage? Or is there something obvious that I missed - as I don't have much experience writing language parsers.

Just to provide a bit more context I'm using Alex for lexing and (plan on using) Happy for parsing.

Javran
  • 3,394
  • 2
  • 23
  • 40
  • 1
    Don’t know how this works in Haskel, but in Java, I’d use a a lazy Lexer whose `nextToken` method has an `inTypeContext` parameter which can easily be provided by the Parser when trying to match a rule. Otherwise, a Lexer indeed can’t know the context, so a non-lazy Lexer has no choice to produce either token unconditionally. In such an implementation, the Parser has to know that this token has to be converted in certain contexts. – Holger Dec 06 '21 at 17:13

0 Answers0