MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
parser.cc File Reference
#include "mbconfig.h"
#include <cstring>
#include <stdlib.h>
#include <stack>
#include <map>
#include "mathtyp.h"
#include "parser.h"
#include "filename.h"
#include "Rot.hh"
Include dependency graph for parser.cc:

Go to the source code of this file.

Classes

struct  DescWordSetType
 
struct  RemarkDR
 
struct  PrintSymbolTableDR
 
struct  SetDR
 
struct  SetEnvDR
 
struct  ExitDR
 

Typedefs

typedef std::map< std::string,
DescRead *, ltstrcase
DescFuncMapType
 

Functions

static int skip_remarks (HighParser &HP, InputStream &In, char &cIn)
 
bool SetDescData (const std::string &name, DescRead *rf)
 
bool ReadDescription (HighParser &HP, const std::string &desc)
 
static void InitDescData (void)
 
static void DestroyDescData (void)
 
HighParser::ErrOut mbdyn_get_line_data (void)
 
std::ostream & mbdyn_print_line_data (std::ostream &out)
 
std::ostream & operator<< (std::ostream &out, const HighParser::ErrOut &err)
 

Variables

static DescFuncMapType DescFuncMap
 
static DescWordSetType DescWordSet
 
static unsigned desc_done
 
static std::stack< const
HighParser * > 
pHP
 
static const HighParser::ErrOut unknownErr = { "(unknown)", "(unknown)", 0 }
 

Typedef Documentation

typedef std::map<std::string, DescRead *, ltstrcase> DescFuncMapType

Definition at line 289 of file parser.cc.

Function Documentation

static void DestroyDescData ( void  )
static

Definition at line 575 of file parser.cc.

References desc_done, DescFuncMap, and MBDYN_EXCEPT_ARGS.

Referenced by HighParser::~HighParser().

