Fw: Bison and [f]lexical tie-ins

Fw: Bison and [f]lexical tie-ins

Post by Christopher Nelso » Sun, 11 Jul 1999 04:00:00



-----Original Message-----


Date: Friday, July 09, 1999 11:14 PM
Subject: Bison and [f]lexical tie-ins

>    The manner you described for your lexical tie-in, is not *exactly* the
>way it should work.  From your text, it sounds as if you're returning the
>type of the id? or perhaps a different token? depending on what you see the
>id as.  This is ambiguous, and creates the errors you described.

>    A better approach is to do the following:

>{ID}    yylvalue.id = install_id(yytext); return ID;

>    In this case, the lexical tie-in makes sure that the lexme that
>corresponds to this particular id is in the symbol table to start with -
but
>without a type.  Or more precisely, type_none.  If the lexme DOES match a
>symbol already in the table, that symbol is returned, otherwise the newly
>created symbol is returned.

>    Inside the parser you should check to see what the type of the symbol
is
>(pretending that $1 is your ID token):

>        if (lookup($1)==TYPE_NONE) addtype($1, the_type);
>       else /* this lexeme exists as a symbol of a different type, you'll
>have to create a
>                    new symbol */ { $1=duplicate_id($1); addtype($1,
>the_type); }

>    This follows C's most-closely nested rule by allowing you to get the
>last-declared version of a symbol first (assuming that your storage
>structure is a list of some sort) by starting at the head of the list and
>seeking towards the end.

>    You should, in addition, have some sort of prologue code on the same
>level as the parameter list nonterminal that sets a global-variable called
>type so that you can use it, or alternatively (and more flexible and
>powerful, though a bit more difficult), construct a small type-tree that
>contains a list or perhaps a stack of the parameters, then walk the tree,
or
>consider the stack until it's empty, applying the above logic to each of
>them.

>    In other words:

>parameter:    id    { $$=$1; }
>                ;

>parameter_list:     parameter                            { push($1,
>parmstack); }
>                        parameter_list ',' parameter      { push($1,
>parmstack); }
>                ;

>decl_prologue:    var_type        { $$=$1; }
>                ;

>declaration:    decl_prologue parameter_list ';' { symentry *sym;

>while((sym==pop(parmstack))

>{ /* consider each one as shown

>above, deciding what to do with

>it based on the type rules. */

> }
>                                                                      }

>    This has the added benefit of then allowing you to warn about
>shadow-variables, and finding scope rules and type sets, rather than just
>returning the first thing you see.

>        -={C}=-

 
 
 

1. Bison and [f]lexical tie-ins

struct a {int a; int b;};
struct b {int a; int b;};

int main()
{
  int a, m(b j), b;
  b=7;
  return 0;
  }

This simple little program breaks any attempt I make to parse C code with
lexical tie-ins.  First of all, if 'a' is a struct, then the tie-in returns
it as a type and that breaks the syntax for "int a".  I found a way around
this by making my flex code a little smarter, and looking for things that
look like declarations, but that breaks with the m(b j) delcaration because
now it thinks b is a variable name.   And, worst of all, even if I could
resolve all of these problems, Bison uses a look-ahead token.  This means
that before 'b' gets identified as a local variable, 'b' get's read in (by
flex, from the line after) and called a typename and Bison sees it as
'typename = 7' which, of course, is a syntax error!  I could just remove
support for delcaring functions in a comma-delimiated list, but that still
wouldn't get rid of the last mentioned problem.  Any ideas or thoughts on
the situation would be appreciated.

--
     -Rolf Campbell (39)3-6318

2. NEED DRIVERS FOR HP THINK JET PRINTER.

3. FW: FW: Turbo Vision for dummies?

4. **HELP** - AS/400 Domino and ODBC

5. bison asks for .\shared\bison.simple

6. Sensible world of golf

7. Tying a floppy to a PC

8. BOOT-U-I/O ERROR and "Set"

9. I need Ctrl-Ins in BC 3.1 again

10. Trapping Ctrl-Alt-Del and Ctrl-Alt-Ins

11. Switch to COMMAND.COM ins

12. Plug-ins......?

13. Fw: Deletion of files with special characters in name]