bison-patches
[Top][All Lists]
Advanced

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

Accepting GCJ's grammar


From: Akim Demaille
Subject: Accepting GCJ's grammar
Date: 10 Jun 2002 18:10:42 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

GCJ does a weird thing:

| /* Source code parsing and tree node generation for the GNU compiler
|    for the Java(TM) language.
| [.........]
| Some rules have been modified to support JDK1.1 inner classes
| definitions and other extensions.  */
| 
| %{
| #include "config.h"
| [.............]
| %}
| 
| %union {
|   tree node;
|   int sub_token;
|   struct {
|     int token;
|     int location;
|   } operator;
|   int value;
| }
| 
| %{
| #include "lex.c"                     <===============================
| %}
| 
| %pure_parser
| 
| /* Things defined here have to match the order of what's in the
|    binop_lookup table.  */
| 
| %token   PLUS_TK         MINUS_TK        MULT_TK         DIV_TK    REM_TK
| %token   LS_TK           SRS_TK          ZRS_TK
| %token   AND_TK          XOR_TK          OR_TK
| %token   BOOL_AND_TK BOOL_OR_TK
| %token   EQ_TK NEQ_TK GT_TK GTE_TK LT_TK LTE_TK

With the funny thing that lex.c uses PLUS_TK etc.

So CVS Bison produces invalid code, since the tokens are defined
*after* the user prologue.

Well, technically, CVS Bison has two prologues: the first one is the
concatenation of all the %{..%} before %union, and the second
corresponds to %{ %}s after %union (this is due to Gettext which
has typedef before %union, which are used in the %union...).

Currently we output tokens like this:

| /* Tokens.  */
| #ifndef YYTOKENTYPE
| # if defined (__STDC__) || defined (__cplusplus)
|    /* Put the tokens into the symbol table, so that GDB and other debuggers
|       know about them.  */
|    enum yytokentype {
|      MY_TOKEN = 258
|    };
| # endif
|   /* POSIX requires `int' for tokens in interfaces.  */
| # define YYTOKENTYPE int
| #endif /* !YYTOKENTYPE */
| #define MY_TOKEN 258

I.e., we do try to provide the user with a means to disable
YYTOKENTYPE via the #ifndef (well, that's my reading, but maybe that's
not what you meant Paul.  Maybe it's merely to cope with include
"parser.h" in parser.c).

Which means we cannot output the tokens in the pre-prologue.  So, to
have GCJ compile properly, I propose the following patch, which output
the token defs in the post-prologue.  I don't apply it, because as is,
it does not allow one to write:

       %{
       void yyerror (const char *s);
       int yylex (void);
       #ifndef MY_TOKEN
       # error "MY_TOKEN not defined."
       #endif
       %}
       %token MY_TOKEN
       %%
       exp: MY_TOKEN;
       %%
       
and maybe you'll think that's better.  I personally don't like this
style, but, hey, if some people use Bison for this, maybe we have to
support that kind of stuff.

So, to summarize: my current idea is what expresses this patch, which
invalidates the snippet right above.  If your plan does not provide
the user with the right to touch YYTOKENTYPE, then we can simply
output token defs very early and ignore all this issue.


Attachment: diffs.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]