COPASI API  4.16.103
CEvaluationLexer.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_CEvaluationLexer
16 #define COPASI_CEvaluationLexer
17 
18 #include <vector>
19 
20 #undef yyFlexLexer
21 #include "FlexLexer.h"
22 
23 #define yyFlexLexer CEvaluationLexer
24 
25 #undef yyYaccParser
26 #define yyYaccParser CEvaluationParserBase
27 
28 #undef YYDEBUG
29 #ifdef COPASI_DEBUG
30 # define YYDEBUG 0 // Set his different from zero to trace the parser
31 #else
32 # define YYDEBUG 0
33 #endif // COPASI_DEBUG
34 
35 /**
36  * This is a base class for the CEvaluationLexer adding member
37  * attributes to enhance the internal functionality.
38  */
40 {
41 public:
42  /**
43  * Default constructor
44  */
46  mpNode(NULL),
47  mpRootNode(NULL),
48  mBoolean(false),
49  mpNodeList(NULL),
50  mPosition(0)
51  {}
52 
53  /**
54  * Destructor
55  */
56  virtual ~yyYaccParser() {}
57 
58  /**
59  * Retrieve the generated list of nodes.
60  * The user owns the list and is repsonsible for the destruction.
61  * To delete the list please use freeNodeList.
62  * Please note that each call to yylex() creates a new list which
63  * must be destoyed.
64  * @return std::vector< CEvaluationNode * > * pNodeList
65  */
66  std::vector< CEvaluationNode * > *getNodeList()
67  {return mpNodeList;}
68 
69  /**
70  * Convenient function to free the list of generated nodes.
71  * @param std::vector< CEvaluationNode * > * pNodeList
72  */
73  static void freeNodeList(std::vector< CEvaluationNode * > * pNodeList)
74  {
75  if (pNodeList == NULL) return;
76 
77  std::vector< CEvaluationNode * >::iterator it;
78  std::vector< CEvaluationNode * >::iterator end = pNodeList->end();
79 
80  for (it = pNodeList->begin(); it != end; ++it)
81  if (*it && (*it)->getParent())
82  (*it)->getParent()->removeChild(*it);
83 
84  for (it = pNodeList->begin(); it != end; ++it)
85  pdelete(*it);
86 
87  pdelete(pNodeList);
88  }
89 
90  virtual int yylex() = 0;
91 
92  virtual int yyparse();
93 
94  CEvaluationNode * getRootNode() {return mpRootNode;}
95 
96  bool isBoolean() const {return mBoolean;}
97 
98  size_t getErrorPosition() {return mPosition;}
99 
100 protected:
103  bool mBoolean;
104  std::vector< CEvaluationNode * > * mpNodeList;
105  size_t mPosition;
106 
107 private:
109  {
110  std::vector< CEvaluationNode * >::iterator it
111  = mpNodeList->begin();
112  std::vector< CEvaluationNode * >::iterator end
113  = mpNodeList->end();
114  size_t oldPosition = mPosition;
115  mPosition = 0;
116 
117  for (; it != end && mPosition < oldPosition; ++it)
118  mPosition += (*it)->getData().length();
119 
120  if (mPosition > 0)
121  mPosition -= (*--it)->getData().length();
122  }
123 };
124 
126 {
127 public:
128  // arg_yyin and arg_yyout default to the cin and cout, but we
129  // only make that assignment when initializing in yylex().
130  yyFlexLexer(FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0);
131 
132  virtual ~yyFlexLexer();
133 
134  void yy_switch_to_buffer(struct yy_buffer_state* new_buffer);
135  struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, int size);
136  void yy_delete_buffer(struct yy_buffer_state* b);
137  void yyrestart(FLEX_STD istream* s);
138 
139  void yypush_buffer_state(struct yy_buffer_state* new_buffer);
140  void yypop_buffer_state(void);
141 
142  virtual int yylex();
143  virtual void switch_streams(FLEX_STD istream* new_in, FLEX_STD ostream* new_out);
144  virtual int yywrap() {return 1;}
145 
146 protected:
147  virtual size_t LexerInput(char* buf, size_t max_size);
148  virtual void LexerOutput(const char* buf, size_t size);
149  virtual void LexerError(const char* msg);
150 
151  void yyunput(int c, char* buf_ptr);
152  int yyinput();
153 
154  void yy_load_buffer_state();
155 
156  void yy_init_buffer(struct yy_buffer_state* b, std::istream* s);
157 
158  void yy_flush_buffer(struct yy_buffer_state* b);
159 
163 
164  void yy_push_state(int new_state);
165  void yy_pop_state();
166  int yy_top_state();
167 
170  int yy_get_next_buffer();
171 
172  std::istream* yyin; // input source for default LexerInput
173  std::ostream* yyout; // output sink for default LexerOutput
174 
176 
177  // yy_hold_char holds the character lost when yytext is formed.
179 
180  // Number of characters read into yy_ch_buf.
182 
183  // Points to current character in buffer.
184  char* yy_c_buf_p;
185 
186  int yy_init; // whether we need to initialize
187  int yy_start; // start state number
188 
189  // Flag which is used to allow yywrap()'s to do buffer switches
190  // instead of setting up a fresh yyin. A bit of a hack ...
192 
193  size_t yy_buffer_stack_top; /**< index of top of stack. */
194  size_t yy_buffer_stack_max; /**< capacity of stack. */
195  struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
196  void yyensure_buffer_stack(void);
197 
198  // The following are not always needed, but may be depending
199  // on use of certain flex features (like REJECT or yymore()).
200 
203 
206 
210 
211  int yy_lp;
213 
218 };
219 
220 #endif // COPASI_CEvaluationLexer
#define pdelete(p)
Definition: copasi.h:215
virtual void LexerError(const char *msg)
void yy_init_buffer(struct yy_buffer_state *b, std::istream *s)
#define yyFlexLexer
CEvaluationNode * mpRootNode
virtual void switch_streams(FLEX_STD istream *new_in, FLEX_STD ostream *new_out)
void yy_switch_to_buffer(struct yy_buffer_state *new_buffer)
#define yyparse
CEvaluationNode * mpNode
virtual void LexerOutput(const char *buf, size_t size)
#define yyYaccParser
virtual int yywrap()
yy_state_type * yy_state_buf
void yy_flush_buffer(struct yy_buffer_state *b)
int yy_state_type
Definition: FlexLexer.h:72
void yypush_buffer_state(struct yy_buffer_state *new_buffer)
struct yy_buffer_state * yy_current_buffer
virtual size_t LexerInput(char *buf, size_t max_size)
void yyrestart(FLEX_STD istream *s)
yy_state_type yy_get_previous_state()
CEvaluationNode * getRootNode()
yy_state_type * yy_state_ptr
struct yy_buffer_state * yy_create_buffer(FLEX_STD istream *s, int size)
void yy_delete_buffer(struct yy_buffer_state *b)
std::ostream * yyout
std::vector< CEvaluationNode * > * mpNodeList
std::istream * yyin
struct yy_buffer_state ** yy_buffer_stack
static void freeNodeList(std::vector< CEvaluationNode * > *pNodeList)
CEvaluationNode * mpNode
void yy_push_state(int new_state)
yy_state_type yy_last_accepting_state
#define FLEX_STD
Definition: FlexLexer.h:66
yy_state_type yy_try_NUL_trans(yy_state_type current_state)
std::vector< CEvaluationNode * > * getNodeList()
void yyunput(int c, char *buf_ptr)