Compiling Java 9
Jonathan Gibbons
jonathan.gibbons at oracle.com
Wed Nov 16 23:54:15 UTC 2016
On 11/16/2016 03:28 PM, Stephan Herrmann wrote:
> On 11/17/2016 12:10 AM, Alex Buckley wrote:
>> On 11/16/2016 3:03 PM, Stephan Herrmann wrote:
>>> On 11/16/2016 11:57 PM, Alex Buckley wrote:
>>>> On 11/16/2016 2:26 PM, Stephan Herrmann wrote:
>>>>> 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?
>>>>
>>>> There is already a production like this:
>>>>
>>>> ModuleStatement:
>>>> requires transitive ModuleName ;
>>>> requires ModuleName ;
>>>
>>> Outch!!
>>>
>>> So when you read "requires transitive" which rule are you parsing
>>> against?
>>> When do you decide whether transitive is a keyword or an identifier?
>>> I guess we have to wait until we matched the full rule.
>>> That requires backtracking, or what am I missing?
>>
>> Yes, you need to lookahead to a ;
>>
>> Alex
>
> So everything points at ';' to the rescue.
>
> Unfortunately, while a user types a line of text, this essential
> character will be missing until the very end, so tool support
> for incomplete lines will not be great.
>
> Not much we can do, I guess.
>
> OK, thanks to you both, I believe I understand the intention.
>
> I guess I made my point that I see tremendous difficulties
> in providing good tool support, and that I'm not convinced
> that the current definition matches to the intended solution.
>
> I mentioned that all this could probably be avoided by using
> an escape mechanism.
>
> That said I will stop harping on these points,
> Stephan
>
>
>
It is not quite as bad as that.
An identifier-that-might-be-a-keyword is definitely a restricted keyword
if it is followed by another identifier (including an
identifier-that-might-be-a-keyword) or static.
An identifier-that-might-be-a-keyword is definitely an identifier if it
is followed by a '.' or ';'.
So in the following horrible cases:
requires transitive transitive;
^ at this point you know the first
transitive was a restricted keyword and the second was an identifier
requires transitive transitive.transitive.transitive;
^ at this point you know the first
transitive was a restricted keyword, and that the second and any
subsequent instances are identifiers.
requires transitive static a.b.c.d.e.f.g.h.i.j;
^ at this point you know transitive was a
restricted keyword
In other words, you don't need unbounded lookahead.
-- Jon
More information about the jigsaw-dev
mailing list