%{
#include "Cycript.tab.hh"
typedef cy::parser::token tk;
+#define YY_EXTRA_TYPE CYParser *
%}
%option prefix="cy"
%option yylineno
%option nounput
%option interactive
+%option reentrant
delim [ \t]
whitesp {delim}+
"(" return tk::OpenParen;
")" return tk::CloseParen;
+
"{" return tk::OpenBrace;
"}" return tk::CloseBrace;
+
"[" return tk::OpenBracket;
"]" return tk::CloseBracket;
[0-9]+ return tk::NumericLiteral;
[ \t\n] ;
+
+%%
+
+void CYParser::ScannerInit() {
+ cylex_init(&scanner_);
+ cyset_extra(this, scanner_);
+}
+
+void CYParser::ScannerDestroy() {
+ cylex_destroy(scanner_);
+}
%code top {
#include "Cycript.tab.hh"
-int cylex(YYSTYPE *lvalp, YYLTYPE *llocp);
+int cylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
+#define scanner driver->scanner_
}
%code requires {
%debug
%error-verbose
-%parse-param { CYParser *context }
+%parse-param { CYParser *driver }
+%lex-param { void *scanner }
%token Ampersand "&"
%token AmpersandAmpersand "&&"
%token OpenParen "("
%token CloseParen ")"
+
%token OpenBrace "{"
%token CloseBrace "}"
+
%token OpenBracket "["
%token CloseBracket "]"
{NULL, NULL, NULL, 0}
};
+CYParser::CYParser() {
+ ScannerInit();
+}
+
+CYParser::~CYParser() {
+ ScannerDestroy();
+}
+
extern int cydebug;
void cy::parser::error(const cy::parser::location_type &loc, const std::string &msg) {
void CYConsole(FILE *fin, FILE *fout, FILE *ferr) {
cydebug = 1;
- CYParser context;
- cy::parser parser(&context);
+ CYParser driver;
+ cy::parser parser(&driver);
parser.parse();
}
#define CYPARSER_HPP
class CYParser {
+ public:
+ void *scanner_;
+
+ private:
+ void ScannerInit();
+ void ScannerDestroy();
+
+ public:
+ CYParser();
+ ~CYParser();
};
struct CYExpression {