OOFEM 3.0
Loading...
Searching...
No Matches
oofem::Parser Class Reference

#include <parser.h>

Collaboration diagram for oofem::Parser:

Classes

struct  name

Public Member Functions

 Parser ()
 ~Parser ()
double eval (const char *string, int &err)
void eval (const char *string, FloatArray &answer, const char *name, int &err)
void setVariableValue (const char *name, int indx, double value)
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 , INT_FUNC ,
  HEAVISIDE_FUNC , HEAVISIDE_FUNC1 , PLUS ='+' , MINUS ='-' ,
  MUL ='*' , DIV ='/' , MOD ='' , POW ='^' ,
  BOOL_EQ , BOOL_LE , BOOL_LT , BOOL_GE ,
  BOOL_GT , PRINT =';' , ASSIGN ='=' , LP ='(' ,
  RP =')' , LB ='[' , RB =']'
}

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 ()
double getVariableValue (const char *name, int indx)

Private Attributes

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

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 55 of file parser.h.

Member Enumeration Documentation

◆ Token_value

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

Definition at line 76 of file parser.h.

Constructor & Destructor Documentation

◆ Parser()

oofem::Parser::Parser ( )
inline

Definition at line 58 of file parser.h.

References curr_tok, no_of_errors, Parser_TBLSZ, PRINT, and table.

◆ ~Parser()

oofem::Parser::~Parser ( )
inline

Definition at line 65 of file parser.h.

References reset().

Member Function Documentation

◆ agr()

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

Definition at line 238 of file parser.C.

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

Referenced by error(), and prim().

◆ error()

void oofem::Parser::error ( const char * s)
private

◆ eval() [1/2]

void oofem::Parser::eval ( const char * string,
FloatArray & answer,
const char * name,
int & err )

◆ eval() [2/2]

◆ expr()

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(), error(), eval(), eval(), and prim().

◆ get_token()

◆ getVariableValue()

double oofem::Parser::getVariableValue ( const char * name,
int indx )
private

◆ insert()

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

Definition at line 100 of file parser.h.

References look().

◆ look()

◆ prim()

◆ reset()

void oofem::Parser::reset ( )

Definition at line 453 of file parser.C.

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

Referenced by ~Parser().

◆ setVariableValue()

void oofem::Parser::setVariableValue ( const char * name,
int indx,
double value )

◆ term()

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, MOD, MUL, OOFEM_ERROR, POW, and prim().

Referenced by error(), and expr().

Member Data Documentation

◆ curr_tok

Token_value oofem::Parser::curr_tok
private

Definition at line 84 of file parser.h.

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

◆ no_of_errors

int oofem::Parser::no_of_errors
private

Definition at line 83 of file parser.h.

Referenced by eval(), eval(), and Parser().

◆ number_value

double oofem::Parser::number_value =0.0
private

Definition at line 95 of file parser.h.

Referenced by get_token(), and prim().

◆ parsedLine

const char* oofem::Parser::parsedLine = nullptr
private

Definition at line 97 of file parser.h.

Referenced by eval(), eval(), and get_token().

◆ string_value

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

Definition at line 96 of file parser.h.

Referenced by get_token(), and prim().

◆ table

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

Definition at line 94 of file parser.h.

Referenced by look(), Parser(), and reset().


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

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011