-
Notifications
You must be signed in to change notification settings - Fork 48
/
mc_parser.yy
82 lines (65 loc) · 1.48 KB
/
mc_parser.yy
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%skeleton "lalr1.cc"
%require "3.0"
%debug
%defines
%define api.namespace {MC}
/**
* bison 3.3.2 change
* %define parser_class_name to this, updated
* should work for previous bison versions as
* well. -jcb 24 Jan 2020
*/
%define api.parser.class {MC_Parser}
%code requires{
namespace MC {
class MC_Driver;
class MC_Scanner;
}
// The following definitions is missing when %locations isn't used
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# endif
}
%parse-param { MC_Scanner &scanner }
%parse-param { MC_Driver &driver }
%code{
#include <iostream>
#include <cstdlib>
#include <fstream>
/* include for all driver functions */
#include "mc_driver.hpp"
#undef yylex
#define yylex scanner.yylex
}
%define api.value.type variant
%define parse.assert
%token END 0 "end of file"
%token UPPER
%token LOWER
%token <std::string> WORD
%token NEWLINE
%token CHAR
%locations
%%
list_option : END | list END;
list
: item
| list item
;
item
: UPPER { driver.add_upper(); }
| LOWER { driver.add_lower(); }
| WORD { driver.add_word( $1 ); }
| NEWLINE { driver.add_newline(); }
| CHAR { driver.add_char(); }
;
%%
void
MC::MC_Parser::error( const location_type &l, const std::string &err_message )
{
std::cerr << "Error: " << err_message << " at " << l << "\n";
}