%glr-parser %language "c++" %require "3.2" %skeleton "glr2.cc" %locations %header %define api.namespace { gen } %define api.parser.class { Parser } %define parse.error verbose %verbose %define parse.trace %define api.location.type { class gen::location } %code requires { #define NOMINMAX // glr2.cc collision with max() #pragma warning(push) #pragma warning(disable : 4065) // switch statement contains 'default' but no 'case' labels #include #include struct parse_param_t { // The first portion must be the same or larger than the largest used in the 'union' gen::index_t index; // Largest type used // The rest of this struct holds the semantic info passed into yylex // These values can be accessed in any %merge routine // We need this until bison let's us have merge routines as members of the parser class. // Otherwise we are forced to use static variables in order to pass context // information to the merge routines. void * pval; class gen::location * ploc; class GenParser * pResult; // NOTE: This is stored at an offset greater than the max used in the 'union' of all others }; } %code top { #include #include "driver.h" #define R (*pDriver->getResult()) #define D (*pDriver) #define P (*D.getParser()) #define S (*D.getScanner()) } %code { int yylex(union gen::Parser::value_type *plval, gen::location *plloc, Driver * pDriver) { plval->parse_param.pval = plval; plval->parse_param.ploc = plloc; plval->parse_param.pResult = pDriver->getResult(); return pDriver->getScanner()->get_next_token(*plval, *plloc, pDriver); } } %param { Driver * pDriver } %union { gen::index_t index; parse_param_t parse_param; } %token IDENTIFIER CONSTANT %token COMPLEX FLOAT %type program %type statements statement %type expr %type ident decl storage decl_single storage_type %type decl_single_vec decl_target pointer_to %start program %% program: decl ; statements: statement | statements ';' statement ; statement: decl | expr ; decl: storage | storage decl_single '(' ')' '{' statements '}' ; storage: storage_type | storage_type '(' expr ')' // If this line commented out, 1 S/R, 2 R/R, app doesn't crash ; storage_type: FLOAT | COMPLEX | ident ; decl_single: decl_single_vec | decl_target | decl_target decl_single_vec | pointer_to | pointer_to decl_single_vec | pointer_to decl_target | pointer_to decl_target decl_single_vec ; decl_single_vec: '[' ']' ; pointer_to: '*' | pointer_to '*' ; decl_target: '(' decl_single ')' | ident ; expr: expr_factor | '*' expr_factor // If this line commented out, 2 S/R, 2 R/R, app doesn't crash ; expr_factor: '(' expr ')' | ident ; ident: IDENTIFIER ; %% /* Epilogue */ #pragma warning(pop) void gen::Parser::error(const location& loc , const std::string& message) { R.error(loc, message.c_str()); }