1 #ifndef GINAC_PARSER_HPP_
2 #define GINAC_PARSER_HPP_
4 #include "parse_context.h"
13 class parse_error : public std::invalid_argument
16 const std::size_t line;
17 const std::size_t column;
18 parse_error(const std::string& what_,
19 const std::size_t line_ = 0,
20 const std::size_t column_ = 0) throw () :
21 std::invalid_argument(what_), line(line_), column(column_)
26 * Recursive descent parser for GiNaC expressions.
30 // The actual parser rules (in EBNF-alike notation):
32 /// expression: primary binoprhs
33 ex parse_expression();
35 /// primary: indentifier_expr | number_expr | paren_expr | unary_expr
38 /// binoprhs: ([+*/^-] primary)*
39 ex parse_binop_rhs(int, ex&);
41 /// identifier_expr: identifier |
42 /// identifier '(' expression (',' expression)* ')'
43 ex parse_identifier_expr();
45 /// paren_expr: '(' expression ')'
46 ex parse_paren_expr();
48 /// number_expr: number
49 ex parse_number_expr();
51 /// unary_expr: [+-] expression
52 ex parse_unary_expr();
54 /// literal_expr: 'I' | 'Pi' | 'Euler' | 'Catalan'
55 ex parse_literal_expr();
59 * @param syms_ symbol table.
60 * @param funcs_ function/ctors table.
61 * @param strict_ if true, throw an exception if unknown
62 * symbol is encountered.
64 parser(const symtab& syms_ = symtab(),
65 const bool strict_ = false,
66 const prototype_table& funcs_ = get_default_reader());
69 /// parse the stream @a input
70 ex operator()(std::istream& input);
71 /// parse the string @a input
72 ex operator()(const std::string& input);
74 /// report the symbol table used by parser
75 symtab get_syms() const
79 /// read/write access to the symbol table
85 /// If true, throw an exception if an unknown symbol is encountered.
89 * Function/ctor table, maps a prototype (which is a name and number
90 * arguments) to a C++ function. Used for parsing identifier_expr's
91 * (see parse_identifier_expr). If expression contains unknown
92 * prototype, an exception will be thrown.
94 const prototype_table funcs;
96 * Symbol (variable) table. Used for parsing identifier_expr's
97 * (see parse_identifier_expr). If parser is strict, exception is
98 * thrown if an unknown symbol is encountered. Non-strict parser
99 * appends unknown symbols to the symbol table.
104 /// current token the parser is looking at
106 /// read the next token from the scanner
112 #endif // GINAC_PARSER_HPP_