#ifndef PARSER_HPP
#define PARSER_HPP #include <exception> #include <list> #include "lex.hpp" #include "symbol-table.hpp" #include "types.hpp" namespace LambdaCalc { /* Parser for simple expressions: expr --> identifier expr --> integer expr --> '(' expr expr ')' expr --> '(' lambda identifier expr ')' expr --> '(' define identifier expr ')' expr --> '(' if expr expr expr')' */ class Parser { public: class Exception: public std::exception { public: Exceptionsp; Exception(conTokenpan> Token& token, const std::string& message); virtu~Exceptionnbsp;~Exception() throw(); virtual const chawhatpan>* what() const throw(); private: std::string msg; }; Parser ParsLexLex& leSymbolTableble& symtab); FunctionPtr; FunctionPgetFunctionion() throw(Exception); private: Lexsp; Lex& lex; // input channel SymbolTable; SymbolTable& symtab; // used for macros Token; Token token; // current token bool tokenConsumed; // true, if we need to fetch the next token std::list<std::string> bindings; // lexically scoped bindings vonextToken nextToken(); Token; TokgetTokenken(); unsigned ifindBindingbsp;findBinding(const std::string& varname); FunctionPtr; FunctionPparseExpressionion() throw(Exception); }; } // namespace LambdaCalc #endif |