lexical grammar

Discussion in 'C Programming' started by aegis, Feb 13, 2005.

  1. aegis

    aegis Guest

    let's say we have the following declaration:

    volatile int (*func)(int a);

    We start with a declaration (A.2.2)
    that expands to declaration-specifiers?
    We find the right form:
    type-qualifier declaration-specifiers opt?
    after volatile is expanded, we look for
    type specifier:
    type-specifier declaration-specifiers opt

    So after that is expanded we have:
    (*func)(int a);

    this counts as a init-declarator?
    If so, then we expand it as a declarator
    since it is not being initialized?

    Then that brings us to the rule:
    pointer opt direct-declarator
    for (*func)(int a);

    No pointer encountered yet, so we continue
    expanding:

    direct-declarator:
    identifier
    ( declarator )
    direct-declarator [ type-qualifier-list opt assignment-expression opt ]
    direct-declarator [ static type-qualifier-list opt
    assignment-expression ]
    direct-declarator [ type-qualifier-list static assignment-expression ]
    direct-declarator [ type-qualifier-list opt *]
    direct-declarator ( parameter-type-list )
    direct-declarator ( identifier-list opt )

    We encounter ( declarator )
    and reapply this rule?

    If so, then the rule pointer opt direct-declarator
    for declarator works here and we expand
    the declarator part which qualifies as an
    identifier. But that leaves us with:
    (int a);

    Which I wonder, where is the rule that should
    be applied here that follows from our expansion?

    Somewhere in the rules of direct declarator
    we should branch to a rule that solves a parameter
    list. But because our construction was (*func),
    we should ignore the identifier in parens after
    resolving that it was an identifier from
    the direct declarator rule, right?

    This is where I don't see how we branch to
    a rule that resolves the parameter list.

    I don't think it would be the following
    rule:
    direct-declarator ( parameter-type-list )
    unless we consider the expanded identifier
    as a direct declarator?

    Also, chris torek, if you are reading this,
    what data structure would you recommend for
    representing this? I read an older
    article by you that describes this process
    as being in factored form. How do you recommend
    to factor it all programmatically?

    --
    aegis
    aegis, Feb 13, 2005
    #1
    1. Advertising

  2. aegis

    Richard Bos Guest

    "aegis" <> wrote:

    > Then that brings us to the rule:
    > pointer opt direct-declarator
    > for (*func)(int a);


    You are (AFAICT!) OK up to here, but...

    > No pointer encountered yet, so we continue
    > expanding:
    >
    > direct-declarator:
    > identifier
    > ( declarator )
    > direct-declarator [ type-qualifier-list opt assignment-expression opt ]
    > direct-declarator [ static type-qualifier-list opt
    > assignment-expression ]
    > direct-declarator [ type-qualifier-list static assignment-expression ]
    > direct-declarator [ type-qualifier-list opt *]
    > direct-declarator ( parameter-type-list )
    > direct-declarator ( identifier-list opt )
    >
    > We encounter ( declarator )
    > and reapply this rule?


    ....if so, we run into problems (as you see), so we take the next option
    that applies, which is

    direct-declarator ( parameter-type-list )

    The first part (the direct-declarator) matches (*func), which you've
    already done; the second part - ( parameter-type-list ) - matches the
    (int a).

    > This is where I don't see how we branch to
    > a rule that resolves the parameter list.
    >
    > I don't think it would be the following
    > rule:
    > direct-declarator ( parameter-type-list )
    > unless we consider the expanded identifier
    > as a direct declarator?


    And you've just proved that it is, so all is fine, surely?

    > Also, chris torek, if you are reading this,
    > what data structure would you recommend for
    > representing this?


    A tree, most likely.

    Richard
    Richard Bos, Feb 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    3
    Views:
    1,138
  2. Collin VanDyck
    Replies:
    0
    Views:
    315
    Collin VanDyck
    Nov 30, 2004
  3. Collin VanDyck
    Replies:
    0
    Views:
    421
    Collin VanDyck
    Nov 30, 2004
  4. Ron

    Lexical convention

    Ron, Aug 30, 2003, in forum: C++
    Replies:
    0
    Views:
    385
  5. cricket

    Python lexical scanner

    cricket, Sep 25, 2003, in forum: Python
    Replies:
    0
    Views:
    451
    cricket
    Sep 25, 2003
Loading...

Share This Page