#ifndef PARSER_H #define PARSER_H #include #include #include "token.h" #include "number.h" namespace Bu { class Stream; }; class Lexer; /** * * expr: literal * | variable * | expr '+' expr * | expr '-' expr * | expr '*' expr * | expr '/' expr * | '(' expr ')' * | '-' expr * | variable '=' expr * ; * * ----- * * expr': literal * | variable * | '(' expr ')' * | '-' expr' * ; * * expr: expr' '+' expr * | expr' '-' expr * | expr' '*' expr * | expr' '/' expr * | expr' * | variable '=' expr * ; */ class Parser { public: Parser( Lexer &lex, Bu::Stream &rOut ); virtual ~Parser(); void parse(); private: void expr(); void exprP(); private: void shift( const Token &t ); void reduce(); int reqTokens( Token::Type eType ); int getPriority( Token::Type eType ); Number &deref( Token &t ); private: Lexer &lex; Bu::Stream &rOut; typedef Bu::List TokenStack; TokenStack tsParse; TokenStack tsScript; }; #endif