Let's stop parser Hell

Timon Gehr timon.gehr at gmx.ch
Wed Jul 11 15:34:03 PDT 2012


On 07/11/2012 11:55 PM, David Piepgrass wrote:
> On Tuesday, 10 July 2012 at 23:49:58 UTC, Timon Gehr wrote:
>> On 07/11/2012 01:16 AM, deadalnix wrote:
>>> On 09/07/2012 10:14, Christophe Travert wrote:
>>>> deadalnix , dans le message (digitalmars.D:171330), a écrit :
>>>>> D isn't 100% CFG. But it is close.
>>>> What makes D fail to be a CFG?
>>> type[something] <= something can be a type or an expression.
>>> typeid(somethning) <= same here
>>> identifier!(something) <= again
>>
>> 'something' is context-free:
>>
>> something ::= type | expression.
>
> I don't see how "type | expression" is context free. The input "Foo"
> could be a type or expression, you can't tell which without looking at
> the context.

'Context free' means that all the production rule left hand sides do
not have a context, i.e. they consist of a single non-terminal.

What you are describing is the fact that the grammar is ambiguous. The 
parser can just assume whatever works and the analyzer takes care of the
interpretation of the resulting AST. The parser does not have to
give a meaning to the code. It just turns it into a representation that
is easy to work with.


More information about the Digitalmars-d mailing list