Mercurial > hg > Members > nobuyasu > SampleSource
view Bison-Flex/CALC/discrete-parser/calc-driver.cpp @ 0:db40c85cad7a default tip
upload sample source
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 May 2011 03:11:59 +0900 |
parents | |
children |
line wrap: on
line source
// // 四則演算パーサーとのインターフェース // // Chihiro.SAKAMOTO // #include <iostream> #include <algorithm> #include "calc-driver.h" #include "parser.h" // コンストラクタ calc_driver::calc_driver() { } // デストラクタ calc_driver::~calc_driver() { } // 計算 bool calc_driver::calc(const std::string &f) { cparser parser; // パーサー構築 int result = parser.parse(this, f); // 構文解析 if (result != 0) return false; // パーサーエラー return true; } // エラーメッセージを出力 void calc_driver::error(const std::string& m) { std::cerr << m << std::endl; } // 代入処理 void calc_driver::assign(const std::string &value, cnode *node) { values[value] = node->expr(this); } // print文 void calc_driver::print(cnode *node) { std::cout << node->expr(this) << std::endl; } // 変数リストの一覧表示 struct list_action { void operator()(const std::pair<std::string, int> &it) { std::cout << it.first << " = " << it.second << std::endl; } } ; void calc_driver::list() { std::for_each(values.begin(), values.end(), list_action()); }