⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cell.hpp

📁 parser in C++~~~~~~~~~~~~
💻 HPP
字号:
/** * \mainpage COMP151 Programming Assignment 1, Spring 2007 * * \author Fok On Man * \author 06035253 * \author cs_fom * \author LA2A * * \date 8 March, 2007 * * Instructor: <a href="http://www.cs.ust.hk/~dekai/">Dekai Wu</a> * Due: 2007.03.06 at 23:00 by CASS *//** * \file Cell.hpp * * Encapsulates the abstract interface for a concrete class-based * implementation of cells for a cons list data structure. */#ifndef CELL_HPP#define CELL_HPP#include <cstddef>#include <cstdlib>#include <iostream>#include <fstream>#include <sstream>#include <string>#include <stack>using namespace std;/** * \class Cell * \brief Class Cell */class Cell {public:  /**   * \brief Check if this is an int cell.   * \return True iff this is an int cell.   */  bool is_int() const;  /**   * \brief Check if this is a double cell.   * \return True iff this is a double cell.   */  bool is_double() const;  /**   * \brief Check if this is a symbol cell.   * \return True iff this is a symbol cell.   */  bool is_symbol() const;  /**   * \brief Check if this is a cons cell.   * \return True iff this is a cons cell.   */  bool is_cons() const;  /**   * \brief Accessor (error if this is not an int cell).   * \return The value in this int cell.   */  int get_int() const;  /**   * \brief Accessor (error if this is not a double cell).   * \return The value in this double cell.   */  double get_double() const;  /**   * \brief Accessor (error if this is not a symbol cell).   * \return The symbol name in this symbol cell.   */  string get_symbol() const;  /**   * \brief Accessor (error if this is not a cons cell).   * \return First child cell.   */  Cell* get_car() const;  /**   * \brief Accessor (error if this is not a cons cell).   * \return Rest child cell.   */  Cell* get_cdr() const;  /**   * \brief Print the subtree rooted at this cell, in s-expression notation.   * \param os The output stream to print to.   */  void print(ostream& os = cout) const;private:  enum TypeTag {type_int, type_double, type_symbol, type_conspair};  TypeTag tag_m;  struct ConsPair  {    Cell *car;	//!< car this is car pointer    Cell *cdr;	//!< cdr this is cdr poin  };  union  {    int int_m;	//!< int_m this is integer cell vaule    double double_m;	//!< double_m this is double cell vaule    char* symbol_m;	//!< symbol_m this is symbol cell vaule    ConsPair conspair_m;	//!< conspair_m this is conspair cell vaule  };};// Reminder: cons.hpp expects nil to be defined somewhere (for this// implementation, Cell.cpp is the logical place to define it).// Here we promise this again, just to be safe.extern Cell* const nil;#endif // CELL_HPP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -