OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
oofem::Parser Class Reference

Class for evaluating mathematical expressions in strings. More...

#include <parser.h>

+ Collaboration diagram for oofem::Parser:

Classes

struct  name
 

Public Member Functions

 Parser ()
 
 ~Parser ()
 
double eval (const char *string, int &err)
 
void reset ()
 

Private Types

enum  Token_value {
  NAME, NUMBER, END, SQRT_FUNC,
  SIN_FUNC, COS_FUNC, TAN_FUNC, ATAN_FUNC,
  ASIN_FUNC, ACOS_FUNC, EXP_FUNC, HEAVISIDE_FUNC,
  PLUS ='+', MINUS ='-', MUL ='*', DIV ='/',
  POW ='^', BOOL_EQ, BOOL_LE, BOOL_LT,
  BOOL_GE, BOOL_GT, PRINT =';', ASSIGN ='=',
  LP ='(', RP =')'
}
 

Private Member Functions

namelook (const char *p, int ins=0)
 
nameinsert (const char *s)
 
void error (const char *s)
 
double expr (bool get)
 
double term (bool get)
 
double prim (bool get)
 
double agr (bool get)
 
Token_value get_token ()
 

Private Attributes

int no_of_errors
 
Token_value curr_tok
 
nametable [Parser_TBLSZ]
 
double number_value
 
char string_value [Parser_CMD_LENGTH]
 
const char * parsedLine
 

Detailed Description

Class for evaluating mathematical expressions in strings.

Strings should be in MATLAB syntax. The parser understands variable names with values set by "x=expression;" The following binary operators are recognized: < > == + - * / and the following functions: sqrt, sin, cos, tan, atan, asin, acos, exp, as well as parentheses ( )

Example string: x=3;y=7;sqrt(x*(x/y+3))

Definition at line 54 of file parser.h.

Member Enumeration Documentation

Enumerator
NAME 
NUMBER 
END 
SQRT_FUNC 
SIN_FUNC 
COS_FUNC 
TAN_FUNC 
ATAN_FUNC 
ASIN_FUNC 
ACOS_FUNC 
EXP_FUNC 
HEAVISIDE_FUNC 
PLUS 
MINUS 
MUL 
DIV 
POW 
BOOL_EQ 
BOOL_LE 
BOOL_LT 
BOOL_GE 
BOOL_GT 
PRINT 
ASSIGN 
LP 
RP 

Definition at line 72 of file parser.h.

Constructor & Destructor Documentation

oofem::Parser::Parser ( )
inline

Definition at line 57 of file parser.h.

References Parser_TBLSZ.

oofem::Parser::~Parser ( )
inline

Definition at line 64 of file parser.h.

Member Function Documentation

double oofem::Parser::agr ( bool  get)
private

Definition at line 203 of file parser.C.

References curr_tok, expr(), get_token(), LP, OOFEM_ERROR, and RP.

Referenced by prim().

void oofem::Parser::error ( const char *  s)
private
double oofem::Parser::expr ( bool  get)
private

Definition at line 44 of file parser.C.

References curr_tok, MINUS, PLUS, and term().

Referenced by agr(), eval(), and prim().

name* oofem::Parser::insert ( const char *  s)
inlineprivate

Definition at line 92 of file parser.h.

Referenced by prim().

Parser::name * oofem::Parser::look ( const char *  p,
int  ins = 0 
)
private
double oofem::Parser::prim ( bool  get)
private
void oofem::Parser::reset ( )

Definition at line 391 of file parser.C.

References oofem::Parser::name::next, Parser_TBLSZ, oofem::Parser::name::string, and table.

double oofem::Parser::term ( bool  get)
private

Definition at line 68 of file parser.C.

References BOOL_EQ, BOOL_GE, BOOL_GT, BOOL_LE, BOOL_LT, curr_tok, DIV, MUL, OOFEM_ERROR, POW, and prim().

Referenced by expr().

Member Data Documentation

Token_value oofem::Parser::curr_tok
private

Definition at line 80 of file parser.h.

Referenced by agr(), eval(), expr(), get_token(), prim(), and term().

int oofem::Parser::no_of_errors
private

Definition at line 79 of file parser.h.

Referenced by eval().

double oofem::Parser::number_value
private

Definition at line 87 of file parser.h.

Referenced by get_token(), and prim().

const char* oofem::Parser::parsedLine
private

Definition at line 89 of file parser.h.

Referenced by eval(), and get_token().

char oofem::Parser::string_value[Parser_CMD_LENGTH]
private

Definition at line 88 of file parser.h.

Referenced by get_token(), and prim().

name* oofem::Parser::table[Parser_TBLSZ]
private

Definition at line 86 of file parser.h.

Referenced by look(), and reset().


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

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:39 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011