[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parser tools: How to make the lexer context sensitive?



I write:
> Flatt writes
>
> | If I remember correctly, the standard solution is to have a
> | table of `typedef'ed names. When the parser encounters a typedef,
> | it puts the type name into the table. So the test above would
> | be "is (get-lexeme) in the table?".
>
> This works.

Almost. But not quite. There are different namespaces and scopes for
different
types. McKeeman wrote the article "Resolving typedefs in a multipass C
compiler".

    http://www.gorillaman.com/mckeeman/writings/typedef/typedef.html

A little quote from the introduction.

    C fails to be LR(1) because of a conflict between identifier and
typedef-name.
    The situation is illustrated by the following fragment:
        static X(Y)
    This text starts a declaration of Y if X is a typedef-name and Y is not.
It starts
    a function prototype for X if Y is a typedef-name and X is not. It
starts an old-style
    function-definition if neither X nor Y is a typedef-name. There are
similar conflicts
    for casts and parenthesized expressions and function calls.

No wonder why everybody write interpreters and compilers for Scheme and not
C.

--
Jens Axel Søgaard