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
|
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.
|