1 #ifndef GINAC_PARSER_HPP_
3 #include "parse_context.hpp"
13 * Recursive descent parser for GiNaC expressions.
17 // The actual parser rules (in EBNF-alike notation):
19 /// expression: primary binoprhs
20 ex parse_expression();
22 /// primary: indentifier_expr | number_expr | paren_expr | unary_expr
25 /// binoprhs: ([+*/^-] primary)*
26 ex parse_binop_rhs(int, ex&);
28 /// identifier_expr: identifier |
29 /// identifier '(' expression (',' expression)* ')'
30 ex parse_identifier_expr();
32 /// paren_expr: '(' expression ')'
33 ex parse_paren_expr();
35 /// number_expr: number
36 ex parse_number_expr();
38 /// unary_expr: [+-] expression
39 ex parse_unary_expr(const int c);
41 /// literal_expr: 'I' | 'Pi' | 'Euler' | 'Catalan'
42 ex parse_literal_expr();
46 * @param syms_ symbol table.
47 * @param funcs_ function/ctors table.
48 * @param strict_ if true, throw an exception if unknown
49 * symbol is encountered.
51 parser(const symtab& syms_ = symtab(),
52 const prototype_table& funcs_ = get_default_reader(),
53 const bool strict_ = false);
56 /// parse the stream @a input
57 ex operator()(std::istream& input);
58 /// parse the string @a input
59 ex operator()(const std::string& input);
61 /// report the symbol table used by parser
62 symtab get_syms() const
68 /// If true, throw an exception if an unknown symbol is encountered.
71 * Function/ctor table, maps a prototype (which is a name and number
72 * arguments) to a C++ function. Used for parsing identifier_expr's
73 * (see parse_identifier_expr). If expression contains unknown
74 * prototype, an exception will be thrown.
76 const prototype_table funcs;
78 * Symbol (variable) table. Used for parsing identifier_expr's
79 * (see parse_identifier_expr). If parser is strict, exception is
80 * thrown if an unknown symbol is encountered. Non-strict parser
81 * appends unknown symbols to the symbol table.
86 /// current token the parser is looking at
88 /// read the next token from the scanner
94 #endif // GINAC_PARSER_HPP_