improve the doxygen documentation of the var-part of mupp.

This commit is contained in:
2025-11-25 17:56:04 +01:00
parent d12b5b23bf
commit d1d1e98a13
14 changed files with 931 additions and 116 deletions

View File

@@ -59,22 +59,51 @@ namespace mupp { namespace parser
namespace ascii = boost::spirit::ascii;
///////////////////////////////////////////////////////////////////////////////
// The expression grammar
/**
* @brief The PExpression grammar for parsing mathematical expressions.
*
* This Boost.Spirit grammar defines the syntax for parsing arithmetic
* expressions with proper operator precedence and associativity:
* - Primary expressions: numbers, variables, functions, parenthesized expressions
* - Unary operators: +, - (highest precedence)
* - Multiplicative operators: *, / (medium precedence)
* - Additive operators: +, - (lowest precedence)
*
* The grammar supports:
* - Numeric literals (double)
* - Variable identifiers (prefixed with '$')
* - Mathematical functions: sin, cos, tan, exp, log, sqrt, etc.
* - Power function: pow(base, exponent)
* - Arithmetic operations with standard precedence
*
* Example expressions:
* - 3.14 * $radius
* - sin($theta) + cos($phi)
* - pow($x, 2.0) + pow($y, 2.0)
*
* @tparam Iterator the iterator type for the input (typically std::string::const_iterator)
*/
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
struct PExpression : qi::grammar<Iterator, ast::expression(), PSkipper<Iterator> >
{
/**
* @brief Constructor that initializes the grammar rules.
* @param error_handler reference to the error handler for reporting parse errors
*/
PExpression(PErrorHandler<Iterator>& error_handler);
qi::symbols<char, ast::optoken> additive_op, multiplicative_op, unary_op;
qi::symbols<char, ast::funid> fun_tok;
qi::symbols<char, ast::optoken> additive_op; ///< Symbol table for additive operators (+, -)
qi::symbols<char, ast::optoken> multiplicative_op; ///< Symbol table for multiplicative operators (*, /)
qi::symbols<char, ast::optoken> unary_op; ///< Symbol table for unary operators (+, -)
qi::symbols<char, ast::funid> fun_tok; ///< Symbol table for function names
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > expr;
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > additive_expr;
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > multiplicative_expr;
qi::rule<Iterator, ast::operand(), PSkipper<Iterator> > unary_expr;
qi::rule<Iterator, ast::operand(), PSkipper<Iterator> > primary_expr;
qi::rule<Iterator, std::string(), PSkipper<Iterator> > identifier;
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > expr; ///< Top-level expression rule
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > additive_expr; ///< Additive expression rule (lowest precedence)
qi::rule<Iterator, ast::expression(), PSkipper<Iterator> > multiplicative_expr; ///< Multiplicative expression rule (medium precedence)
qi::rule<Iterator, ast::operand(), PSkipper<Iterator> > unary_expr; ///< Unary expression rule
qi::rule<Iterator, ast::operand(), PSkipper<Iterator> > primary_expr; ///< Primary expression rule (highest precedence)
qi::rule<Iterator, std::string(), PSkipper<Iterator> > identifier; ///< Identifier rule (variables prefixed with '$')
};
}}