bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: enum instead of #define for tokens


From: Akim Demaille
Subject: Re: enum instead of #define for tokens
Date: 03 Apr 2002 16:02:49 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

| In all cases, files with definitions should have something like:
| 
| #ifndef __BISON_PREFIX_H__
| 
| #define ...
| 
|    or
| 
| typedef enum _bison_prefix_enum { ERROR = ...} PREFIX_TOKEN;
| 
| #endif
| 
| wrapping the code. Where PREFIX is the "name" of the grammar from
| the bison command line switch.

This what we have in mind.

Currently, there is a class Parser, in the namespace yy.  Then we
intend to have an enum yytokentype in it.  But then, the problem is
that you have to write

"if"   return yy::Parser::IF;
"else" return yy::Parser::ELSE;

etc.

unless you import the whole class:

using yy::Parser;

"if"   return IF;
"else" return ELSE;

We would have liked to be able to import only the enum, unfortunately,
there is no such thing as

using yy::Parser::yytokentype;

So we have in mind something else: in addition to Parser, there is a
namespace TokenType, containing either an enum or a list of const
int.  The class Parser forwards this enum declaration, and therefore
the user can choose between:

"if"   return yy::TokenTypes::IF;
"else" return yy::TokenTypes::ELSE;

and

"if"   return yy::Parser::IF;
"else" return yy::Parser::ELSE;

and

using yy::TokenTypes;

"if"   return IF;
"else" return ELSE;



But actually, it doesn't seem _too_ much wrong to import the whole
class, so maybe we are too demanding.

Thoughts?



reply via email to

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