annotate parser.yy @ 12:894be158b32d

define parser as a class and eliminate some global variables
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 17:57:20 -0400
parents b652a5528fb1
children d179b0bb85e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 // Infix notation calculator.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 %{
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 #define YYSTYPE double
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 #include <iostream>
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
8 #include <string>
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 #include <cctype>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 #include <cmath>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 #include <cstdio>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
14 #include "interpreter.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
15 #include "parser.h"
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
17 namespace calc
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 {
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
19 static void *create_parser_state (void);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
20 static void delete_parser_state (void *);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
21
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
22 parser::parser (interpreter& interp)
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
23 : m_interpreter (interp),
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
24 m_parser_state (create_parser_state ()),
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
25 m_beg_of_stmt (true)
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
26 { }
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
27
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
28 parser::~parser (void)
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
29 {
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
30 delete_parser_state (m_parser_state);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
31 }
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
32
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
33 void parser::emit_error (const char *msg) const
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
34 {
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
35 m_interpreter.emit_error (msg);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
36 }
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
37
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
38 void parser::emit_result (double value) const
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
39 {
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
40 m_interpreter.emit_result (value);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
41 }
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
42
11
b652a5528fb1 handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents: 9
diff changeset
43 // For communication between the lexer and parser.
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 size_t bufptr = 0;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 size_t chunk_size = 0;
11
b652a5528fb1 handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents: 9
diff changeset
46 const char *buf;
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
48 static int yylex (YYSTYPE& token_value);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
51 static void yyerror (calc::parser&, char const *);
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
52
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 %}
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
55 %define api.pure full
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 %define api.push-pull push
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
58 %parse-param {calc::parser& parser}
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
59
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 // Bison declarations.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 %token NUM
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 %left '-' '+'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 %left '*' '/'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 %left NEG // negation--unary minus
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 %right '^' // exponentiation
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 %%
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 input : // empty
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 { }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 | input line
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
72 | error
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
73 {
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
74 YYABORT;
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
75 }
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 ;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 line : ';'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 { }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 | exp ';'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 {
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
82 parser.emit_result ($1);
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
83 parser.beg_of_stmt (true);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
85 ;
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 exp : NUM
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 $$ = $1;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
90 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 | exp '+' exp
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 $$ = $1 + $3;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
95 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 | exp '-' exp
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 $$ = $1 - $3;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
100 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 | exp '*' exp
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 $$ = $1 * $3;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
105 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 | exp '/' exp
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 $$ = $1 / $3;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
110 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 | '-' exp %prec NEG
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 $$ = -$2;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
115 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 | exp '^' exp
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 $$ = std::pow ($1, $3);
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
120 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 | '(' exp ')'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 $$ = $2;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
125 parser.beg_of_stmt (false);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 ;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 %%
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
131 namespace calc
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 // The lexical analyzer returns a double floating point number on the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 // stack and the token NUM, or the numeric code of the character read
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 // if not a number. It skips all blanks and tabs, and returns -1 for
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 // end-of-input.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
138 static int yylex (YYSTYPE& token_value)
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 int c;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 if (bufptr >= chunk_size)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 return -1;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 // Skip white space.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 while ((c = buf[bufptr++]) == ' ' || c == '\t' || c == '\n')
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 ;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 // Process numbers.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 if (c == '.' || isdigit (c))
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 int chars_read = 0;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 bufptr--;
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
154 sscanf (&buf[bufptr], "%lf%n", &token_value, &chars_read);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 bufptr += chars_read;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 return NUM;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 // Return a single char.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 return c;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
163 int parser::parse_and_execute (const std::string& line)
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 bufptr = 0;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 chunk_size = line.length ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 buf = line.c_str ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 int status;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 do
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 {
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
173 YYSTYPE token_value;
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
174 int input_char = yylex (token_value);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
176 if (input_char < 0)
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 return -1;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
179 status = yypush_parse (static_cast<yypstate *> (m_parser_state),
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
180 input_char, &token_value, *this);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 while (status == YYPUSH_MORE);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
184 return -2;
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
187 static void *create_parser_state (void)
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
188 {
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
189 return yypstate_new ();
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
190 }
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
191
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
192 static void delete_parser_state (void *parser_state)
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
193 {
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
194 return yypstate_delete (static_cast<yypstate *> (parser_state));
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
195 }
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 }
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
197
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
198 static void yyerror (calc::parser& parser, char const *msg)
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
199 {
12
894be158b32d define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 11
diff changeset
200 parser.emit_error (msg);
6
1b575145197e interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
201 }