[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: beta testing
From: |
Philippe Bekaert |
Subject: |
Re: beta testing |
Date: |
Tue, 20 Feb 2001 16:40:53 +0100 |
> -- But one still has to give thought how to make those macro names that the
> parser uses local.
>
> -- Another problem is how to deliver the parsed value in a pure (local)
> fashion. Currently one has to write something like
>
> %{
>
> my_type global_value; // Global variable
>
> %}
>
> %%
>
> sentence: foo { global_value = $1; /* Deliver the global value */ }
>
> This is not good if one wants to write thread-safe parsers. -- Somehow, one
> must be able to ensure that every invokation of the parser only uses its
> own local values.
I made all these global variables members of my parser class.
This is what I now got:
class Parser: public Scanner (besides some other classes) {
protected:
(lot's of my_type global_value 's ....)
void yyerror(char *s);// parser error reporting routine
int yyparse(void); // bison generated parser
YYSTYPE yylval; // bison generated "global" variables
int yychar;
int yynerrs;
inline int yylex(YYSTYPE *lvalp)
{
int token = vrml2_utf8_scanner::yylex(lvalp);
vrml::current_linenr = yylineno; // keep track of line number
return token;
}
// by default, yylex fills in yylval "global" variable.
inline int yylex(void)
{
return yylex(&yylval);
}
public:
bool parse(char* filename); // opens the file, initialises the
scanner to read from the file and calls yyparse()
};
#include "y.tab.h"
class Scanner: pulic FlexLexer { // declared in a header file included
before parser
protected:
YYSTYPE *lastvalp;
int LexerInput(char *buf, int max_size);
public:
void init(char* filename); // opens the file and lets lex read from it
int yylex(YYSTYPE *lvalp);
virtual void yyerror(char *s); // overriden in the parser class, so
same routine is used.
...
};
The parser.bison script:
%{
#include "parser.H"
#define yyparse Parser::yyparse
#define yylex Parser::yylex
#define yyerror Parser::yyerror
#define yylval Parser::yylval
#define yychar Parser::yychar
#define yydebug Parser::yydebug
#define yynerrs Parser::yynerrs
// the following are used in my modified bison.simple file:
#define YYSTYPE DUPLICATE_YYSTYPE
#define YY_OMIT_DECLS
%}
%union { /* stack type */
...
}
...
Best regards,
Philippe.
--
Philippe Bekaert
Post-doctoral Research Fellow
Max-Planck-Institut fuer Informatik
Im Stadtwald, Geb. 46.1
66123 Saarbruecken - Germany
+49 681 9325422 (office phone)
+49 681 9325499 (office fax)
+49 179 4503121 (private phone)
Re: beta testing, Hans Aberg, 2001/02/20