|
mupp 1.1.0
|
The PProgram struct performs semantic analysis on the AST. More...
#include <PProgram.hpp>
Public Types | |
| typedef bool | result_type |
| Return type for all visitor methods. | |
Public Member Functions | |
| template<typename PErrorHandler> | |
| PProgram (PErrorHandler &error_handler_) | |
| Constructor that sets up the error handler. | |
| bool | operator() (ast::nil) |
| Visitor for nil AST nodes (should never be called). | |
| bool | operator() (double x) |
| Visitor for numeric literal nodes. | |
| bool | operator() (ast::assignment const &x) |
| Visitor for assignment statements. | |
| bool | operator() (ast::expression const &x) |
| Visitor for expression nodes. | |
| bool | operator() (ast::function const &x) |
| Visitor for function call nodes. | |
| bool | operator() (ast::operation const &x) |
| Visitor for binary operation nodes. | |
| bool | operator() (ast::power const &x) |
| Visitor for power operation nodes. | |
| bool | operator() (ast::statement const &x) |
| Visitor for statement nodes (variant wrapper). | |
| bool | operator() (ast::statement_list const &x) |
| Visitor for statement lists (program entry point). | |
| bool | operator() (ast::unary const &x) |
| Visitor for unary operation nodes. | |
| bool | operator() (ast::variable const &x) |
| Visitor for variable reference nodes. | |
| bool | operator() (ast::variable_declaration const &x) |
| Visitor for variable declaration nodes. | |
| void | add_predef_var_values (const std::string &name, std::vector< double > &val, std::vector< double > &err) |
| Injects predefined variable values from collection data. | |
| void | add_var (std::string const &name) |
| Adds a variable to the symbol table. | |
| bool | find_var (std::string const &name) |
| Checks if a variable exists in the symbol table. | |
| bool | find_var (std::string const &name, unsigned int &idx) |
| Finds a variable and returns its index. | |
| std::string | pos_to_var (std::string const &name, bool &ok) |
| Converts position-based variable reference to variable name. | |
| std::vector< PVarHandler > | getVars () |
| Gets all variables from the symbol table. | |
Private Attributes | |
| std::vector< PVarHandler > | fVariable |
| Symbol table of declared variables. | |
| std::map< int, std::string > | fVarPos |
| Map from position index to variable name. | |
| boost::function< void(int tag, std::string const &what)> | error_handler |
| Error handler function for reporting semantic errors. | |
The PProgram struct performs semantic analysis on the AST.
This visitor pattern struct traverses the AST generated by the parser and performs semantic checks:
After successful semantic analysis, the variable table can be used by PProgEval for expression evaluation. Semantic errors are reported via the error handler with source position information.
Definition at line 164 of file PProgram.hpp.
| typedef bool mupp::prog::PProgram::result_type |
Return type for all visitor methods.
Definition at line 166 of file PProgram.hpp.
|
inline |
Constructor that sets up the error handler.
| PErrorHandler | the error handler type |
| error_handler_ | reference to the error handler for reporting semantic errors |
Definition at line 174 of file PProgram.hpp.
| void mupp::prog::PProgram::add_predef_var_values | ( | const std::string & | name, |
| std::vector< double > & | val, | ||
| std::vector< double > & | err ) |
Injects predefined variable values from collection data.
| name | the variable name |
| val | vector of values for this variable |
| err | vector of error values for this variable |
Definition at line 261 of file PProgram.cpp.
| void mupp::prog::PProgram::add_var | ( | std::string const & | name | ) |
Adds a variable to the symbol table.
| name | the variable name to add |
Definition at line 275 of file PProgram.cpp.
| bool mupp::prog::PProgram::find_var | ( | std::string const & | name | ) |
Checks if a variable exists in the symbol table.
| name | the variable name to find (with or without leading '$') |
Definition at line 285 of file PProgram.cpp.
| bool mupp::prog::PProgram::find_var | ( | std::string const & | name, |
| unsigned int & | idx ) |
Finds a variable and returns its index.
| name | the variable name to find (with or without leading '$') |
| idx | output parameter for the variable index |
Definition at line 291 of file PProgram.cpp.
|
inline |
Gets all variables from the symbol table.
Definition at line 311 of file PProgram.hpp.
| bool mupp::prog::PProgram::operator() | ( | ast::assignment const & | x | ) |
Visitor for assignment statements.
| x | the assignment AST node |
Definition at line 84 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::expression const & | x | ) |
Visitor for expression nodes.
| x | the expression AST node |
Definition at line 101 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::function const & | x | ) |
Visitor for function call nodes.
| x | the function AST node |
Definition at line 114 of file PProgram.cpp.
|
inline |
Visitor for nil AST nodes (should never be called).
Definition at line 187 of file PProgram.hpp.
| bool mupp::prog::PProgram::operator() | ( | ast::operation const & | x | ) |
Visitor for binary operation nodes.
| x | the operation AST node |
Definition at line 147 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::power const & | x | ) |
Visitor for power operation nodes.
| x | the power AST node |
Definition at line 173 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::statement const & | x | ) |
Visitor for statement nodes (variant wrapper).
| x | the statement AST node |
Definition at line 188 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::statement_list const & | x | ) |
Visitor for statement lists (program entry point).
| x | the statement list AST node |
Definition at line 193 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::unary const & | x | ) |
Visitor for unary operation nodes.
| x | the unary AST node |
Definition at line 202 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::variable const & | x | ) |
Visitor for variable reference nodes.
| x | the variable AST node |
Definition at line 220 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | ast::variable_declaration const & | x | ) |
Visitor for variable declaration nodes.
| x | the variable declaration AST node |
Definition at line 239 of file PProgram.cpp.
| bool mupp::prog::PProgram::operator() | ( | double | x | ) |
Visitor for numeric literal nodes.
| x | the numeric value |
Definition at line 79 of file PProgram.cpp.
| std::string mupp::prog::PProgram::pos_to_var | ( | std::string const & | name, |
| bool & | ok ) |
Converts position-based variable reference to variable name.
Supports syntax like $0, $1, etc. to reference variables by position.
| name | the variable reference (name or position number) |
| ok | output parameter indicating whether conversion succeeded |
Definition at line 313 of file PProgram.cpp.
|
private |
Error handler function for reporting semantic errors.
Definition at line 319 of file PProgram.hpp.
|
private |
Symbol table of declared variables.
Definition at line 314 of file PProgram.hpp.
|
private |
Map from position index to variable name.
Definition at line 315 of file PProgram.hpp.