#ifndef PARSER_H #define PARSER_H #include #include #include "token.h" #include "number.h" namespace Bu { class Stream; }; class Lexer; class Expression; /** * * 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 ); virtual ~Parser(); Expression *parse(); private: void expr(); void exprP(); void exprR(); void statement(); private: void shift( const Token &t ); void reduce(); void output( const Token &t ); int reqTokens( Token::Type eType ); int getPriority( Token::Type eType ); void printState( const Bu::String &sTag ); private: Lexer &lex; typedef Bu::List TokenStack; TokenStack tsTerminal; TokenStack tsNonTerminal; Expression *pCurExp; }; #endif