Parser Struct Template Reference
[Series]

Parser class used in the parse() function. More...

List of all members.

Public Types

typedef KRatExpToken< typename
Element< S, T >::monoid_elt_value_t,
typename Element< S, T
>::semiring_elt_value_t
krat_exp_token_t
typedef Element< S, T >::monoid_elt_t monoid_elt_t
typedef Element< S, T >::monoid_elt_value_t monoid_elt_value_t
typedef monoid_elt_t::set_t monoid_t
typedef Element< S, T >::semiring_elt_t semiring_elt_t
typedef semiring_elt_t::set_t semiring_t
typedef Element< S, T >::semiring_elt_value_t semiring_elt_value_t
typedef std::list< krat_exp_token_ttoken_stream_t

Public Member Functions

 Parser (Lexer< S, T > &lexer, bool trace=false)
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.
void set_trace (bool trace)

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.

Protected Attributes

Lexer< S, T > & lexer_
bool trace_
bool error_
std::string error_msg_


Detailed Description

template<class S, class T>
struct vcsn::algebra::Parser< S, T >

Parser class used in the parse() function.

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 420 of file krat_exp_parser.hxx.


Member Function Documentation

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.

Parameters:
tok The token to match.

Definition at line 517 of file krat_exp_parser.hxx.

References KRatExpToken::is_a(), Parser::lexer_, Parser::parse_error(), KRatExpToken::to_string(), and Parser::trace().

Referenced by Parser::parse(), and Parser::parse_exp().


Generated on Sat Jul 29 17:31:38 2006 for Vaucanson by  doxygen 1.4.6