MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
LowParser Class Reference

#include <parser.h>

Collaboration diagram for LowParser:

Public Types

enum  Token {
  UNKNOWN, WORD, COMMA = ',', COLON = ':',
  SEMICOLON = ';', NUMBER, ENDOFFILE, LASTTOKEN
}
 

Public Member Functions

 LowParser (HighParser &hp)
 
 ~LowParser (void)
 
Token GetToken (InputStream &In)
 
doublereal dGetReal (void) const
 
integer iGetInt (void) const
 
char * sGetWord (void)
 

Private Member Functions

void PackWords (InputStream &In)
 

Private Attributes

HighParserHP
 
enum Token CurrToken
 
char * sCurrWordBuf
 
unsigned iBufSize
 
doublereal dCurrNumber
 

Friends

class HighParser
 

Detailed Description

Definition at line 144 of file parser.h.

Member Enumeration Documentation

Enumerator
UNKNOWN 
WORD 
COMMA 
COLON 
SEMICOLON 
NUMBER 
ENDOFFILE 
LASTTOKEN 

Definition at line 148 of file parser.h.

148  {
149  UNKNOWN,
150 
151  WORD,
152  COMMA = ',',
153  COLON = ':',
154  SEMICOLON = ';',
155  NUMBER,
156  ENDOFFILE,
157 
158  LASTTOKEN
159  };

Constructor & Destructor Documentation

LowParser::LowParser ( HighParser hp)

Definition at line 132 of file parser.cc.

References iBufSize, SAFENEWARR, and sCurrWordBuf.

134 {
136 }
char * sCurrWordBuf
Definition: parser.h:164
HighParser & HP
Definition: parser.h:162
const unsigned int iDefaultBufSize
Definition: parser.h:133
unsigned iBufSize
Definition: parser.h:165
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
LowParser::~LowParser ( void  )

Definition at line 138 of file parser.cc.

References SAFEDELETEARR, and sCurrWordBuf.

139 {
140  if (sCurrWordBuf) {
142  }
143 }
char * sCurrWordBuf
Definition: parser.h:164
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713

Member Function Documentation

doublereal LowParser::dGetReal ( void  ) const

Definition at line 230 of file parser.cc.

References dCurrNumber.

231 {
232  return dCurrNumber;
233 }
doublereal dCurrNumber
Definition: parser.h:166
LowParser::Token LowParser::GetToken ( InputStream In)

Definition at line 189 of file parser.cc.

References COLON, COMMA, CurrToken, dCurrNumber, ENDOFFILE, HP, NUMBER, PackWords(), InputStream::putback(), SEMICOLON, skip_remarks(), UNKNOWN, and WORD.

Referenced by HighParser::FirstToken(), HighParser::GetDescription(), HighParser::GetWord(), and HighParser::NextToken().

190 {
191  /* toglie gli spazi iniziali e tutti i commenti */
192  char cIn;
193  if (skip_remarks(HP, In, cIn)) {
195  }
196 
197  if (isalpha(cIn) || cIn == '_') {
198  PackWords(In.putback(cIn));
199  return CurrToken = LowParser::WORD;
200  }
201 
202  switch (cIn) {
203  case ',':
204  return CurrToken = LowParser::COMMA;
205 
206  case ':':
207  return CurrToken = LowParser::COLON;
208 
209  case ';':
211 
212  case '.':
213  case '-':
214  case '+':
215 is_digit:;
216  In.putback(cIn) >> dCurrNumber;
217  return CurrToken = LowParser::NUMBER;
218 
219  default:
220  if (isdigit(cIn)) {
221  goto is_digit;
222  }
223  In.putback(cIn);
224  return CurrToken = LowParser::UNKNOWN;
225  }
226 }
enum Token CurrToken
Definition: parser.h:163
InputStream & putback(char ch)
Definition: input.h:121
HighParser & HP
Definition: parser.h:162
void PackWords(InputStream &In)
Definition: parser.cc:146
static int skip_remarks(HighParser &HP, InputStream &In, char &cIn)
Definition: parser.cc:49
doublereal dCurrNumber
Definition: parser.h:166

Here is the call graph for this function:

integer LowParser::iGetInt ( void  ) const

Definition at line 237 of file parser.cc.

References dCurrNumber.

238 {
239  return integer(dCurrNumber);
240 }
doublereal dCurrNumber
Definition: parser.h:166
long int integer
Definition: colamd.c:51
void LowParser::PackWords ( InputStream In)
private

Definition at line 146 of file parser.cc.

References COLON, COMMA, InputStream::eof(), InputStream::get(), iBufSize, MBDYN_EXCEPT_ARGS, InputStream::putback(), SAFEDELETEARR, SAFENEWARR, sCurrWordBuf, and SEMICOLON.

Referenced by GetToken().

147 {
148  unsigned iCur = 0;
149  char cIn;
150 
151  /* note: no remarks allowed inside words */
152  for (cIn = In.get(); !In.eof(); cIn = In.get()) {
153  switch (cIn) {
154  case COLON:
155  case COMMA:
156  case SEMICOLON:
157  goto end_of_word;
158 
159  default:
160  if (!isspace(cIn)) {
161  sCurrWordBuf[iCur] = cIn;
162  iCur++;
163  if (iCur == iBufSize - 1) {
164  char *s = NULL;
165  unsigned i = 2*iBufSize;
166 
167  /* FIXME: no limit on max size? */
168 
169  SAFENEWARR(s, char, i);
170  memcpy(s, sCurrWordBuf, iBufSize);
172  sCurrWordBuf = s;
173  iBufSize = i;
174  }
175  }
176  }
177  }
178 
180 
181 end_of_word:;
182 
183  sCurrWordBuf[iCur] = '\0';
184  In.putback(cIn);
185 }
char * sCurrWordBuf
Definition: parser.h:164
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
char get(void)
Definition: input.h:99
InputStream & putback(char ch)
Definition: input.h:121
unsigned iBufSize
Definition: parser.h:165
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
bool eof(void) const
Definition: input.h:139

Here is the call graph for this function:

char * LowParser::sGetWord ( void  )

Definition at line 244 of file parser.cc.

References sCurrWordBuf.

Referenced by HighParser::GetDescription(), and HighParser::GetWord().

245 {
246  return sCurrWordBuf;
247 }
char * sCurrWordBuf
Definition: parser.h:164

Friends And Related Function Documentation

friend class HighParser
friend

Definition at line 145 of file parser.h.

Member Data Documentation

enum Token LowParser::CurrToken
private

Definition at line 163 of file parser.h.

Referenced by GetToken().

doublereal LowParser::dCurrNumber
private

Definition at line 166 of file parser.h.

Referenced by dGetReal(), GetToken(), and iGetInt().

HighParser& LowParser::HP
private

Definition at line 162 of file parser.h.

Referenced by GetToken().

unsigned LowParser::iBufSize
private

Definition at line 165 of file parser.h.

Referenced by LowParser(), and PackWords().

char* LowParser::sCurrWordBuf
private

Definition at line 164 of file parser.h.

Referenced by LowParser(), PackWords(), sGetWord(), and ~LowParser().


The documentation for this class was generated from the following files: