-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathflexexample8.yxx
47 lines (38 loc) · 1.07 KB
/
flexexample8.yxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* 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;
}