/* Parser to convert "C" assignments to lisp using Bison in C++. */
/* Demonstrates bison pure parsers */
/* Compile: bison -d flexexample4.yxx */

%{
#include <iostream>
#include "lex.yy.h"  /* Generated by reflex: scanner_t, yyscan_t, yylex_init, yylex_destroy */
void yyerror(yyscan_t, const char*);
/* Pass the parameter 'scanner' to yyparse through to yylex. */
#define YYPARSE_PARAM scanner
#define YYLEX_PARAM   scanner
%}

%pure-parser
%lex-param { void *scanner }
%parse-param { void *scanner }

%union {
    int   num;
    char *str;
}

%token <str> STRING
%token <num> NUMBER

%%

assignments : assignment
            | assignment assignments
            ;
assignment  : STRING '=' NUMBER ';' { std::cout << "(setf " << $1 << " " << $3 << ")\n"; }
            ;

%%

int main()
{
  yyscanner_t scanner;	// new way in C++ using reflex-generated yyscanner_t
  yyparse(&scanner);	// scanner is passed on to yylex()
  return 0;
}

void yyerror(yyscan_t scanner, const char *msg)
{
  (void)scanner; /* appease -Wall -Werror */
  std::cerr << msg << std::endl; /* how to use yylineno with bison-bridge? See flexexample5.yxx */
}
