45 lines
No EOL
750 B
Text
45 lines
No EOL
750 B
Text
%skeleton "lalr1.cc"
|
|
%require "3.0"
|
|
%defines
|
|
%define api.value.type variant
|
|
%define api.parser.class { parser }
|
|
%define api.namespace { yy }
|
|
%define api.token.prefix {TOK_}
|
|
|
|
%code requires {
|
|
#include <string>
|
|
}
|
|
|
|
%code {
|
|
#include <iostream>
|
|
|
|
int scanner_lex(yy::parser::semantic_type* yylval);
|
|
|
|
#undef yylex
|
|
#define yylex scanner_lex
|
|
}
|
|
|
|
%token <std::string> WORD
|
|
%token NUMBER
|
|
%token CHAR
|
|
|
|
%%
|
|
input:
|
|
/* empty */
|
|
| input element
|
|
;
|
|
|
|
element:
|
|
WORD { std::cout << "WORD: " << $1 << "\n"; }
|
|
| NUMBER { std::cout << "NUMBER\n"; }
|
|
| CHAR { std::cout << "CHAR\n"; }
|
|
;
|
|
|
|
%%
|
|
|
|
namespace yy {
|
|
void parser::error(const std::string& msg)
|
|
{
|
|
std::cerr << "Error: " << msg << "\n";
|
|
}
|
|
} |