/* Parser to convert "C" assignments to lisp using Bison in C. */
/* Compile: bison -d flexexample8.yxx */

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

%locations
%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(YYLTYPE *yylloc, yyscan_t scanner, const char *msg)
{
  (void)scanner; // appease -Wall -Werror
  std::cerr << msg << " at " << yylloc->first_line << "," << yylloc->first_column << std::endl;
}
