Public Member Functions | |
void | parse (Element< S, T > &exp) |
Do the parsing. | |
bool | error () const |
Return true when an error occured. | |
const std::string & | error_msg () const |
Return the error message. | |
Protected Member Functions | |
void | parse_error (const std::string &msg="parse_error.") throw (const std::string&) |
Generate a parse error. | |
void | accept (token_e tok) |
Accept token, or generate an error. | |
void | parse_exp (Element< S, T > &exp) |
exp ::= term ('+' term)* | |
void | parse_term (Element< S, T > &exp) |
term ::= right_weighted ('.'? right_weighted)* | |
void | parse_right_weighted (Element< S, T > &exp) |
right_weighted ::= left_weighted (' ' weight)* | |
void | parse_left_weighted (Element< S, T > &exp) |
left_weighted ::= weight ' ' left_weighted | stared | |
void | parse_stared (Element< S, T > &exp) |
stared ::= factor '*'* | |
void | parse_factor (Element< S, T > &exp) |
factor ::= 1 | 0 | word | '(' exp ')' | |
void | trace (const std::string &msg) |
Trace parsing. | |
template<class Misc> | |
void | trace (const std::string &msg, const Misc &v) |
Trace parsing. |
This class handles rational expression parsing, once a Lexer has been created.
Ideally, we would like to parse:
exp ::= '(' exp ')' | exp '+' exp | exp '.' exp | exp exp | exp '*' | weight ' ' exp | exp ' ' weight | 0 | 1 | word
But this grammar has to be changed to allow a classical LL(2) parsing:
exp ::= term ('+' term)* term ::= right_weighted ('.'? right_weighted)* right_weighted ::= left_weighted (' ' weight)* left_weighted ::= weight ' ' left_weighted | stared stared ::= factor '*'* factor ::= '(' exp ')' | word | 0 | 1
Definition at line 421 of file krat_exp_parser.hxx.
void accept | ( | token_e | tok | ) | [inline, protected] |
Accept token, or generate an error.
This function asks the lexer whether the first input token matches the argument or not. When matching is successfull, the first input token is eaten, an error is risen else.
tok | The token to match. |
Definition at line 518 of file krat_exp_parser.hxx.
References KRatExpToken::is_a(), Parser::parse_error(), KRatExpToken::to_string(), KRatExpToken::token::to_string(), and Parser::trace().
Referenced by Parser::parse(), Parser::parse_exp(), Parser::parse_factor(), Parser::parse_left_weighted(), Parser::parse_right_weighted(), Parser::parse_stared(), and Parser::parse_term().