- 1 名前:デフォルトの名無しさん mailto:sage [2006/05/06(土) 00:59:13 ]
- プログラミング言語処理系の開発に興味のある人達のスレッドです。
字句解析・構文解析から,データフロー解析,ループ並列化,データ分散,SSA変換, CPS変換,レジスタ割付,命令スケジューリング,ソフトウェアパイプライン, SIMD命令生成,VLIW向けクラスタリング,スクラッチメモリ向け最適化,リンク時最適化, JIT,動的バイナリ変換等の各種最適化,それにVM,GC,低消費電力化などなど。 意味論に関する話題も歓迎です。 過去スレ 1 pc.2ch.net/tech/kako/981/981672957.html 2 pc2.2ch.net/test/read.cgi/tech/1021136715/ 3 pc5.2ch.net/test/read.cgi/tech/1070089173/ 4 pc5.2ch.net/test/read.cgi/tech/1100097050/ 5 pc8.2ch.net/test/read.cgi/tech/1106129164/ 6 pc8.2ch.net/test/read.cgi/tech/1115335709/ 7 pc8.2ch.net/test/read.cgi/tech/1129287390/ 8 pc8.2ch.net/test/read.cgi/tech/1131273918/ 9 pc8.2ch.net/test/read.cgi/tech/1135082582/ 関連リンクは多分 >>2-10 あたり
- 229 名前:デフォルトの名無しさん mailto:sage [2006/05/20(土) 04:50:38 ]
- #include <vector>
#include <functional> #include <stdio.h> #include <ctype.h> bool expression(); char buf[1000], *pc = buf; std::vector<int> data; std::vector<bool(*)()> ops; bool end(int c) { return c == 0 || c == '\n' || c == '\r'; } bool get(char& c) { while (!end(*pc++)) if (!isspace(c = pc[-1])) return true; return false; } bool get_digit(char& c) { return get(c) && (isdigit(c) || --pc && false); } bool is(char c) { char d; return get(d) && (d == c || --pc && false); } bool number() { char c; if (!get_digit(c)) return false; data.push_back(0); do { data.back() = 10 * data.back() + c - '0'; } while (get_digit(c)); return true; } template<typename T> bool binary(T t) { int i = data.back(); data.pop_back(); data.back() = t(data.back(), i); return true; } bool add() { return binary(std::plus<int>()); } bool subtract() { return binary(std::minus<int>()); } bool multiply() { return binary(std::multiplies<int>()); } bool divide() { return binary(std::divides<int>()); }
- 230 名前:デフォルトの名無しさん mailto:sage [2006/05/20(土) 04:52:16 ]
- bool no_operation() { return true; }
bool plus() { return true; } bool minus() { data.back() = -data.back(); return true; } bool push(bool(*op)() = no_operation) { ops.push_back(op); return true; } bool pop() { ops.back()(); ops.pop_back(); return true; } bool additive() { return is('+') && push(add) || is('-') && push(subtract); } bool multicative() { return is('*') && push(multiply) || is('/') && push(divide); } bool unary() { return is('-') && push(minus) || (push(plus), is('+')); } bool factor() { return (number() || is('(') && push() && expression() && is(')')) && pop(); } bool term() { return unary(), factor() && pop() && (!multicative() || term()); } bool expression() { return push() && term() && pop() && (!additive() || expression()); } int main() { while (fgets(pc = buf, sizeof buf, stdin) && push() && expression()) printf(" = %d\n", data.back()); }
- 231 名前:デフォルトの名無しさん mailto:sage [2006/05/20(土) 04:54:38 ]
- 標準入力から正しい式が入力されたら、計算し、
正しくない場合は、何もせずに終了するプログラムをC++で書いてみた やっつけですが
|

|