576 {
577  if (::desc_done == 0) {
578  silent_cerr("DestroyDescData() called once too many" << std::endl);
580  }
581 
582  if (--::desc_done > 0) {
583  return;
584  }
585 
586  /* free stuff */
587  for (DescFuncMapType::iterator i = DescFuncMap.begin(); i != DescFuncMap.end(); ++i) {
588  delete i->second;
589  }
590  DescFuncMap.clear();
591 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
static DescFuncMapType DescFuncMap
Definition: parser.cc:290
static unsigned desc_done
Definition: parser.cc:550
static void InitDescData ( void  )
static

Definition at line 553 of file parser.cc.

References desc_done, and SetDescData().

Referenced by HighParser::HighParser().

554 {
555  if (::desc_done++ > 0) {
556  return;
557  }
558 
559  SetDescData("remark", new RemarkDR);
560  SetDescData("print" "symbol" "table", new PrintSymbolTableDR);
561  SetDescData("set", new SetDR);
562  SetDescData("setenv", new SetEnvDR);
563  SetDescData("exit", new ExitDR);
564 
565  /* NOTE: add here initialization of new built-in descriptions;
566  * alternative ways to register new custom descriptions are:
567  * - call SetDescData() from anywhere in the code
568  * - write a module that calls SetDescData() from inside a function
569  * called module_init(), and run-time load it using "module load"
570  * in the input file.
571  */
572 }
bool SetDescData(const std::string &name, DescRead *rf)
Definition: parser.cc:301
Definition: parser.cc:421
static unsigned desc_done
Definition: parser.cc:550

Here is the call graph for this function:

HighParser::ErrOut mbdyn_get_line_data ( void  )

Definition at line 603 of file parser.cc.

References pHP, and unknownErr.

Referenced by TypedValue::Cast(), and MathParser::stmt().

604 {
605  if (!pHP.empty()) {
606  return pHP.top()->GetLineData();
607  }
608 
609  return unknownErr;
610 }
static const HighParser::ErrOut unknownErr
Definition: parser.cc:600
static std::stack< const HighParser * > pHP
Definition: parser.cc:598
std::ostream& mbdyn_print_line_data ( std::ostream &  out)

Definition at line 613 of file parser.cc.

References pHP.

614 {
615  if (!pHP.empty()) {
616  out << pHP.top()->GetLineData();
617  }
618 
619  return out;
620 }
static std::stack< const HighParser * > pHP
Definition: parser.cc:598
std::ostream& operator<< ( std::ostream &  out,
const HighParser::ErrOut err 
)

Definition at line 1372 of file parser.cc.

References DIR_SEP, HighParser::ErrOut::iLineNumber, HighParser::ErrOut::sFileName, and HighParser::ErrOut::sPathName.

1373 {
1374  out << err.iLineNumber;
1375 
1376  if (err.sFileName != 0) {
1377  out << ", file <";
1378  if (err.sPathName != 0) {
1379  out << err.sPathName << DIR_SEP;
1380  }
1381  out << err.sFileName << '>';
1382  }
1383 
1384  return out;
1385 }
const char * sFileName
Definition: parser.h:304
unsigned int iLineNumber
Definition: parser.h:306
const char DIR_SEP
Definition: filename.h:88
const char * sPathName
Definition: parser.h:305
bool ReadDescription ( HighParser HP,
const std::string &  desc 
)

Definition at line 310 of file parser.cc.

References DEBUGCOUTFNAME, DescFuncMap, func(), HighParser::GetLineData(), HighParser::GotDescription(), HighParser::IsArg(), HighParser::IsDescription(), and MBDYN_EXCEPT_ARGS.

Referenced by HighParser::GetDescription().

311 {
312  DEBUGCOUTFNAME("ReadDescription()");
313 
314  bool bRC(false);
315  DescFuncMapType::iterator func = DescFuncMap.find(desc);
316  if (func != DescFuncMap.end()) {
317  HP.GotDescription();
318  if (!HP.IsArg() && !HP.IsDescription()) {
319  silent_cerr("Parser error in ReadDescription(),"
320  " colon or semicolon expected after description at line "
321  << HP.GetLineData() << std::endl);
323  }
324 
325  bRC = func->second->Read(HP);
326 
327  if (HP.IsArg()) {
328  silent_cerr("semicolon expected at line " << HP.GetLineData() << std::endl);
330  }
331  }
332 
333  return bRC;
334 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define DEBUGCOUTFNAME(fname)
Definition: myassert.h:256
bool IsDescription(void) const
Definition: parser.cc:692
virtual HighParser::ErrOut GetLineData(void) const
Definition: parser.cc:681
Token GotDescription(void)
Definition: parser.cc:698
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
static DescFuncMapType DescFuncMap
Definition: parser.cc:290
virtual bool IsArg(void)
Definition: parser.cc:807

Here is the call graph for this function:

bool SetDescData ( const std::string &  name,
DescRead rf 
)

Definition at line 301 of file parser.cc.

References DescFuncMap.

Referenced by InitDescData(), and module_init().

302 {
303  pedantic_cout("registering description \"" << name << "\"" << std::endl);
304  return DescFuncMap.insert(DescFuncMapType::value_type(name, rf)).second;
305 }
static DescFuncMapType DescFuncMap
Definition: parser.cc:290
static int skip_remarks ( HighParser HP,
InputStream In,
char &  cIn 
)
static

Definition at line 49 of file parser.cc.

References InputStream::eof(), InputStream::get(), HighParser::GetLineData(), MathParser::ONE_LINE_REMARK, and InputStream::putback().

Referenced by HighParser::GetStringWithDelims(), LowParser::GetToken(), HighParser::IsStringWithDelims(), and HighParser::ParseWord().

50 {
51 skip_again:;
52  for (cIn = In.get(); isspace(cIn); cIn = In.get()) {
53  // this is here in case in some implementation isspace returns success for EOF
54  if (In.eof()) {
55  return -1;
56  }
57  }
58 
59  if (In.eof()) {
60  return -1;
61  }
62 
63  switch (cIn) {
64  case -1: // should be EOF!
65  return -1;
66 
68  for (cIn = In.get(); cIn != '\n'; cIn = In.get()) {
69  if (cIn == '\\') {
70  cIn = In.get();
71  if (In.eof()) {
72  return -1;
73  }
74  if (cIn == '\r') {
75  /* if input file was prepared
76  * under DOS/Windows */
77  cIn = In.get();
78  if (In.eof()) {
79  return -1;
80  }
81  }
82  }
83  if (In.eof()) {
84  return -1;
85  }
86  }
87  goto skip_again;
88 
89  case '/':
90  cIn = In.get();
91  if (In.eof()) {
92  return -1;
93 
94  } else if (cIn == '*') {
95  for (cIn = In.get(); !In.eof(); cIn = In.get()) {
96  if (cIn == '*') {
97 end_of_comment:;
98  cIn = In.get();
99  if (In.eof()) {
100  return -1;
101  }
102  if (cIn == '/') {
103  goto skip_again;
104  }
105 
106  } else if (cIn == '/') {
107  cIn = In.get();
108  if (In.eof()) {
109  return -1;
110  }
111  if (cIn == '*') {
112  silent_cerr("warning: '/*' inside a comment "
113  "at line " << HP.GetLineData()
114  << std::endl);
115  goto end_of_comment;
116  }
117  }
118  }
119  if (In.eof()) {
120  return -1;
121  }
122 
123  } else {
124  In.putback(cIn);
125  return 0;
126  }
127  }
128 
129  return 0;
130 }
static const char ONE_LINE_REMARK
Definition: mathp.h:188
virtual HighParser::ErrOut GetLineData(void) const
Definition: parser.cc:681
char get(void)
Definition: input.h:99
InputStream & putback(char ch)
Definition: input.h:121
bool eof(void) const
Definition: input.h:139

Here is the call graph for this function:

Variable Documentation

unsigned desc_done
static

Definition at line 550 of file parser.cc.

Referenced by DestroyDescData(), and InitDescData().

DescFuncMapType DescFuncMap
static

Definition at line 290 of file parser.cc.

Referenced by DestroyDescData(), DescWordSetType::IsWord(), ReadDescription(), and SetDescData().

DescWordSetType DescWordSet
static

Definition at line 298 of file parser.cc.

std::stack<const HighParser *> pHP
static
const HighParser::ErrOut unknownErr = { "(unknown)", "(unknown)", 0 }
static

Definition at line 600 of file parser.cc.

Referenced by mbdyn_get_line_data().