Re: Keyword Caution (was: keyword 'cell')

From: Paul Graham (pgraham@cadence.com)
Date: Fri Nov 30 2001 - 07:54:19 PST


Precedence: bulk

> I agree with you Steve, that lex, yacc have the ability to have
> several rule sets for parsing keywords, identifiers, etc. And
> I have utilized these abilities successfully to parse verilog,
> -f files, etc. But it seems that not all places utilize
> tools with these capabilities.

It's not whether the tool can handle it. Actually, I'm using yacc plus a
hand-written lexer, so I have a lot of flexibility in what I can parse. The
only question is whether to make keyword recognition context-sensitive.

It would be possible to allow "cell" even as a module identifier, because in
a configuration block, the name following the keyword "cell" can always be
treated as an identifier:

    cell cell

is unambiguous, since the first "cell" is the keyword and the second "cell"
is the module name.

VHDL does something like this in allowing x'range, since "range" is a
keyword. The yacc grammar for a vhdl attribute name might look like this:

    attribute_name :
        prefix ' identifier
        | prefix ' kw_range
        ;

And so the yacc grammar for a cell clause could look like this:

    cell_clause :
        kw_cell identifier
        | kw_cell kw_cell
        ;

Or cell could simply be made into a non-keyword:

    cell_clause :
        identifier identifier
           { ... check whether strcmp($1, "cell") ... }

But all this context-sensitivity requires a lot of thought to make sure
nothing gets screwed up. That's why the world has moved to
context-insensitive keyword recognition -- it makes it easier to reason
about grammars.

Paul



This archive was generated by hypermail 2.1.4 : Mon Jul 08 2002 - 12:54:48 PDT and
sponsored by Boyd Technology, Inc.