On 11/16/2016 02:26 PM, Stephan Herrmann wrote:
On 11/16/2016 11:01 PM, Jonathan Gibbons wrote:


On 11/16/2016 01:41 PM, Stephan Herrmann wrote:

At the end of the day we need full pattern matching right?

Not really, at least, not in javac.

Words like 'module', 'requires', etc are lexed as identifiers. When we get to the point where the grammar would accept one of these words as a keyword, we simply check to see if we have an identifier with the appropriate value.

-- Jon

OK, feedback from the parser to the scanner to tell it
whether the current context accepts a specific restricted keyword.

And we may safely assume regularity of the grammar, i.e.,
the above approach will never lead to ambiguities, right?

Fictitious counter example

   ModuleDeclaration:
     module open Identifier ModuleBody;
     module Identifier ModuleBody;

With this the second token could be keyword or identifier, and we're stuck, aren't we?

May we assume that the grammar will not be extended in such ambiguous ways?

I'll leave it to Alex to declare definitively on that, but I think that would be a reasonable assumption. :-)


For all tools that read from the start of the file this is good news.

Still no good news for tools wishing to process just a fragment of the text.


Just how small a fragment, and in how unknown a context are you worried about? Yes, if you're wanting to locally analyse the character string "module" in isolation, then yes, you cannot say whether it is a keyword or an identifier, but if you know you're in a ModuleBody, then "exports to to exports;" can be processed just fine.


thanks,
Stephan

Reply via email to