1 #ifndef GINAC_PARSER_HPP_
3 #include "parse_context.hpp"
12 class parse_error : public std::invalid_argument
15 const std::size_t line;
16 const std::size_t column;
17 parse_error(const std::string& what_,
18 const std::size_t line_ = 0,
19 const std::size_t column_ = 0) throw () :
20 std::invalid_argument(what_), line(line_), column(column_)
25 * Recursive descent parser for GiNaC expressions.
29 // The actual parser rules (in EBNF-alike notation):
31 /// expression: primary binoprhs
32 ex parse_expression();
34 /// primary: indentifier_expr | number_expr | paren_expr | unary_expr
37 /// binoprhs: ([+*/^-] primary)*
38 ex parse_binop_rhs(int, ex&);
40 /// identifier_expr: identifier |
41 /// identifier '(' expression (',' expression)* ')'
42 ex parse_identifier_expr();
44 /// paren_expr: '(' expression ')'
45 ex parse_paren_expr();
47 /// number_expr: number
48 ex parse_number_expr();
50 /// unary_expr: [+-] expression
51 ex parse_unary_expr(const int c);
53 /// literal_expr: 'I' | 'Pi' | 'Euler' | 'Catalan'
54 ex parse_literal_expr();
58 * @param syms_ symbol table.
59 * @param funcs_ function/ctors table.
60 * @param strict_ if true, throw an exception if unknown
61 * symbol is encountered.
63 parser(const symtab& syms_ = symtab(),
64 const prototype_table& funcs_ = get_default_reader(),
65 const bool strict_ = false);
68 /// parse the stream @a input
69 ex operator()(std::istream& input);
70 /// parse the string @a input
71 ex operator()(const std::string& input);
73 /// report the symbol table used by parser
74 symtab get_syms() const
80 /// If true, throw an exception if an unknown symbol is encountered.
83 * Function/ctor table, maps a prototype (which is a name and number
84 * arguments) to a C++ function. Used for parsing identifier_expr's
85 * (see parse_identifier_expr). If expression contains unknown
86 * prototype, an exception will be thrown.
88 const prototype_table funcs;
90 * Symbol (variable) table. Used for parsing identifier_expr's
91 * (see parse_identifier_expr). If parser is strict, exception is
92 * thrown if an unknown symbol is encountered. Non-strict parser
93 * appends unknown symbols to the symbol table.
98 /// current token the parser is looking at
100 /// read the next token from the scanner
106 #endif // GINAC_PARSER_HPP_