1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
#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