lispLike.yy
77 lines
| 1.7 KiB
| text/plain
|
TextLexer
r0 | %skeleton "lalr1.cc" | |||
//%require "3.0" | ||||
r6 | //%debug | |||
r0 | %defines | |||
r7 | %define api.namespace {QIlib} | |||
%define parser_class_name {lispLike_Parser} | ||||
r0 | ||||
%code requires{ | ||||
#include <QString> | ||||
namespace QIlib { | ||||
class lispLike_Driver; | ||||
class lispLike_Scanner; | ||||
} | ||||
} | ||||
%lex-param { QIlib::lispLike_Scanner &scanner } | ||||
%parse-param { QIlib::lispLike_Scanner &scanner } | ||||
%lex-param { QIlib::lispLike_Driver &driver } | ||||
%parse-param { QIlib::lispLike_Driver &driver } | ||||
%code{ | ||||
#include <iostream> | ||||
#include <cstdlib> | ||||
#include <fstream> | ||||
/* include for all driver functions */ | ||||
#include <lispLike_driver.h> | ||||
/* this is silly, but I can't figure out a way around */ | ||||
static int yylex(QIlib::lispLike_Parser::semantic_type *yylval, | ||||
QIlib::lispLike_Scanner &scanner, | ||||
QIlib::lispLike_Driver &driver); | ||||
} | ||||
/* token types */ | ||||
%union { | ||||
QString* sval; | ||||
} | ||||
//%token END 0 "end of file" | ||||
%token <sval> VALUE | ||||
%token <sval> NODE | ||||
%token CLOSENODE | ||||
/* destructor rule for <sval> objects */ | ||||
%destructor { if ($$) { delete ($$); ($$) = NULL; } } <sval> | ||||
%% | ||||
PartNode | ||||
: NODE { driver.add_node( *$1 ); } | ||||
| PartNode NODE { driver.add_node( *$2 ); } | ||||
| PartNode VALUE { driver.add_value( *$2 ); } | ||||
| PartNode CLOSENODE { driver.close_node(); } | ||||
%% | ||||
r6 | void QIlib::lispLike_Parser::error(const std::string& error) | |||
r0 | { | |||
r6 | std::cerr << "Error: " << error << "\n"; | |||
r0 | } | |||
/* include for access to scanner.yylex */ | ||||
#include "lispLike_scanner.h" | ||||
static int yylex( QIlib::lispLike_Parser::semantic_type *yylval, | ||||
QIlib::lispLike_Scanner &scanner, | ||||
QIlib::lispLike_Driver &driver ) | ||||
{ | ||||
return( scanner.yylex(yylval) ); | ||||
} | ||||