torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LutParser.hpp
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.3. */
2 
3 /* Skeleton interface for Bison LALR(1) parsers in C++
4 
5  Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2, or (at your option)
10  any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA. */
21 
22 /* As a special exception, you may create a larger work that contains
23  part or all of the Bison parser skeleton and distribute that work
24  under terms of your choice, so long as that work isn't itself a
25  parser generator using the skeleton or a modified version thereof
26  as a parser skeleton. Alternatively, if you modify or redistribute
27  the parser skeleton itself, you may (at your option) remove this
28  special exception, which will cause the skeleton and the resulting
29  Bison output files to be licensed under the GNU General Public
30  License without this special exception.
31 
32  This special exception was added by the Free Software Foundation in
33  version 2.2 of Bison. */
34 
35 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
36 
37 #ifndef PARSER_HEADER_H
38 # define PARSER_HEADER_H
39 
40 #include <string>
41 #include <iostream>
42 #include "stack.hh"
43 
44 namespace torc
45 {
46  class position;
47  class location;
48 }
49 
50 /* First part of user declarations. */
51 #line 16 "parser.yy"
52 
53 
54 
55 // ------------------------------------------------------------------------------------------------
56 // -------------------------------------- C/C++ declarations --------------------------------------
57 // ------------------------------------------------------------------------------------------------
58 
59 
60 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
61 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/bitstream/assembler/lut/parser.yy $
62 // $Id: parser.yy 1304 2013-02-26 01:16:38Z nsteiner $
63 
64 // This program is free software: you can redistribute it and/or modify it under the terms of the
65 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
66 // License, or (at your option) any later version.
67 //
68 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
69 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
70 // the GNU General Public License for more details.
71 //
72 // You should have received a copy of the GNU General Public License along with this program. If
73 // not, see <http://www.gnu.org/licenses/>.
74 
76 #include <cstdio>
77 #include <iostream>
78 
79 //#define YYPRINT(file, type, value) fprintf(file, "token [%d] \"%s\"", type, value);
80 
81 using std::string;
82 using namespace torc::bitstream;
83 
84 #define YYSTYPE std::string
85 
86 
87 #line 122 "parser.yy"
88 
89 
90 /// \brief Code to connect the bison parser in the importer to the flex scanner object.
91 /// \details This defines the yylex() function call to pull the next token from the current lexer
92 /// object in the importer.
93 #undef yylex
94 #define yylex lut.lexer->lex
95 
96 
97 
98 /* Line 303 of lalr1.cc. */
99 #line 100 "LutParser.hpp"
100 
101 #include "location.hh"
102 
103 /* Enabling traces. */
104 #ifndef YYDEBUG
105 # define YYDEBUG 0
106 #endif
107 
108 /* Enabling verbose error messages. */
109 #ifdef YYERROR_VERBOSE
110 # undef YYERROR_VERBOSE
111 # define YYERROR_VERBOSE 1
112 #else
113 # define YYERROR_VERBOSE 1
114 #endif
115 
116 /* Enabling the token table. */
117 #ifndef YYTOKEN_TABLE
118 # define YYTOKEN_TABLE 0
119 #endif
120 
121 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
122  If N is 0, then set CURRENT to the empty location which ends
123  the previous symbol: RHS[0] (always defined). */
124 
125 #ifndef YYLLOC_DEFAULT
126 # define YYLLOC_DEFAULT(Current, Rhs, N) \
127 do { \
128  if (N) \
129  { \
130  (Current).begin = (Rhs)[1].begin; \
131  (Current).end = (Rhs)[N].end; \
132  } \
133  else \
134  { \
135  (Current).begin = (Current).end = (Rhs)[0].end; \
136  } \
137 } while (false)
138 #endif
139 
140 namespace torc
141 {
142 
143  /// A Bison parser.
144  class LutParser
145  {
146  public:
147  /// Symbol semantic values.
148 #ifndef YYSTYPE
149  typedef int semantic_type;
150 #else
152 #endif
153  /// Symbol locations.
155  /// Tokens.
156  struct token
157  {
158  /* Tokens. */
159  enum yytokentype {
160  END = 0,
161  EOL = 258,
162  VAR = 259,
163  LITERAL = 260,
164  AND = 261,
165  OR = 262,
166  NOT = 263,
167  XOR = 264,
168  RP = 265,
169  LP = 266,
170  INVALID = 267
171  };
172 
173  };
174  /// Token type.
176 
177  /// Build a parser object.
178  LutParser (class Assembler& lut_yyarg);
179  virtual ~LutParser ();
180 
181  /// Parse.
182  /// \returns 0 iff parsing succeeded.
183  virtual int parse ();
184 
185  /// The current debugging stream.
186  std::ostream& debug_stream () const;
187  /// Set the current debugging stream.
188  void set_debug_stream (std::ostream &);
189 
190  /// Type for debugging levels.
191  typedef int debug_level_type;
192  /// The current debugging level.
193  debug_level_type debug_level () const;
194  /// Set the current debugging level.
195  void set_debug_level (debug_level_type l);
196 
197  private:
198  /// Report a syntax error.
199  /// \param loc where the syntax error is found.
200  /// \param msg a description of the syntax error.
201  virtual void error (const location_type& loc, const std::string& msg);
202 
203  /// Generate an error message.
204  /// \param state the state where the error occurred.
205  /// \param tok the look-ahead token.
206  virtual std::string yysyntax_error_ (int yystate, int tok);
207 
208 #if YYDEBUG
209  /// \brief Report a symbol value on the debug stream.
210  /// \param yytype The token type.
211  /// \param yyvaluep Its semantic value.
212  /// \param yylocationp Its location.
213  virtual void yy_symbol_value_print_ (int yytype,
214  const semantic_type* yyvaluep,
215  const location_type* yylocationp);
216  /// \brief Report a symbol on the debug stream.
217  /// \param yytype The token type.
218  /// \param yyvaluep Its semantic value.
219  /// \param yylocationp Its location.
220  virtual void yy_symbol_print_ (int yytype,
221  const semantic_type* yyvaluep,
222  const location_type* yylocationp);
223 #endif /* ! YYDEBUG */
224 
225 
226  /// State numbers.
227  typedef int state_type;
228  /// State stack type.
230  /// Semantic value stack type.
232  /// location stack type.
234 
235  /// The state stack.
237  /// The semantic value stack.
239  /// The location stack.
241 
242  /// Internal symbol numbers.
243  typedef unsigned char token_number_type;
244  /* Tables. */
245  /// For a state, the index in \a yytable_ of its portion.
246  static const signed char yypact_[];
247  static const signed char yypact_ninf_;
248 
249  /// For a state, default rule to reduce.
250  /// Unless\a yytable_ specifies something else to do.
251  /// Zero means the default is an error.
252  static const unsigned char yydefact_[];
253 
254  static const signed char yypgoto_[];
255  static const signed char yydefgoto_[];
256 
257  /// What to do in a state.
258  /// \a yytable_[yypact_[s]]: what to do in state \a s.
259  /// - if positive, shift that token.
260  /// - if negative, reduce the rule which number is the opposite.
261  /// - if zero, do what YYDEFACT says.
262  static const unsigned char yytable_[];
263  static const signed char yytable_ninf_;
264 
265  static const signed char yycheck_[];
266 
267  /// For a state, its accessing symbol.
268  static const unsigned char yystos_[];
269 
270  /// For a rule, its LHS.
271  static const unsigned char yyr1_[];
272  /// For a rule, its RHS length.
273  static const unsigned char yyr2_[];
274 
275 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
276  /// For a symbol, its name in clear.
277  static const char* const yytname_[];
278 #endif
279 
280 #if YYERROR_VERBOSE
281  /// Convert the symbol name \a n to a form suitable for a diagnostic.
282  virtual std::string yytnamerr_ (const char *n);
283 #endif
284 
285 #if YYDEBUG
286  /// A type to store symbol numbers and -1.
287  typedef signed char rhs_number_type;
288  /// A `-1'-separated list of the rules' RHS.
289  static const rhs_number_type yyrhs_[];
290  /// For each rule, the index of the first RHS symbol in \a yyrhs_.
291  static const unsigned char yyprhs_[];
292  /// For each rule, its source line number.
293  static const unsigned char yyrline_[];
294  /// For each scanner token number, its symbol number.
295  static const unsigned short int yytoken_number_[];
296  /// Report on the debug stream that the rule \a r is going to be reduced.
297  virtual void yy_reduce_print_ (int r);
298  /// Print the state stack on the debug stream.
299  virtual void yystack_print_ ();
300 #endif
301 
302  /// Convert a scanner token number \a t to a symbol number.
303  token_number_type yytranslate_ (int t);
304 
305  /// \brief Reclaim the memory associated to a symbol.
306  /// \param yymsg Why this token is reclaimed.
307  /// \param yytype The symbol type.
308  /// \param yyvaluep Its semantic value.
309  /// \param yylocationp Its location.
310  inline void yydestruct_ (const char* yymsg,
311  int yytype,
312  semantic_type* yyvaluep,
313  location_type* yylocationp);
314 
315  /// Pop \a n symbols the three stacks.
316  inline void yypop_ (unsigned int n = 1);
317 
318  /* Constants. */
319  static const int yyeof_;
320  /* LAST_ -- Last index in TABLE_. */
321  static const int yylast_;
322  static const int yynnts_;
323  static const int yyempty_;
324  static const int yyfinal_;
325  static const int yyterror_;
326  static const int yyerrcode_;
327  static const int yyntokens_;
328  static const unsigned int yyuser_token_number_max_;
330 
331  /* Debugging. */
332  int yydebug_;
333  std::ostream* yycdebug_;
334 
335 
336  /* User arguments. */
337  class Assembler& lut;
338  };
339 }
340 
341 
342 #endif /* ! defined PARSER_HEADER_H */
stack< semantic_type > semantic_stack_type
Semantic value stack type.
Definition: LutParser.hpp:231
token::yytokentype token_type
Token type.
Definition: LutParser.hpp:175
YYSTYPE semantic_type
Symbol semantic values.
Definition: LutParser.hpp:151
static const int yyntokens_
Definition: LutParser.hpp:327
location_stack_type yylocation_stack_
The location stack.
Definition: LutParser.hpp:240
semantic_stack_type yysemantic_stack_
The semantic value stack.
Definition: LutParser.hpp:238
A Bison parser.
Definition: LutParser.hpp:144
int debug_level_type
Type for debugging levels.
Definition: LutParser.hpp:191
int state_type
State numbers.
Definition: LutParser.hpp:227
static const int yyeof_
Definition: LutParser.hpp:319
Base class for Xdl to bitstream conversion. This class is abstract but still contains lot of architec...
std::string string
static const unsigned int yyuser_token_number_max_
Definition: LutParser.hpp:328
static const signed char yytable_ninf_
Definition: LutParser.hpp:263
static const int yyerrcode_
Definition: LutParser.hpp:326
static const signed char yypact_ninf_
Definition: LutParser.hpp:247
class Assembler & lut
Definition: LutParser.hpp:337
stack< location_type > location_stack_type
location stack type.
Definition: LutParser.hpp:233
std::ostream * yycdebug_
Definition: LutParser.hpp:333
static const int yyempty_
Definition: LutParser.hpp:323
static const token_number_type yyundef_token_
Definition: LutParser.hpp:329
static const int yyterror_
Definition: LutParser.hpp:325
location location_type
Symbol locations.
Definition: LutParser.hpp:154
stack< state_type > state_stack_type
State stack type.
Definition: LutParser.hpp:229
static const int yynnts_
Definition: LutParser.hpp:322
static const int yyfinal_
Definition: LutParser.hpp:324
unsigned char token_number_type
Internal symbol numbers.
Definition: LutParser.hpp:243
state_stack_type yystate_stack_
The state stack.
Definition: LutParser.hpp:236
static const int yylast_
Definition: LutParser.hpp:321
Base class for bitstream assembly.
Definition: Assembler.hpp:46
#define YYSTYPE
Definition: LutParser.hpp:84