# HG changeset patch # User nobuyasu # Date 1304976368 -32400 # Node ID a3ea4c73696bd6484978795d986cd894dc73e237 # Parent 3f4ade70b4d21f72acce84d2786e980e52d8aab6 move files diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/Makefile Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,94 @@ +SOURCES = script.cpp compiler.cpp node.cpp vm.cpp script-parser.yy script-scanner.ll +HEADERS = compiler.h node.h vm.h vm_code.h vm_value.h +OBJ = script.o compiler.o node.o vm.o script-parser.o script-scanner.o +BISON_OUTPUT = script-parser.cc script-parser.hh location.hh position.hh + +#CFLAGS = -O2 +CFLAGS = -g3 -O0 + +all: script + +convert: $(SOURCES) $(HEADERS) + +.SUFFIXES: +.SUFFIXES: .cpp .cc .ll .yy .o + +script: $(OBJ) + $(CC) $(LDFLAGS) -o $@ $(OBJ) -lstdc++ + +.cpp.o: + $(CC) -c $(CFLAGS) -o $@ $< + +.cc.o: + $(CC) -c $(CFLAGS) -o $@ $< + +$(BISON_OUTPUT): script-parser.yy + bison -d -ra -oscript-parser.cc script-parser.yy + +script-scanner.cc: script-scanner.ll + flex -8 -oscript-scanner.cc script-scanner.ll + +script-parser.o: $(BISON_OUTPUT) +script-scanner.o: script-scanner.cc + +script.cpp: ../script.cpp + nkf --unix $< > $@ + +compiler.cpp: ../compiler.cpp + nkf --unix $< > $@ + +node.cpp: ../node.cpp + nkf --unix $< > $@ + +vm.cpp: ../vm.cpp + nkf --unix $< > $@ + +script-parser.yy: ../script-parser.yy + nkf --unix $< > $@ + +script-scanner.ll: ../script-scanner.ll + nkf --unix $< > $@ + +vm_code.h: ../vm_code.h + nkf --unix $< > $@ + +vm_value.h: ../vm_value.h + nkf --unix $< > $@ + +vm.h: ../vm.h + nkf --unix $< > $@ + +node.h: ../node.h + nkf --unix $< > $@ + +compiler.h: ../compiler.h + nkf --unix $< > $@ + +depend: + makedepend -- $(CFLAGS) -- $(SOURCES) + +script.o: script-parser.hh +node.o: location.hh + +# DO NOT DELETE + +script.o: compiler.h script-parser.hh stack.hh node.h location.hh position.hh +script.o: vm.h vm_value.h vm_code.h +compiler.o: script-parser.hh stack.hh node.h location.hh position.hh vm.h +compiler.o: vm_value.h vm_code.h compiler.h +node.o: node.h location.hh position.hh vm.h vm_value.h vm_code.h compiler.h +node.o: script-parser.hh stack.hh +vm.o: vm.h vm_value.h vm_code.h +script-parser.o: node.h location.hh position.hh vm.h vm_value.h vm_code.h +script-parser.o: compiler.h script-parser.hh stack.hh +#script-scanner.o: /usr/include/errno.h /usr/include/features.h +#script-scanner.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h +#script-scanner.o: /usr/include/bits/errno.h /usr/include/linux/errno.h +#script-scanner.o: /usr/include/asm/errno.h /usr/include/asm-i486/errno.h +#script-scanner.o: /usr/include/asm-generic/errno.h +#script-scanner.o: /usr/include/asm-generic/errno-base.h /usr/include/limits.h +#script-scanner.o: /usr/include/bits/posix1_lim.h +#script-scanner.o: /usr/include/bits/local_lim.h /usr/include/linux/limits.h +#script-scanner.o: /usr/include/bits/posix2_lim.h compiler.h script-parser.hh +script-scanner.o: stack.hh node.h location.hh position.hh vm.h vm_value.h +script-scanner.o: vm_code.h diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/compiler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/compiler.cpp Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,426 @@ +#include +#include +#include "script-parser.hh" +#include "compiler.h" + +#ifdef _MSC_VER +#pragma warning(disable: 4996) +#endif + +// コンストラクタ + +compiler::compiler() + : error_count(0) +{ +} + +// デストラクタ + +compiler::~compiler() +{ +} + +// コンパイル + +bool compiler::compile(const std::string &f, vm::data &data) +{ + // システムコールの設定 + + file = f; + scan_begin(); // スキャナー初期化 + yy::script_parser parser(*this); // パーサー構築 + int result = parser.parse(); // 構文解析 + scan_end(); // スキャナー終了 + + if (result != 0) + return false; // パーサーエラー + + // ステートスタックが空ではないならば、if, for, whileが + // 閉じていない + while (!state_stack.empty()) { + CState &state = state_stack.top(); + switch (state.state_) { + case STATE_IF: + error(state.l_, "ifに対応するendifが有りません"); + break; + + case STATE_FOR: + error(state.l_, "forに対応するnextが有りません"); + delete state.start_; + delete state.end_; + delete state.step_; + break; + + case STATE_WHILE: + error(state.l_, "whileに対応するwendが有りません"); + break; + } + state_stack.pop(); + } + + // 番兵用HALTコマンドを追加 + const CVMCode &code = statement.back(); + if (code.op_ != VM_HALT) // haltが無いならば + OpHalt(); // haltを追加 + + int code_size = LabelSetting(); // ラベルにアドレスを設定 + CraeteData(data, code_size); // バイナリ生成 + + return error_count == 0; +} + +// エラーメッセージを出力 + +void compiler::error(const yy::location& l, const std::string& m) +{ + std::cerr << l << ": " << m << std::endl; + error_count++; +} + +// エラーメッセージを出力 + +void compiler::error(const std::string& m) +{ + std::cerr << m << std::endl; + error_count++; +} + +// 命令文の登録 + +// 代入文 +void compiler::AssignStatement(const yy::location& l, CAssign *assign) +{ + assign->analyze(this); + delete assign; +} + +// if文 +// +// if expr then +// A +// endif +// +// > push expr +// > jmp_nc L1 +// > A +// > L1: +// +// if expr then +// A +// else +// B +// endif +// +// > push expr +// > jmp_nc L1 +// > A +// > jmp L2 +// > L1: +// > B +// > L2: +// +void compiler::IfStatement(const yy::location& l, CNode *expr) +{ + expr->push(this); + int label = MakeLabel(); + OpJmpNC(label); // 偽の時の飛び先 + + state_stack.push(CState(l, STATE_IF, label)); + + delete expr; +} + +void compiler::ElseStatement(const yy::location& l) +{ + if (state_stack.empty() || state_stack.top().state_ != STATE_IF) { + error(l, "if文と対応していないelse文が有りました。"); + } + else { + CState &state = state_stack.top(); + int label = MakeLabel(); + OpJmp(label); + SetLabel(state.label1_); // 偽の時の飛び先をここにする + state.label1_ = label; // endifの飛び先を再設定 + } +} + +void compiler::EndifStatement(const yy::location& l) +{ + if (state_stack.empty() || state_stack.top().state_ != STATE_IF) { + error(l, "if文と対応していないendif文が有りました。"); + } + else { + CState &state = state_stack.top(); + SetLabel(state.label1_); // endifの飛び先をここにする + state_stack.pop(); // ステートスタックをpop + } +} + +// FOR文 +// +// for value=X to Y step Z +// A +// next +// +// > push X : value = X +// > pop value +// > L1: +// > A +// > push value : if (value == Y) goto L2 +// > push Y +// > eq +// > jmp_c L2 +// > push value : value = value + Z +// > push Z +// > add +// > pop value +// > jmp L1 +// > L2: +// +void compiler::ForStatement(const yy::location& l, CAssign *start, CNode *end, CNode *step) +{ + int label = MakeLabel(); + + start->analyze(this); + SetLabel(label); + + state_stack.push(CState(l, STATE_FOR, label, start, end, step)); +} + +void compiler::NextStatement(const yy::location& l) +{ + if (state_stack.empty() || state_stack.top().state_ != STATE_FOR) { + error(l, "for文と対応していないnext文が有りました。"); + } + else { + CState &state = state_stack.top(); + int label = MakeLabel(); + + // ループ終了のチェック + state.start_->push_value(this); + state.end_->push(this); + OpEq(); + OpJmpC(label); // 終了時飛び先 + + // カウンター増分 + state.start_->push_value(this); + if (state.step_) + state.step_->push(this); + else + PushConst(1); + + OpAdd(); + state.start_->pop_value(this); + + // ループ + OpJmp(state.label1_); + + // ループ終了 + SetLabel(label); + + // 後始末 + delete state.start_; + delete state.end_; + delete state.step_; + + state_stack.pop(); + } +} + +// while文 +// +// while (expr) A +// > L1: +// > push expr +// > jmp_nc L2 +// > A +// > jmp L1 +// > L2: +// +void compiler::WhileStatement(const yy::location& l, CNode *expr) +{ + int label1 = MakeLabel(); + int label2 = MakeLabel(); + + SetLabel(label1); + expr->push(this); + OpJmpNC(label2); + + state_stack.push(CState(l, STATE_WHILE, label1, label2)); + + delete expr; +} + +void compiler::WendStatement(const yy::location& l) +{ + if (state_stack.empty() || state_stack.top().state_ != STATE_WHILE) { + error(l, "while文と対応していないwend文が有りました。"); + } + else { + CState &state = state_stack.top(); + OpJmp(state.label1_); + SetLabel(state.label2_); + state_stack.pop(); + } +} + +// end文 +// +// > halt +// +void compiler::EndStatement(const yy::location& l) +{ + OpHalt(); +} + +// print文 +// +// print a, b, c +// +// > push c +// > push b +// > push a +// > print 3 +// +void compiler::PrintStatement(const yy::location& l, CArgs *args) +{ + int arg_count = 0; + if (args) { + args->for_each_rev(std::bind2nd(std::mem_fun(&CNode::push), this)); + arg_count = args->size(); + } + + OpPrint(arg_count); + + delete args; +} + +// ラベル生成 + +int compiler::MakeLabel() +{ + int index = (int)labels.size(); + labels.push_back(CLabel(index)); + return index; +} + +// ラベルのダミーコマンドをステートメントリストに登録する + +void compiler::SetLabel(int label) +{ + statement.push_back(CVMCode(VM_MAXCOMMAND, label)); +} + +// ラベル解決 +// +// 1.アドレスを生成する +// 2.ダミーのラベルコマンドが有ったアドレスを、ラベルテーブルに登録する +// 3.Jmpコマンドの飛び先をラベルテーブルに登録されたアドレスにする + +// note: +// GCCでは、関数オブジェクトを関数内に書けないので、ここに記述する。 +// VC++9.0(VS2008)では関数内に書くことで、スコープを封じ込める事が可能。 + +// アドレス計算関数オブジェクト +struct calc_addr { + std::vector &labels_; + int &pos_; + calc_addr(std::vector &labels, int &pos): labels_(labels), pos_(pos) + { + } + void operator()(const CVMCode &code) + { + if (code.op_ == VM_MAXCOMMAND) { // ラベルのダミーコマンド + labels_[code.arg1_].pos_ = pos_; + } + else { + pos_ += code.size_; + } + } +} ; + +// ジャンプアドレス設定関数オブジェクト +struct set_addr { + std::vector &labels_; + set_addr(std::vector &labels): labels_(labels) + { + } + void operator()(CVMCode &code) + { + switch (code.op_) { + case VM_JMP: + case VM_JMPC: + case VM_JMPNC: + code.arg1_ = labels_[code.arg1_].pos_; + break; + } + } +} ; + +int compiler::LabelSetting() +{ + // アドレス計算 + int pos = 0; + std::for_each(statement.begin(), statement.end(), calc_addr(labels, pos)); + // ジャンプアドレス設定 + std::for_each(statement.begin(), statement.end(), set_addr(labels)); + + return pos; +} + +// バイナリデータ生成 + +// 関数オブジェクト +struct copy_code { + unsigned char *p; + copy_code(unsigned char *code): p(code) + { + } + void operator()(const CVMCode &code) + { + p = code.Get(p); + } +} ; + +bool compiler::CraeteData(vm::data &data, int code_size) +{ + data.command_ = new unsigned char[code_size]; + data.command_size_ = code_size; + data.value_size_ = (int)variables.size(); + + std::for_each(statement.begin(), statement.end(), copy_code(data.command_)); + + return true; +} + +// デバッグダンプ +#ifdef _DEBUG +void compiler::debug_dump() +{ + std::cout << "---variables---" << std::endl; + variables.dump(); + + static const char *op_name[] = { +#define VM_NAMETABLE +#include "vm_code.h" +#undef VM_NAMETABLE + "LABEL", + } ; + std::cout << "---code---" << std::endl; + + int pos = 0; + size_t size = statement.size(); + for (size_t i=0; i < size; i++) { + std::cout << std::setw(6) << pos << ": " << op_name[statement[i].op_]; + if (statement[i].size_ > 1) { + std::cout << ", " << statement[i].arg1_; + } + std::cout << std::endl; + + if (statement[i].op_ != VM_MAXCOMMAND) { + pos += statement[i].size_; + } + } + std::cout << "---" << std::endl; +} +#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/compiler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/compiler.h Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,254 @@ +#ifndef __COMPILER_H__ +#define __COMPILER_H__ + +#include +#include "script-parser.hh" +#include "vm.h" +#include "node.h" + +// Forward declarations. +class compiler; + +// flexの関数宣言 +#define YY_DECL \ + yy::script_parser::token_type \ + yylex(yy::script_parser::semantic_type* yylval, \ + yy::script_parser::location_type* yylloc, \ + compiler& driver) + +YY_DECL; + +// 仮想マシンコード生成用 + +class CVMCode { + public: + CVMCode(unsigned char op) + : size_(1), op_(op), arg1_(0) + { + } + CVMCode(unsigned char op, int arg1) + : size_(5), op_(op), arg1_(arg1) + { + } + + unsigned char *Get(unsigned char *p) const + { + if (op_ != VM_MAXCOMMAND) { // ラベルのダミーコマンド + *p++ = op_; + if (size_ > 1) { + *(int *)p = arg1_; + p += 4; + } + } + return p; + } + + public: + unsigned char size_; + unsigned char op_; + int arg1_; +} ; + +// ラベル + +class CLabel { + public: + CLabel(int index) + : index_(index), pos_(0) + { + } + ~CLabel() + { + } + + public: + int index_; + int pos_; +} ; + +// 変数テーブル + +class CValueTag { + public: + CValueTag(): addr_(-1), size_(1) + { + } + CValueTag(int addr, int size) + : addr_(addr), size_(size) + { + } + + public: + int addr_; + int size_; +} ; + +class CValueTable { + private: + typedef std::map::iterator iter; + typedef std::map::const_iterator const_iter; + + public: + CValueTable(int start_addr=0): addr_(start_addr) + { + } + + bool add(const std::string &name, int size=1) + { + std::pair result = variables_.insert(make_pair(name, CValueTag(addr_, size))); + if (result.second) { + addr_ += size; + return true; + } + return false; + } + + const CValueTag *find(const std::string &name) const + { + const_iter it = variables_.find(name); + if (it != variables_.end()) + return &it->second; + return NULL; + } + + bool add_arg(const std::string &name, int addr) + { + std::pair result = variables_.insert(make_pair(name, CValueTag(addr, 1))); + return result.second; + } + + int size() const { return addr_; } + void clear() + { + variables_.clear(); + addr_ = 0; + } + +#ifdef _DEBUG + struct dump_action { + void operator()(const std::pair &it) + { + std::cout << it.first << ", addr = " << it.second.addr_ << ", size = " << it.second.size_ << std::endl; + } + } ; + + void dump() const + { + std::for_each(variables_.begin(), variables_.end(), dump_action()); + } +#endif + + private: + std::map variables_; + int addr_; +} ; + +// コンパイラ + +class compiler { + private: + enum STACK_STATE { + STATE_IF, + STATE_FOR, + STATE_WHILE, + } ; + + class CState { + public: + CState(const yy::location& l, int state, int label) + : l_(l), state_(state), label1_(label), label2_(0), start_(0), end_(0), step_(0) + { + } + CState(const yy::location& l, int state, int label1, int label2) + : l_(l), state_(state), label1_(label1), label2_(label2), start_(0), end_(0), step_(0) + { + } + CState(const yy::location& l, int state, int label, CAssign *start, CNode *end, CNode *step) + : l_(l), state_(state), label1_(label), label2_(0), start_(start), end_(end), step_(step) + { + } + + public: + yy::location l_; + int state_; + int label1_; + int label2_; + CAssign *start_; + CNode *end_; + CNode *step_; + } ; + + public: + compiler(); + virtual ~compiler(); + + std::string &get_filename() { return file; } + bool compile(const std::string &f, vm::data &data); +#ifdef _DEBUG + void debug_dump(); +#endif + + // 文 + // 代入文 + void AssignStatement(const yy::location& l, CAssign *assign); + // if文 + void IfStatement(const yy::location& l, CNode *expr); + void ElseStatement(const yy::location& l); + void EndifStatement(const yy::location& l); + // for文 + void ForStatement(const yy::location& l, CAssign *start, CNode *end, CNode *step); + void NextStatement(const yy::location& l); + // while文 + void WhileStatement(const yy::location& l, CNode *expr); + void WendStatement(const yy::location& l); + // end文 + void EndStatement(const yy::location& l); + // print文 + void PrintStatement(const yy::location& l, CArgs *args); + + const CValueTag *GetValueTag(const std::string &name) const + { + return variables.find(name); + } + + const CValueTag *AddValue(const std::string &name) + { + if (variables.add(name, 1)) { + return variables.find(name); + } + return NULL; + } + + // for code generator. +#define VM_CREATE +#include "vm_code.h" +#undef VM_CREATE + + int LabelSetting(); + + int MakeLabel(); + + void SetLabel(int label); + + bool CraeteData(vm::data &data, int code_size); + + // Error handling. + void error(const yy::location& l, const std::string& m); + void error(const std::string& m); + + private: + void scan_begin(); + void scan_end(); + + private: + CValueTable variables; + std::vector statement; + std::vector labels; + std::stack state_stack; + + int error_count; + + std::string file; +} ; + +#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/location.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/location.hh Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,145 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Locations for Bison parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/** + ** \file location.hh + ** Define the yy::location class. + */ + +#ifndef BISON_LOCATION_HH +# define BISON_LOCATION_HH + +# include +# include +# include "position.hh" + +namespace yy +{ + + /// Abstract a location. + class location + { + public: + + /// Construct a location. + location () + : begin (), end () + { + } + + + /// Initialization. + inline void initialize (std::string* fn) + { + begin.initialize (fn); + end = begin; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// Reset initial location to final location. + inline void step () + { + begin = end; + } + + /// Extend the current location to the COUNT next columns. + inline void columns (unsigned int count = 1) + { + end += count; + } + + /// Extend the current location to the COUNT next lines. + inline void lines (unsigned int count = 1) + { + end.lines (count); + } + /** \} */ + + + public: + /// Beginning of the located region. + position begin; + /// End of the located region. + position end; + }; + + /// Join two location objects to create a location. + inline const location operator+ (const location& begin, const location& end) + { + location res = begin; + res.end = end.end; + return res; + } + + /// Add two location objects. + inline const location operator+ (const location& begin, unsigned int width) + { + location res = begin; + res.columns (width); + return res; + } + + /// Add and assign a location. + inline location& operator+= (location& res, unsigned int width) + { + res.columns (width); + return res; + } + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param loc a reference to the location to redirect + ** + ** Avoid duplicate information. + */ + inline std::ostream& operator<< (std::ostream& ostr, const location& loc) + { + position last = loc.end - 1; + ostr << loc.begin; + if (last.filename + && (!loc.begin.filename + || *loc.begin.filename != *last.filename)) + ostr << '-' << last; + else if (loc.begin.line != last.line) + ostr << '-' << last.line << '.' << last.column; + else if (loc.begin.column != last.column) + ostr << '-' << last.column; + return ostr; + } + +} + +#endif // not BISON_LOCATION_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/node.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/node.cpp Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,213 @@ +#include +#include +#include +#include "node.h" +#include "compiler.h" +#include "script-parser.hh" + +// ノード生成 +// ただし、定数同士の計算は、leftノードに結果を代入し、それを返す + +CNode *CNode::MakeNode(compiler &c, const yy::location& l, int op, CNode *left, CNode *right) +{ + if (right == 0) { + switch (op) { + case OP_NEG: + if (left->op_ == OP_CONST) { // 定数演算を計算する + left->value_ = -left->value_; + return left; + } + break; + } + return new CNode(l, op, left); + } + + // 定数演算を計算する + if (left->op_ == OP_CONST && right->op_ == OP_CONST) { + switch (op) { + case OP_EQ: + left->value_ = (left->value_ == right->value_)? 1: 0; + break; + + case OP_NE: + left->value_ = (left->value_ != right->value_)? 1: 0; + break; + + case OP_GT: + left->value_ = (left->value_ > right->value_)? 1: 0; + break; + + case OP_GE: + left->value_ = (left->value_ >= right->value_)? 1: 0; + break; + + case OP_LT: + left->value_ = (left->value_ < right->value_)? 1: 0; + break; + + case OP_LE: + left->value_ = (left->value_ <= right->value_)? 1: 0; + break; + + case OP_MINUS: + left->value_ -= right->value_; + break; + + case OP_PLUS: + left->value_ += right->value_; + break; + + case OP_TIMES: + left->value_ *= right->value_; + break; + + case OP_DIVIDE: + if (right->value_ == 0) { + c.error(l, "定数計算を0で除算しました。"); + } + else { + left->value_ /= right->value_; + } + break; + + case OP_MOD: + if (right->value_ == 0) { + c.error(l, "定数計算を0で除算しました。"); + } + else { + left->value_ %= right->value_; + } + break; + + default: + return new CNode(l, op, left, right); + } + delete right; + return left; + } + return new CNode(l, op, left, right); +} + +void CNode::push(compiler *c) const +{ + switch (op_) { + case OP_NEG: + left_->push(c); + c->OpNeg(); + return; + + case OP_RANDFUNC: + left_->push(c); + c->OpRand(); + return; + + case OP_CONST: + c->PushConst(value_); + return; + } + + left_->push(c); + right_->push(c); + + // 整数計算ノードの処理 + switch (op_) { + case OP_EQ: + c->OpEq(); + break; + + case OP_NE: + c->OpNe(); + break; + + case OP_GT: + c->OpGt(); + break; + + case OP_GE: + c->OpGe(); + break; + + case OP_LT: + c->OpLt(); + break; + + case OP_LE: + c->OpLe(); + break; + + case OP_MINUS: + c->OpSub(); + break; + + case OP_PLUS: + c->OpAdd(); + break; + + case OP_TIMES: + c->OpMul(); + break; + + case OP_DIVIDE: + c->OpDiv(); + break; + + case OP_MOD: + c->OpMod(); + break; + + default: + c->error(l_, "内部エラー:処理できない計算ノードがありました。"); + break; + } +} + +void CNode::pop(compiler *c) const +{ + c->error(l_, "内部エラー:計算ノードをpopしています。"); +} + +void CValueNode::push(compiler *c) const +{ + if (op_ != OP_VALUE) { + c->error(l_, "内部エラー:変数ノードに変数以外が登録されています。"); + } + else { + const CValueTag *tag = c->GetValueTag(*string_); + if (tag == 0) { + c->error(l_, "変数 " + *string_ + " は定義されていません。"); + } + else { + c->PushValue(tag->addr_); + } + } +} + +void CValueNode::pop(compiler *c) const +{ + if (op_ != OP_VALUE) { + c->error(l_, "内部エラー:変数ノードに変数以外が登録されています。"); + } + else { + const CValueTag *tag = c->GetValueTag(*string_); + if (tag == 0) { + tag = c->AddValue(*string_); + } + if (tag == 0) { + c->error(l_, "変数 " + *string_ + " が定義できません。"); + } + else { + c->PopValue(tag->addr_); + } + } +} + +// 代入命令を生成 +// +// > push b +// > pop a +// +void CAssign::analyze(compiler *c) +{ + expr_->push(c); + value_->pop(c); +} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/node.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/node.h Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,181 @@ +#ifndef __NODE_H__ +#define __NODE_H__ + +#include +#include +#include +#include +#include +#include "location.hh" +#include "vm.h" + +class compiler; +class CNode; +class CValueNode; +class CArgDef; + +// 配列 + +template +class CNodeList { + struct delete_object { + void operator()(T *ptr){ delete ptr; } + } ; + + public: + CNodeList(const yy::location& l, T *node) + { + args.push_back(node); + } + ~CNodeList() + { + std::for_each(args.begin(), args.end(), delete_object()); + } + + CNodeList *Add(const yy::location& l, T *add) + { + args.push_back(add); + return this; + } + + template + void for_each(const Fn &func) + { + std::for_each(args.begin(), args.end(), func); + } + + template + void for_each_rev(const Fn &func) + { + std::for_each(args.rbegin(), args.rend(), func); + } + + void analyze(compiler *c) + { + std::for_each(args.begin(), args.end(), std::bind2nd(std::mem_fun(&T::analyze), c)); + } + + size_t size() const { return args.size(); } + T *get(size_t idx) { return args[idx]; } + T *operator[](size_t idx) { return args[idx]; } + const T *get(size_t idx) const { return args[idx]; } + const T *operator[](size_t idx) const { return args[idx]; } + + private: + std::vector args; +} ; + +typedef CNodeList CArgs; + +// ノードの命令 +enum { + OP_NEG, + OP_PLUS, + OP_MINUS, + OP_TIMES, + OP_DIVIDE, + OP_MOD, + OP_EQ, + OP_NE, + OP_GT, + OP_GE, + OP_LT, + OP_LE, + OP_VALUE, + OP_CONST, + OP_RANDFUNC, +} ; + +// ノード + +class CNode { + public: + CNode(const yy::location& l, int op, CNode *left, CNode *right=0) + : l_(l), op_(op), left_(left), right_(right), value_(0), string_(0) + { + } + CNode(const yy::location& l, int op, int value) + : l_(l), op_(op), left_(0), right_(0), value_(value), string_(0) + { + } + CNode(const yy::location& l, int op, std::string *str) + : l_(l), op_(op), left_(0), right_(0), value_(0), string_(str) + { + } + CNode(const yy::location& l, int op, std::string *str, CNode *node) + : l_(l), op_(op), left_(node), right_(0), value_(0), string_(str) + { + } + virtual ~CNode() + { + delete left_; + delete right_; + delete string_; + } + + virtual void push(compiler *c) const; + virtual void pop(compiler *c) const; + + const yy::location &location() const { return l_; } + int op() const { return op_; } + int value() const { return value_; } + const std::string &string() const { return *string_; } + const CNode *left() const { return left_; } + const CNode *right() const { return right_; } + + static CNode *MakeNode(compiler &c, const yy::location& l, int op, CNode *left, CNode *right=0); + + protected: + const yy::location l_; + int op_; + int value_; + std::string *string_; + CNode *left_; + CNode *right_; +} ; + +// 変数ノード + +class CValueNode: public CNode { + public: + CValueNode(const yy::location& l, std::string *name, CNode *node=NULL) + : CNode(l, OP_VALUE, name, node) + { + } + + void push(compiler *c) const; + void pop(compiler *c) const; +} ; + +// 代入文用 + +class CAssign { + public: + CAssign(const yy::location& l, int op, CNode *value, CNode *expr) + : l_(l), op_(op), value_(value), expr_(expr) + { + } + ~CAssign() + { + delete value_; + delete expr_; + } + + void analyze(compiler *c); + void push_value(compiler *c) + { + value_->push(c); + } + void pop_value(compiler *c) + { + value_->pop(c); + } + + private: + const yy::location l_; + int op_; + CNode *value_; + CNode *expr_; +} ; + +#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/position.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/position.hh Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,142 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Positions for Bison parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/** + ** \file position.hh + ** Define the yy::position class. + */ + +#ifndef BISON_POSITION_HH +# define BISON_POSITION_HH + +# include +# include + +namespace yy +{ + /// Abstract a position. + class position + { + public: + + /// Construct a position. + position () + : filename (0), line (1), column (0) + { + } + + + /// Initialization. + inline void initialize (std::string* fn) + { + filename = fn; + line = 1; + column = 0; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// (line related) Advance to the COUNT next lines. + inline void lines (int count = 1) + { + column = 0; + line += count; + } + + /// (column related) Advance to the COUNT next columns. + inline void columns (int count = 1) + { + int leftmost = 0; + int current = column; + if (leftmost <= current + count) + column += count; + else + column = 0; + } + /** \} */ + + public: + /// File name to which this position refers. + std::string* filename; + /// Current line number. + unsigned int line; + /// Current column number. + unsigned int column; + }; + + /// Add and assign a position. + inline const position& + operator+= (position& res, const int width) + { + res.columns (width); + return res; + } + + /// Add two position objects. + inline const position + operator+ (const position& begin, const int width) + { + position res = begin; + return res += width; + } + + /// Add and assign a position. + inline const position& + operator-= (position& res, const int width) + { + return res += -width; + } + + /// Add two position objects. + inline const position + operator- (const position& begin, const int width) + { + return begin + -width; + } + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param pos a reference to the position to redirect + */ + inline std::ostream& + operator<< (std::ostream& ostr, const position& pos) + { + if (pos.filename) + ostr << *pos.filename << ':'; + return ostr << pos.line << '.' << pos.column; + } + +} +#endif // not BISON_POSITION_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script Binary file Bison-Flex/BasicCompiler-StackBase/script has changed diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-parser.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-parser.cc Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,1070 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton implementation for Bison LALR(1) parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +#include "script-parser.hh" + +/* User implementation prologue. */ +#line 36 "script-parser.yy" + +#include "compiler.h" + + +/* Line 317 of lalr1.cc. */ +#line 46 "script-parser.cc" + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include /* FIXME: INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#define YYUSE(e) ((void) (e)) + +/* A pseudo ostream that takes yydebug_ into account. */ +# define YYCDEBUG \ + for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ + (*yycdebug_) + +/* Enable debugging if requested. */ +#if YYDEBUG + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_symbol_print_ ((Type), (Value), (Location)); \ + *yycdebug_ << std::endl; \ + } \ +} while (false) + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug_) \ + yy_reduce_print_ (Rule); \ +} while (false) + +# define YY_STACK_PRINT() \ +do { \ + if (yydebug_) \ + yystack_print_ (); \ +} while (false) + +#else /* !YYDEBUG */ + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_REDUCE_PRINT(Rule) +# define YY_STACK_PRINT() + +#endif /* !YYDEBUG */ + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + +namespace yy +{ +#if YYERROR_VERBOSE + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + script_parser::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr = ""; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + +#endif + + /// Build a parser object. + script_parser::script_parser (compiler& driver_yyarg) + : yydebug_ (false), + yycdebug_ (&std::cerr), + driver (driver_yyarg) + { + } + + script_parser::~script_parser () + { + } + +#if YYDEBUG + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + inline void + script_parser::yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yyvaluep); + switch (yytype) + { + default: + break; + } + } + + + void + script_parser::yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") + << ' ' << yytname_[yytype] << " (" + << *yylocationp << ": "; + yy_symbol_value_print_ (yytype, yyvaluep, yylocationp); + *yycdebug_ << ')'; + } +#endif /* ! YYDEBUG */ + + void + script_parser::yydestruct_ (const char* yymsg, + int yytype, semantic_type* yyvaluep, location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yymsg); + YYUSE (yyvaluep); + + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + case 4: /* "\"identifier\"" */ +#line 68 "script-parser.yy" + { delete (yyvaluep->sval); }; +#line 206 "script-parser.cc" + break; + case 39: /* "assign" */ +#line 71 "script-parser.yy" + { delete (yyvaluep->assign); }; +#line 211 "script-parser.cc" + break; + case 40: /* "comp_expr" */ +#line 74 "script-parser.yy" + { delete (yyvaluep->expr); }; +#line 216 "script-parser.cc" + break; + case 41: /* "expr" */ +#line 73 "script-parser.yy" + { delete (yyvaluep->expr); }; +#line 221 "script-parser.cc" + break; + case 42: /* "value" */ +#line 72 "script-parser.yy" + { delete (yyvaluep->expr); }; +#line 226 "script-parser.cc" + break; + case 43: /* "args" */ +#line 70 "script-parser.yy" + { delete (yyvaluep->args); }; +#line 231 "script-parser.cc" + break; + + default: + break; + } + } + + void + script_parser::yypop_ (unsigned int n) + { + yystate_stack_.pop (n); + yysemantic_stack_.pop (n); + yylocation_stack_.pop (n); + } + + std::ostream& + script_parser::debug_stream () const + { + return *yycdebug_; + } + + void + script_parser::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + script_parser::debug_level_type + script_parser::debug_level () const + { + return yydebug_; + } + + void + script_parser::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } + + + int + script_parser::parse () + { + /// Look-ahead and look-ahead in internal form. + int yychar = yyempty_; + int yytoken = 0; + + /* State. */ + int yyn; + int yylen = 0; + int yystate = 0; + + /* Error handling. */ + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// Semantic value of the look-ahead. + semantic_type yylval; + /// Location of the look-ahead. + location_type yylloc; + /// The locations where the error started and ended. + location yyerror_range[2]; + + /// $$. + semantic_type yyval; + /// @$. + location_type yyloc; + + int yyresult; + + YYCDEBUG << "Starting parse" << std::endl; + + + /* User initialization code. */ + #line 20 "script-parser.yy" +{ + // ロケーション初期化 + yylloc.begin.filename = yylloc.end.filename = &driver.get_filename(); +} + /* Line 547 of yacc.c. */ +#line 313 "script-parser.cc" + /* Initialize the stacks. The initial state will be pushed in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystate_stack_ = state_stack_type (0); + yysemantic_stack_ = semantic_stack_type (0); + yylocation_stack_ = location_stack_type (0); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* New state. */ + yynewstate: + yystate_stack_.push (yystate); + YYCDEBUG << "Entering state " << yystate << std::endl; + goto yybackup; + + /* Backup. */ + yybackup: + + /* Try to take a decision without look-ahead. */ + yyn = yypact_[yystate]; + if (yyn == yypact_ninf_) + goto yydefault; + + /* Read a look-ahead token. */ + if (yychar == yyempty_) + { + YYCDEBUG << "Reading a token: "; + yychar = yylex (&yylval, &yylloc, driver); + } + + + /* Convert token to internal form. */ + if (yychar <= yyeof_) + { + yychar = yytoken = yyeof_; + YYCDEBUG << "Now at end of input." << std::endl; + } + else + { + yytoken = yytranslate_ (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) + goto yydefault; + + /* Reduce or error. */ + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == yytable_ninf_) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Accept? */ + if (yyn == yyfinal_) + goto yyacceptlab; + + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != yyeof_) + yychar = yyempty_; + + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus_) + --yyerrstatus_; + + yystate = yyn; + goto yynewstate; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen) + yyval = yysemantic_stack_[yylen - 1]; + else + yyval = yysemantic_stack_[0]; + + { + slice slice (yylocation_stack_, yylen); + YYLLOC_DEFAULT (yyloc, slice, yylen); + } + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 6: +#line 90 "script-parser.yy" + { driver.EndStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 7: +#line 91 "script-parser.yy" + { driver.AssignStatement((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].assign)); ;} + break; + + case 8: +#line 92 "script-parser.yy" + { driver.IfStatement((yylocation_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (2)].expr)); ;} + break; + + case 9: +#line 93 "script-parser.yy" + { driver.ElseStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 10: +#line 94 "script-parser.yy" + { driver.EndifStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 11: +#line 95 "script-parser.yy" + { driver.ForStatement((yylocation_stack_[(6) - (1)]), (yysemantic_stack_[(6) - (2)].assign), (yysemantic_stack_[(6) - (4)].expr), (yysemantic_stack_[(6) - (6)].expr)); ;} + break; + + case 12: +#line 96 "script-parser.yy" + { driver.ForStatement((yylocation_stack_[(4) - (1)]), (yysemantic_stack_[(4) - (2)].assign), (yysemantic_stack_[(4) - (4)].expr), NULL); ;} + break; + + case 13: +#line 97 "script-parser.yy" + { driver.NextStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 14: +#line 98 "script-parser.yy" + { driver.WhileStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].expr)); ;} + break; + + case 15: +#line 99 "script-parser.yy" + { driver.WendStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 16: +#line 100 "script-parser.yy" + { driver.PrintStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].args)); ;} + break; + + case 18: +#line 104 "script-parser.yy" + { (yyval.assign) = new CAssign((yylocation_stack_[(3) - (1)]), '=', (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 19: +#line 107 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_EQ, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 20: +#line 108 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_NE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 21: +#line 109 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 22: +#line 110 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 23: +#line 111 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 24: +#line 112 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 25: +#line 115 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MINUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 26: +#line 116 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_PLUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 27: +#line 117 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_TIMES, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 28: +#line 118 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_DIVIDE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 29: +#line 119 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MOD, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 30: +#line 120 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(2) - (1)]), OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;} + break; + + case 31: +#line 121 "script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;} + break; + + case 32: +#line 122 "script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(1) - (1)].expr); ;} + break; + + case 33: +#line 123 "script-parser.yy" + { (yyval.expr) = new CNode((yylocation_stack_[(1) - (1)]), OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;} + break; + + case 34: +#line 124 "script-parser.yy" + { (yyval.expr) = new CNode((yylocation_stack_[(4) - (1)]), OP_RANDFUNC, (yysemantic_stack_[(4) - (3)].expr)); ;} + break; + + case 35: +#line 127 "script-parser.yy" + { (yyval.expr) = new CValueNode((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].sval)); ;} + break; + + case 36: +#line 130 "script-parser.yy" + { (yyval.args) = new CArgs((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].expr)); ;} + break; + + case 37: +#line 131 "script-parser.yy" + { (yyval.args) = (yysemantic_stack_[(3) - (1)].args)->Add((yylocation_stack_[(3) - (3)]), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + + /* Line 675 of lalr1.cc. */ +#line 585 "script-parser.cc" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); + + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + + yysemantic_stack_.push (yyval); + yylocation_stack_.push (yyloc); + + /* Shift the result of the reduction. */ + yyn = yyr1_[yyn]; + yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0]; + if (0 <= yystate && yystate <= yylast_ + && yycheck_[yystate] == yystate_stack_[0]) + yystate = yytable_[yystate]; + else + yystate = yydefgoto_[yyn - yyntokens_]; + goto yynewstate; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus_) + { + ++yynerrs_; + error (yylloc, yysyntax_error_ (yystate, yytoken)); + } + + yyerror_range[0] = yylloc; + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse look-ahead token after an + error, discard it. */ + + if (yychar <= yyeof_) + { + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + } + else + { + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; + } + } + + /* Else will try to reuse look-ahead token after shifting the error + token. */ + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (false) + goto yyerrorlab; + + yyerror_range[0] = yylocation_stack_[yylen - 1]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + yystate = yystate_stack_[0]; + goto yyerrlab1; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact_[yystate]; + if (yyn != yypact_ninf_) + { + yyn += yyterror_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystate_stack_.height () == 1) + YYABORT; + + yyerror_range[0] = yylocation_stack_[0]; + yydestruct_ ("Error: popping", + yystos_[yystate], + &yysemantic_stack_[0], &yylocation_stack_[0]); + yypop_ (); + yystate = yystate_stack_[0]; + YY_STACK_PRINT (); + } + + if (yyn == yyfinal_) + goto yyacceptlab; + + yyerror_range[1] = yylloc; + // Using YYLLOC is tempting, but would change the location of + // the look-ahead. YYLOC is available though. + YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yyloc); + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], + &yysemantic_stack_[0], &yylocation_stack_[0]); + + yystate = yyn; + goto yynewstate; + + /* Accept. */ + yyacceptlab: + yyresult = 0; + goto yyreturn; + + /* Abort. */ + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyreturn: + if (yychar != yyeof_ && yychar != yyempty_) + yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); + + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + while (yystate_stack_.height () != 1) + { + yydestruct_ ("Cleanup: popping", + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); + } + + return yyresult; + } + + // Generate an error message. + std::string + script_parser::yysyntax_error_ (int yystate, int tok) + { + std::string res; + YYUSE (yystate); +#if YYERROR_VERBOSE + int yyn = yypact_[yystate]; + if (yypact_ninf_ < yyn && yyn <= yylast_) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + ++count; + + // FIXME: This method of building the message is not compatible + // with internationalization. It should work like yacc.c does it. + // That is, first build a string that looks like this: + // "syntax error, unexpected %s or %s or %s" + // Then, invoke YY_ on this string. + // Finally, use the string as a format to output + // yytname_[tok], etc. + // Until this gets fixed, this message appears in English only. + res = "syntax error, unexpected "; + res += yytnamerr_ (yytname_[tok]); + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + { + res += (!count++) ? ", expecting " : " or "; + res += yytnamerr_ (yytname_[x]); + } + } + } + else +#endif + res = YY_("syntax error"); + return res; + } + + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + const signed char script_parser::yypact_ninf_ = -23; + const signed char + script_parser::yypact_[] = + { + 85, -23, -23, -23, 19, -23, -23, -3, -23, 19, + -23, -23, 19, 66, -23, -7, -23, -22, -23, -14, + 19, 19, 8, 38, -23, 9, -23, 103, 4, -23, + -23, -23, 19, 19, -23, 86, -23, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 103, 91, -23, 103, 103, 103, 103, -20, -20, -23, + -23, -23, 103, 103, -11, 103, -23, 19, 103 + }; + + /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE + doesn't specify something else to do. Zero means the default is an + error. */ + const unsigned char + script_parser::yydefact_[] = + { + 0, 17, 35, 5, 0, 9, 10, 0, 13, 0, + 15, 6, 0, 0, 2, 0, 7, 0, 33, 0, + 0, 0, 0, 0, 32, 0, 14, 36, 16, 1, + 3, 4, 0, 0, 30, 0, 8, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 18, 0, 31, 19, 20, 22, 24, 26, 25, 27, + 28, 29, 21, 23, 12, 37, 34, 0, 11 + }; + + /* YYPGOTO[NTERM-NUM]. */ + const signed char + script_parser::yypgoto_[] = + { + -23, -23, 27, -23, 34, 39, -12, 3, -23 + }; + + /* YYDEFGOTO[NTERM-NUM]. */ + const signed char + script_parser::yydefgoto_[] = + { + -1, 13, 14, 15, 16, 22, 23, 24, 28 + }; + + /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. */ + const signed char script_parser::yytable_ninf_ = -1; + const unsigned char + script_parser::yytable_[] = + { + 27, 2, 31, 17, 43, 44, 45, 32, 34, 35, + 17, 41, 42, 43, 44, 45, 17, 67, 33, 36, + 50, 51, 18, 2, 48, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 49, 19, + 30, 25, 20, 37, 38, 39, 40, 0, 26, 0, + 0, 21, 0, 0, 0, 68, 0, 0, 0, 0, + 41, 42, 43, 44, 45, 0, 29, 1, 46, 47, + 2, 0, 0, 0, 0, 3, 4, 0, 5, 6, + 7, 0, 8, 9, 10, 11, 1, 12, 0, 2, + 0, 0, 0, 0, 3, 4, 0, 5, 6, 7, + 0, 8, 9, 10, 11, 0, 12, 0, 41, 42, + 43, 44, 45, 41, 42, 43, 44, 45, 0, 52, + 0, 0, 0, 0, 66, 41, 42, 43, 44, 45 + }; + + /* YYCHECK. */ + const signed char + script_parser::yycheck_[] = + { + 12, 4, 9, 0, 24, 25, 26, 29, 20, 21, + 7, 22, 23, 24, 25, 26, 13, 28, 32, 11, + 32, 33, 3, 4, 15, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 34, 20, + 13, 7, 23, 5, 6, 7, 8, -1, 9, -1, + -1, 32, -1, -1, -1, 67, -1, -1, -1, -1, + 22, 23, 24, 25, 26, -1, 0, 1, 30, 31, + 4, -1, -1, -1, -1, 9, 10, -1, 12, 13, + 14, -1, 16, 17, 18, 19, 1, 21, -1, 4, + -1, -1, -1, -1, 9, 10, -1, 12, 13, 14, + -1, 16, 17, 18, 19, -1, 21, -1, 22, 23, + 24, 25, 26, 22, 23, 24, 25, 26, -1, 33, + -1, -1, -1, -1, 33, 22, 23, 24, 25, 26 + }; + + /* STOS_[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ + const unsigned char + script_parser::yystos_[] = + { + 0, 1, 4, 9, 10, 12, 13, 14, 16, 17, + 18, 19, 21, 36, 37, 38, 39, 42, 3, 20, + 23, 32, 40, 41, 42, 39, 40, 41, 43, 0, + 37, 9, 29, 32, 41, 41, 11, 5, 6, 7, + 8, 22, 23, 24, 25, 26, 30, 31, 15, 34, + 41, 41, 33, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 33, 28, 41 + }; + +#if YYDEBUG + /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding + to YYLEX-NUM. */ + const unsigned short int + script_parser::yytoken_number_[] = + { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 43, 45, 42, 47, 37, 277, 278, 61, + 62, 60, 40, 41, 44 + }; +#endif + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ + const unsigned char + script_parser::yyr1_[] = + { + 0, 35, 36, 36, 37, 37, 38, 38, 38, 38, + 38, 38, 38, 38, 38, 38, 38, 38, 39, 40, + 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 42, 43, 43 + }; + + /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ + const unsigned char + script_parser::yyr2_[] = + { + 0, 2, 1, 2, 2, 1, 1, 1, 3, 1, + 1, 6, 4, 1, 2, 1, 2, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 3, 1, 1, 4, 1, 1, 3 + }; + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a yyntokens_, nonterminals. */ + const char* + const script_parser::yytname_[] = + { + "\"end of file\"", "error", "$undefined", "\"ival\"", "\"identifier\"", + "\"==\"", "\"!=\"", "\">=\"", "\"<=\"", "\"\\n\"", "\"if\"", "\"then\"", + "\"else\"", "\"endif\"", "\"for\"", "\"to\"", "\"next\"", "\"while\"", + "\"wend\"", "\"end\"", "\"rand\"", "\"print\"", "'+'", "'-'", "'*'", + "'/'", "'%'", "NEG", "\"step\"", "'='", "'>'", "'<'", "'('", "')'", + "','", "$accept", "unit", "states", "statement", "assign", "comp_expr", + "expr", "value", "args", 0 + }; +#endif + +#if YYDEBUG + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ + const script_parser::rhs_number_type + script_parser::yyrhs_[] = + { + 36, 0, -1, 37, -1, 36, 37, -1, 38, 9, + -1, 9, -1, 19, -1, 39, -1, 10, 40, 11, + -1, 12, -1, 13, -1, 14, 39, 15, 41, 28, + 41, -1, 14, 39, 15, 41, -1, 16, -1, 17, + 40, -1, 18, -1, 21, 43, -1, 1, -1, 42, + 29, 41, -1, 41, 5, 41, -1, 41, 6, 41, + -1, 41, 30, 41, -1, 41, 7, 41, -1, 41, + 31, 41, -1, 41, 8, 41, -1, 41, 23, 41, + -1, 41, 22, 41, -1, 41, 24, 41, -1, 41, + 25, 41, -1, 41, 26, 41, -1, 23, 41, -1, + 32, 41, 33, -1, 42, -1, 3, -1, 20, 32, + 41, 33, -1, 4, -1, 41, -1, 43, 34, 41, + -1 + }; + + /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ + const unsigned char + script_parser::yyprhs_[] = + { + 0, 0, 3, 5, 8, 11, 13, 15, 17, 21, + 23, 25, 32, 37, 39, 42, 44, 47, 49, 53, + 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, + 97, 100, 104, 106, 108, 113, 115, 117 + }; + + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + const unsigned char + script_parser::yyrline_[] = + { + 0, 82, 82, 83, 86, 87, 90, 91, 92, 93, + 94, 95, 96, 97, 98, 99, 100, 101, 104, 107, + 108, 109, 110, 111, 112, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 127, 130, 131 + }; + + // Print the state stack on the debug stream. + void + script_parser::yystack_print_ () + { + *yycdebug_ << "Stack now"; + for (state_stack_type::const_iterator i = yystate_stack_.begin (); + i != yystate_stack_.end (); ++i) + *yycdebug_ << ' ' << *i; + *yycdebug_ << std::endl; + } + + // Report on the debug stream that the rule \a yyrule is going to be reduced. + void + script_parser::yy_reduce_print_ (int yyrule) + { + unsigned int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 + << " (line " << yylno << "), "; + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + yyrhs_[yyprhs_[yyrule] + yyi], + &(yysemantic_stack_[(yynrhs) - (yyi + 1)]), + &(yylocation_stack_[(yynrhs) - (yyi + 1)])); + } +#endif // YYDEBUG + + /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + script_parser::token_number_type + script_parser::yytranslate_ (int t) + { + static + const token_number_type + translate_table[] = + { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 26, 2, 2, + 32, 33, 24, 22, 34, 23, 2, 25, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 31, 29, 30, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 27, 28 + }; + if ((unsigned int) t <= yyuser_token_number_max_) + return translate_table[t]; + else + return yyundef_token_; + } + + const int script_parser::yyeof_ = 0; + const int script_parser::yylast_ = 129; + const int script_parser::yynnts_ = 9; + const int script_parser::yyempty_ = -2; + const int script_parser::yyfinal_ = 29; + const int script_parser::yyterror_ = 1; + const int script_parser::yyerrcode_ = 256; + const int script_parser::yyntokens_ = 35; + + const unsigned int script_parser::yyuser_token_number_max_ = 278; + const script_parser::token_number_type script_parser::yyundef_token_ = 2; + +} // namespace yy + +#line 134 "script-parser.yy" + +void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) +{ + driver.error(l, m); +} + diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-parser.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-parser.hh Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,329 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton interface for Bison LALR(1) parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C++ LALR(1) parser skeleton written by Akim Demaille. */ + +#ifndef PARSER_HEADER_H +# define PARSER_HEADER_H + +#include +#include +#include "stack.hh" + +namespace yy +{ + class position; + class location; +} + +/* First part of user declarations. */ +#line 4 "script-parser.yy" + +#ifdef _MSC_VER +#pragma warning(disable: 4800) +#pragma warning(disable: 4267) +#endif + +#include +#include "node.h" +class compiler; + + +/* Line 35 of lalr1.cc. */ +#line 65 "script-parser.hh" + +#include "location.hh" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ +do { \ + if (N) \ + { \ + (Current).begin = (Rhs)[1].begin; \ + (Current).end = (Rhs)[N].end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = (Rhs)[0].end; \ + } \ +} while (false) +#endif + +namespace yy +{ + + /// A Bison parser. + class script_parser + { + public: + /// Symbol semantic values. +#ifndef YYSTYPE + union semantic_type +#line 28 "script-parser.yy" +{ + int ival; + std::string *sval; + + CArgs *args; + CNode *expr; + CAssign *assign; +} +/* Line 35 of lalr1.cc. */ +#line 126 "script-parser.hh" + ; +#else + typedef YYSTYPE semantic_type; +#endif + /// Symbol locations. + typedef location location_type; + /// Tokens. + struct token + { + /* Tokens. */ + enum yytokentype { + END_OF_FILE = 0, + TK_IVAL = 258, + TK_IDENTIFIER = 259, + TK_EQ = 260, + TK_NE = 261, + TK_GE = 262, + TK_LE = 263, + TK_NEWLINE = 264, + TK_IF = 265, + TK_THEN = 266, + TK_ELSE = 267, + TK_ENDIF = 268, + TK_FOR = 269, + TK_TO = 270, + TK_NEXT = 271, + TK_WHILE = 272, + TK_WEND = 273, + TK_END = 274, + TK_RAND = 275, + TK_PRINT = 276, + NEG = 277 + }; + + }; + /// Token type. + typedef token::yytokentype token_type; + + /// Build a parser object. + script_parser (compiler& driver_yyarg); + virtual ~script_parser (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); + + private: + /// Report a syntax error. + /// \param loc where the syntax error is found. + /// \param msg a description of the syntax error. + virtual void error (const location_type& loc, const std::string& msg); + + /// Generate an error message. + /// \param state the state where the error occurred. + /// \param tok the look-ahead token. + virtual std::string yysyntax_error_ (int yystate, int tok); + +#if YYDEBUG + /// \brief Report a symbol value on the debug stream. + /// \param yytype The token type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + virtual void yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); + /// \brief Report a symbol on the debug stream. + /// \param yytype The token type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + virtual void yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); +#endif /* ! YYDEBUG */ + + + /// State numbers. + typedef int state_type; + /// State stack type. + typedef stack state_stack_type; + /// Semantic value stack type. + typedef stack semantic_stack_type; + /// location stack type. + typedef stack location_stack_type; + + /// The state stack. + state_stack_type yystate_stack_; + /// The semantic value stack. + semantic_stack_type yysemantic_stack_; + /// The location stack. + location_stack_type yylocation_stack_; + + /// Internal symbol numbers. + typedef unsigned char token_number_type; + /* Tables. */ + /// For a state, the index in \a yytable_ of its portion. + static const signed char yypact_[]; + static const signed char yypact_ninf_; + + /// For a state, default rule to reduce. + /// Unless\a yytable_ specifies something else to do. + /// Zero means the default is an error. + static const unsigned char yydefact_[]; + + static const signed char yypgoto_[]; + static const signed char yydefgoto_[]; + + /// What to do in a state. + /// \a yytable_[yypact_[s]]: what to do in state \a s. + /// - if positive, shift that token. + /// - if negative, reduce the rule which number is the opposite. + /// - if zero, do what YYDEFACT says. + static const unsigned char yytable_[]; + static const signed char yytable_ninf_; + + static const signed char yycheck_[]; + + /// For a state, its accessing symbol. + static const unsigned char yystos_[]; + + /// For a rule, its LHS. + static const unsigned char yyr1_[]; + /// For a rule, its RHS length. + static const unsigned char yyr2_[]; + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif + +#if YYERROR_VERBOSE + /// Convert the symbol name \a n to a form suitable for a diagnostic. + virtual std::string yytnamerr_ (const char *n); +#endif + +#if YYDEBUG + /// A type to store symbol numbers and -1. + typedef signed char rhs_number_type; + /// A `-1'-separated list of the rules' RHS. + static const rhs_number_type yyrhs_[]; + /// For each rule, the index of the first RHS symbol in \a yyrhs_. + static const unsigned char yyprhs_[]; + /// For each rule, its source line number. + static const unsigned char yyrline_[]; + /// For each scanner token number, its symbol number. + static const unsigned short int yytoken_number_[]; + /// Report on the debug stream that the rule \a r is going to be reduced. + virtual void yy_reduce_print_ (int r); + /// Print the state stack on the debug stream. + virtual void yystack_print_ (); +#endif + + /// Convert a scanner token number \a t to a symbol number. + token_number_type yytranslate_ (int t); + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// \param yytype The symbol type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + inline void yydestruct_ (const char* yymsg, + int yytype, + semantic_type* yyvaluep, + location_type* yylocationp); + + /// Pop \a n symbols the three stacks. + inline void yypop_ (unsigned int n = 1); + + /* Constants. */ + static const int yyeof_; + /* LAST_ -- Last index in TABLE_. */ + static const int yylast_; + static const int yynnts_; + static const int yyempty_; + static const int yyfinal_; + static const int yyterror_; + static const int yyerrcode_; + static const int yyntokens_; + static const unsigned int yyuser_token_number_max_; + static const token_number_type yyundef_token_; + + /* Debugging. */ + int yydebug_; + std::ostream* yycdebug_; + + + /* User arguments. */ + compiler& driver; + }; +} + + +#endif /* ! defined PARSER_HEADER_H */ diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-parser.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-parser.output Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,1303 @@ +文法 + + 0 $accept: unit "end of file" + + 1 unit: states + 2 | unit states + + 3 states: statement "\n" + 4 | "\n" + + 5 statement: "end" + 6 | assign + 7 | "if" comp_expr "then" + 8 | "else" + 9 | "endif" + 10 | "for" assign "to" expr "step" expr + 11 | "for" assign "to" expr + 12 | "next" + 13 | "while" comp_expr + 14 | "wend" + 15 | "print" args + 16 | error + + 17 assign: value '=' expr + + 18 comp_expr: expr "==" expr + 19 | expr "!=" expr + 20 | expr '>' expr + 21 | expr ">=" expr + 22 | expr '<' expr + 23 | expr "<=" expr + + 24 expr: expr '-' expr + 25 | expr '+' expr + 26 | expr '*' expr + 27 | expr '/' expr + 28 | expr '%' expr + 29 | '-' expr + 30 | '(' expr ')' + 31 | value + 32 | "ival" + 33 | "rand" '(' expr ')' + + 34 value: "identifier" + + 35 args: expr + 36 | args ',' expr + + +出現位置の規則による終端 + +"end of file" (0) 0 +'%' (37) 28 +'(' (40) 30 33 +')' (41) 30 33 +'*' (42) 26 +'+' (43) 25 +',' (44) 36 +'-' (45) 24 29 +'/' (47) 27 +'<' (60) 22 +'=' (61) 17 +'>' (62) 20 +error (256) 16 +"ival" (258) 32 +"identifier" (259) 34 +"==" (260) 18 +"!=" (261) 19 +">=" (262) 21 +"<=" (263) 23 +"\n" (264) 3 4 +"if" (265) 7 +"then" (266) 7 +"else" (267) 8 +"endif" (268) 9 +"for" (269) 10 11 +"to" (270) 10 11 +"next" (271) 12 +"while" (272) 13 +"wend" (273) 14 +"end" (274) 5 +"rand" (275) 33 +"print" (276) 15 +NEG (277) +"step" (278) 10 + + +出現位置の規則による非終端 + +$accept (35) + 左辺: 0 +unit (36) + 左辺: 1 2, 右辺: 0 2 +states (37) + 左辺: 3 4, 右辺: 1 2 +statement (38) + 左辺: 5 6 7 8 9 10 11 12 13 14 15 16, 右辺: 3 +assign (39) + 左辺: 17, 右辺: 6 10 11 +comp_expr (40) + 左辺: 18 19 20 21 22 23, 右辺: 7 13 +expr (41) + 左辺: 24 25 26 27 28 29 30 31 32 33, 右辺: 10 11 17 18 19 20 + 21 22 23 24 25 26 27 28 29 30 33 35 36 +value (42) + 左辺: 34, 右辺: 17 31 +args (43) + 左辺: 35 36, 右辺: 15 36 + + +状態 0 + + 0 $accept: . unit "end of file" + 1 unit: . states + 2 | . unit states + 3 states: . statement "\n" + 4 | . "\n" + 5 statement: . "end" + 6 | . assign + 7 | . "if" comp_expr "then" + 8 | . "else" + 9 | . "endif" + 10 | . "for" assign "to" expr "step" expr + 11 | . "for" assign "to" expr + 12 | . "next" + 13 | . "while" comp_expr + 14 | . "wend" + 15 | . "print" args + 16 | . error + 17 assign: . value '=' expr + 34 value: . "identifier" + + error shift, and go to state 1 + "identifier" shift, and go to state 2 + "\n" shift, and go to state 3 + "if" shift, and go to state 4 + "else" shift, and go to state 5 + "endif" shift, and go to state 6 + "for" shift, and go to state 7 + "next" shift, and go to state 8 + "while" shift, and go to state 9 + "wend" shift, and go to state 10 + "end" shift, and go to state 11 + "print" shift, and go to state 12 + + unit go to state 13 + states go to state 14 + statement go to state 15 + assign go to state 16 + value go to state 17 + + +状態 1 + + 16 statement: error . + + $default reduce using rule 16 (statement) + + +状態 2 + + 34 value: "identifier" . + + $default reduce using rule 34 (value) + + +状態 3 + + 4 states: "\n" . + + $default reduce using rule 4 (states) + + +状態 4 + + 7 statement: "if" . comp_expr "then" + 18 comp_expr: . expr "==" expr + 19 | . expr "!=" expr + 20 | . expr '>' expr + 21 | . expr ">=" expr + 22 | . expr '<' expr + 23 | . expr "<=" expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + comp_expr go to state 22 + expr go to state 23 + value go to state 24 + + +状態 5 + + 8 statement: "else" . + + $default reduce using rule 8 (statement) + + +状態 6 + + 9 statement: "endif" . + + $default reduce using rule 9 (statement) + + +状態 7 + + 10 statement: "for" . assign "to" expr "step" expr + 11 | "for" . assign "to" expr + 17 assign: . value '=' expr + 34 value: . "identifier" + + "identifier" shift, and go to state 2 + + assign go to state 25 + value go to state 17 + + +状態 8 + + 12 statement: "next" . + + $default reduce using rule 12 (statement) + + +状態 9 + + 13 statement: "while" . comp_expr + 18 comp_expr: . expr "==" expr + 19 | . expr "!=" expr + 20 | . expr '>' expr + 21 | . expr ">=" expr + 22 | . expr '<' expr + 23 | . expr "<=" expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + comp_expr go to state 26 + expr go to state 23 + value go to state 24 + + +状態 10 + + 14 statement: "wend" . + + $default reduce using rule 14 (statement) + + +状態 11 + + 5 statement: "end" . + + $default reduce using rule 5 (statement) + + +状態 12 + + 15 statement: "print" . args + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + 35 args: . expr + 36 | . args ',' expr + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 27 + value go to state 24 + args go to state 28 + + +状態 13 + + 0 $accept: unit . "end of file" + 2 unit: unit . states + 3 states: . statement "\n" + 4 | . "\n" + 5 statement: . "end" + 6 | . assign + 7 | . "if" comp_expr "then" + 8 | . "else" + 9 | . "endif" + 10 | . "for" assign "to" expr "step" expr + 11 | . "for" assign "to" expr + 12 | . "next" + 13 | . "while" comp_expr + 14 | . "wend" + 15 | . "print" args + 16 | . error + 17 assign: . value '=' expr + 34 value: . "identifier" + + "end of file" shift, and go to state 29 + error shift, and go to state 1 + "identifier" shift, and go to state 2 + "\n" shift, and go to state 3 + "if" shift, and go to state 4 + "else" shift, and go to state 5 + "endif" shift, and go to state 6 + "for" shift, and go to state 7 + "next" shift, and go to state 8 + "while" shift, and go to state 9 + "wend" shift, and go to state 10 + "end" shift, and go to state 11 + "print" shift, and go to state 12 + + states go to state 30 + statement go to state 15 + assign go to state 16 + value go to state 17 + + +状態 14 + + 1 unit: states . + + $default reduce using rule 1 (unit) + + +状態 15 + + 3 states: statement . "\n" + + "\n" shift, and go to state 31 + + +状態 16 + + 6 statement: assign . + + $default reduce using rule 6 (statement) + + +状態 17 + + 17 assign: value . '=' expr + + '=' shift, and go to state 32 + + +状態 18 + + 32 expr: "ival" . + + $default reduce using rule 32 (expr) + + +状態 19 + + 33 expr: "rand" . '(' expr ')' + + '(' shift, and go to state 33 + + +状態 20 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 29 | '-' . expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 34 + value go to state 24 + + +状態 21 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 30 | '(' . expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 35 + value go to state 24 + + +状態 22 + + 7 statement: "if" comp_expr . "then" + + "then" shift, and go to state 36 + + +状態 23 + + 18 comp_expr: expr . "==" expr + 19 | expr . "!=" expr + 20 | expr . '>' expr + 21 | expr . ">=" expr + 22 | expr . '<' expr + 23 | expr . "<=" expr + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + "==" shift, and go to state 37 + "!=" shift, and go to state 38 + ">=" shift, and go to state 39 + "<=" shift, and go to state 40 + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + '>' shift, and go to state 46 + '<' shift, and go to state 47 + + +状態 24 + + 31 expr: value . + + $default reduce using rule 31 (expr) + + +状態 25 + + 10 statement: "for" assign . "to" expr "step" expr + 11 | "for" assign . "to" expr + + "to" shift, and go to state 48 + + +状態 26 + + 13 statement: "while" comp_expr . + + $default reduce using rule 13 (statement) + + +状態 27 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + 35 args: expr . ["\n", ','] + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 35 (args) + + +状態 28 + + 15 statement: "print" args . ["\n"] + 36 args: args . ',' expr + + ',' shift, and go to state 49 + + $default reduce using rule 15 (statement) + + +状態 29 + + 0 $accept: unit "end of file" . + + $default accept + + +状態 30 + + 2 unit: unit states . + + $default reduce using rule 2 (unit) + + +状態 31 + + 3 states: statement "\n" . + + $default reduce using rule 3 (states) + + +状態 32 + + 17 assign: value '=' . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 50 + value go to state 24 + + +状態 33 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 33 | "rand" '(' . expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 51 + value go to state 24 + + +状態 34 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + 29 | '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + + $default reduce using rule 29 (expr) + + Conflict between rule 29 and token '+' resolved as reduce ('+' < NEG). + Conflict between rule 29 and token '-' resolved as reduce ('-' < NEG). + Conflict between rule 29 and token '*' resolved as reduce ('*' < NEG). + Conflict between rule 29 and token '/' resolved as reduce ('/' < NEG). + Conflict between rule 29 and token '%' resolved as reduce ('%' < NEG). + + +状態 35 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + 30 | '(' expr . ')' + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + ')' shift, and go to state 52 + + +状態 36 + + 7 statement: "if" comp_expr "then" . + + $default reduce using rule 7 (statement) + + +状態 37 + + 18 comp_expr: expr "==" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 53 + value go to state 24 + + +状態 38 + + 19 comp_expr: expr "!=" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 54 + value go to state 24 + + +状態 39 + + 21 comp_expr: expr ">=" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 55 + value go to state 24 + + +状態 40 + + 23 comp_expr: expr "<=" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 56 + value go to state 24 + + +状態 41 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 25 | expr '+' . expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 57 + value go to state 24 + + +状態 42 + + 24 expr: . expr '-' expr + 24 | expr '-' . expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 58 + value go to state 24 + + +状態 43 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 26 | expr '*' . expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 59 + value go to state 24 + + +状態 44 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 27 | expr '/' . expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 60 + value go to state 24 + + +状態 45 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 28 | expr '%' . expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 61 + value go to state 24 + + +状態 46 + + 20 comp_expr: expr '>' . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 62 + value go to state 24 + + +状態 47 + + 22 comp_expr: expr '<' . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 63 + value go to state 24 + + +状態 48 + + 10 statement: "for" assign "to" . expr "step" expr + 11 | "for" assign "to" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 64 + value go to state 24 + + +状態 49 + + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + 36 args: args ',' . expr + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 65 + value go to state 24 + + +状態 50 + + 17 assign: value '=' expr . ["\n", "to"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 17 (assign) + + +状態 51 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + 33 | "rand" '(' expr . ')' + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + ')' shift, and go to state 66 + + +状態 52 + + 30 expr: '(' expr ')' . + + $default reduce using rule 30 (expr) + + +状態 53 + + 18 comp_expr: expr "==" expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 18 (comp_expr) + + +状態 54 + + 19 comp_expr: expr "!=" expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 19 (comp_expr) + + +状態 55 + + 21 comp_expr: expr ">=" expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 21 (comp_expr) + + +状態 56 + + 23 comp_expr: expr "<=" expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 23 (comp_expr) + + +状態 57 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 25 | expr '+' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 25 (expr) + + Conflict between rule 25 and token '+' resolved as reduce (%left '+'). + Conflict between rule 25 and token '-' resolved as reduce (%left '-'). + Conflict between rule 25 and token '*' resolved as shift ('+' < '*'). + Conflict between rule 25 and token '/' resolved as shift ('+' < '/'). + Conflict between rule 25 and token '%' resolved as shift ('+' < '%'). + + +状態 58 + + 24 expr: expr . '-' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 24 | expr '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 24 (expr) + + Conflict between rule 24 and token '+' resolved as reduce (%left '+'). + Conflict between rule 24 and token '-' resolved as reduce (%left '-'). + Conflict between rule 24 and token '*' resolved as shift ('-' < '*'). + Conflict between rule 24 and token '/' resolved as shift ('-' < '/'). + Conflict between rule 24 and token '%' resolved as shift ('-' < '%'). + + +状態 59 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 26 | expr '*' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 27 | expr . '/' expr + 28 | expr . '%' expr + + $default reduce using rule 26 (expr) + + Conflict between rule 26 and token '+' resolved as reduce ('+' < '*'). + Conflict between rule 26 and token '-' resolved as reduce ('-' < '*'). + Conflict between rule 26 and token '*' resolved as reduce (%left '*'). + Conflict between rule 26 and token '/' resolved as reduce (%left '/'). + Conflict between rule 26 and token '%' resolved as reduce (%left '%'). + + +状態 60 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 27 | expr '/' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 28 | expr . '%' expr + + $default reduce using rule 27 (expr) + + Conflict between rule 27 and token '+' resolved as reduce ('+' < '/'). + Conflict between rule 27 and token '-' resolved as reduce ('-' < '/'). + Conflict between rule 27 and token '*' resolved as reduce (%left '*'). + Conflict between rule 27 and token '/' resolved as reduce (%left '/'). + Conflict between rule 27 and token '%' resolved as reduce (%left '%'). + + +状態 61 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 28 | expr '%' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + + $default reduce using rule 28 (expr) + + Conflict between rule 28 and token '+' resolved as reduce ('+' < '%'). + Conflict between rule 28 and token '-' resolved as reduce ('-' < '%'). + Conflict between rule 28 and token '*' resolved as reduce (%left '*'). + Conflict between rule 28 and token '/' resolved as reduce (%left '/'). + Conflict between rule 28 and token '%' resolved as reduce (%left '%'). + + +状態 62 + + 20 comp_expr: expr '>' expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 20 (comp_expr) + + +状態 63 + + 22 comp_expr: expr '<' expr . ["\n", "then"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 22 (comp_expr) + + +状態 64 + + 10 statement: "for" assign "to" expr . "step" expr + 11 | "for" assign "to" expr . ["\n"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + "step" shift, and go to state 67 + + $default reduce using rule 11 (statement) + + +状態 65 + + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + 36 args: args ',' expr . ["\n", ','] + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 36 (args) + + +状態 66 + + 33 expr: "rand" '(' expr ')' . + + $default reduce using rule 33 (expr) + + +状態 67 + + 10 statement: "for" assign "to" expr "step" . expr + 24 expr: . expr '-' expr + 25 | . expr '+' expr + 26 | . expr '*' expr + 27 | . expr '/' expr + 28 | . expr '%' expr + 29 | . '-' expr + 30 | . '(' expr ')' + 31 | . value + 32 | . "ival" + 33 | . "rand" '(' expr ')' + 34 value: . "identifier" + + "ival" shift, and go to state 18 + "identifier" shift, and go to state 2 + "rand" shift, and go to state 19 + '-' shift, and go to state 20 + '(' shift, and go to state 21 + + expr go to state 68 + value go to state 24 + + +状態 68 + + 10 statement: "for" assign "to" expr "step" expr . ["\n"] + 24 expr: expr . '-' expr + 25 | expr . '+' expr + 26 | expr . '*' expr + 27 | expr . '/' expr + 28 | expr . '%' expr + + '+' shift, and go to state 41 + '-' shift, and go to state 42 + '*' shift, and go to state 43 + '/' shift, and go to state 44 + '%' shift, and go to state 45 + + $default reduce using rule 10 (statement) diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-parser.yy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-parser.yy Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,138 @@ +%skeleton "lalr1.cc" +%define "parser_class_name" "script_parser" +%defines +%{ +#ifdef _MSC_VER +#pragma warning(disable: 4800) +#pragma warning(disable: 4267) +#endif + +#include +#include "node.h" +class compiler; +%} +// The parsing context. +%parse-param { compiler& driver } +%lex-param { compiler& driver } +%locations +//%expect 7 +%initial-action +{ + // ロケーション初期化 + @$.begin.filename = @$.end.filename = &driver.get_filename(); +}; +// %debug +%error-verbose +// Symbols. +%union +{ + int ival; + std::string *sval; + + CArgs *args; + CNode *expr; + CAssign *assign; +} +%{ +#include "compiler.h" +%} + +%token END_OF_FILE 0 "end of file" +%token TK_IVAL "ival" +%token TK_IDENTIFIER "identifier" +%token TK_EQ "==" +%token TK_NE "!=" +%token TK_GE ">=" +%token TK_LE "<=" +%token TK_NEWLINE "\n" + +%token TK_IF "if" +%token TK_THEN "then" +%token TK_ELSE "else" +%token TK_ENDIF "endif" +%token TK_FOR "for" +%token TK_TO "to" +%token TK_NEXT "next" +%token TK_WHILE "while" +%token TK_WEND "wend" +%token TK_END "end" +%token TK_RAND "rand" +%token TK_PRINT "print" + +%type expr +%type comp_expr +%type value +%type assign +%type args + +%destructor { delete $$; } "identifier" + +%destructor { delete $$; } args +%destructor { delete $$; } assign +%destructor { delete $$; } value +%destructor { delete $$; } expr +%destructor { delete $$; } comp_expr + +%left '+' '-'; +%left '*' '/' '%'; +%left NEG; +%% +%start unit; + +unit : states + | unit states + ; + +states : statement "\n" + | "\n" + ; + +statement : "end" { driver.EndStatement(@1); } + | assign { driver.AssignStatement(@1, $1); } + | "if" comp_expr "then" { driver.IfStatement(@1, $2); } + | "else" { driver.ElseStatement(@1); } + | "endif" { driver.EndifStatement(@1); } + | "for" assign "to" expr "step" expr { driver.ForStatement(@1, $2, $4, $6); } + | "for" assign "to" expr { driver.ForStatement(@1, $2, $4, NULL); } + | "next" { driver.NextStatement(@1); } + | "while" comp_expr { driver.WhileStatement(@1, $2); } + | "wend" { driver.WendStatement(@1); } + | "print" args { driver.PrintStatement(@1, $2); } + | error /* エラーの場合 */ + ; + +assign : value '=' expr { $$ = new CAssign(@1, '=', $1, $3); } + ; + +comp_expr : expr "==" expr { $$ = CNode::MakeNode(driver, @1, OP_EQ, $1, $3); } + | expr "!=" expr { $$ = CNode::MakeNode(driver, @1, OP_NE, $1, $3); } + | expr '>' expr { $$ = CNode::MakeNode(driver, @1, OP_GT, $1, $3); } + | expr ">=" expr { $$ = CNode::MakeNode(driver, @1, OP_GE, $1, $3); } + | expr '<' expr { $$ = CNode::MakeNode(driver, @1, OP_LT, $1, $3); } + | expr "<=" expr { $$ = CNode::MakeNode(driver, @1, OP_LE, $1, $3); } + ; + +expr : expr '-' expr { $$ = CNode::MakeNode(driver, @1, OP_MINUS, $1, $3); } + | expr '+' expr { $$ = CNode::MakeNode(driver, @1, OP_PLUS, $1, $3); } + | expr '*' expr { $$ = CNode::MakeNode(driver, @1, OP_TIMES, $1, $3); } + | expr '/' expr { $$ = CNode::MakeNode(driver, @1, OP_DIVIDE, $1, $3); } + | expr '%' expr { $$ = CNode::MakeNode(driver, @1, OP_MOD, $1, $3); } + | '-' expr %prec NEG { $$ = CNode::MakeNode(driver, @1, OP_NEG, $2); } + | '(' expr ')' { $$ = $2; } + | value { $$ = $1; } + | "ival" { $$ = new CNode(@1, OP_CONST, $1); } + | "rand" '(' expr ')' { $$ = new CNode(@1, OP_RANDFUNC, $3); } + ; + +value : "identifier" { $$ = new CValueNode(@1, $1); } + ; + +args : expr { $$ = new CArgs(@1, $1); } + | args ',' expr { $$ = $1->Add(@3, $3); } + ; + +%% +void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) +{ + driver.error(l, m); +} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-scanner.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-scanner.cc Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,1822 @@ +#line 2 "script-scanner.cc" + +#line 4 "script-scanner.cc" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 33 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef unsigned int yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define yywrap() 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 31 +#define YY_END_OF_BUFFER 32 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[75] = + { 0, + 0, 0, 29, 29, 32, 28, 24, 18, 28, 19, + 2, 26, 25, 17, 19, 19, 19, 27, 28, 28, + 27, 27, 27, 27, 27, 27, 27, 27, 29, 30, + 24, 21, 25, 23, 20, 22, 27, 16, 1, 27, + 27, 27, 4, 27, 27, 27, 27, 27, 9, 27, + 27, 29, 27, 13, 8, 27, 27, 27, 3, 27, + 27, 27, 6, 27, 10, 27, 14, 5, 12, 27, + 7, 15, 11, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 1, 5, 1, 6, 1, 7, 6, + 6, 6, 6, 6, 6, 1, 6, 8, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 10, 1, 11, + 12, 13, 1, 1, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 1, 15, 1, 16, 14, 1, 17, 14, 14, 18, + + 19, 20, 14, 21, 22, 14, 14, 23, 24, 25, + 26, 27, 14, 28, 29, 30, 14, 14, 31, 32, + 14, 14, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[33] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 3, 3, 1, + 1, 1, 1, 3, 1, 1, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3 + } ; + +static yyconst flex_int16_t yy_base[78] = + { 0, + 0, 0, 83, 82, 84, 87, 81, 87, 70, 87, + 87, 87, 25, 87, 69, 68, 67, 0, 75, 72, + 12, 50, 55, 55, 45, 19, 18, 21, 0, 87, + 70, 87, 37, 87, 87, 87, 0, 87, 87, 42, + 52, 41, 0, 36, 45, 41, 41, 45, 0, 38, + 40, 0, 42, 38, 0, 29, 33, 39, 0, 31, + 37, 31, 0, 33, 0, 21, 0, 0, 0, 24, + 0, 0, 0, 87, 46, 38, 49 + } ; + +static yyconst flex_int16_t yy_def[78] = + { 0, + 74, 1, 75, 75, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 76, 74, 74, + 76, 76, 76, 76, 76, 76, 76, 76, 77, 74, + 74, 74, 74, 74, 74, 74, 76, 74, 74, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 77, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 0, 74, 74, 74 + } ; + +static yyconst flex_int16_t yy_nxt[120] = + { 0, + 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 18, 18, 21, 22, + 18, 23, 18, 18, 24, 18, 25, 26, 18, 27, + 28, 18, 33, 33, 40, 46, 41, 47, 48, 50, + 37, 51, 73, 49, 33, 33, 29, 29, 29, 52, + 72, 52, 71, 70, 69, 68, 67, 66, 65, 64, + 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, + 53, 31, 45, 44, 43, 42, 39, 38, 36, 35, + 34, 32, 31, 74, 30, 30, 5, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74 + } ; + +static yyconst flex_int16_t yy_chk[120] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 13, 13, 21, 26, 21, 26, 27, 28, + 76, 28, 70, 27, 33, 33, 75, 75, 75, 77, + 66, 77, 64, 62, 61, 60, 58, 57, 56, 54, + 53, 51, 50, 48, 47, 46, 45, 44, 42, 41, + 40, 31, 25, 24, 23, 22, 20, 19, 17, 16, + 15, 9, 7, 5, 4, 3, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "script-scanner.ll" +#line 2 "script-scanner.ll" +#include +#include +#include +#include +#include "compiler.h" +#include "script-parser.hh" + +#ifdef _MSC_VER +#pragma warning(disable:4018) +#pragma warning(disable:4102) +#pragma warning(disable:4244) +#pragma warning(disable:4267) +#pragma warning(disable:4996) +#endif + +#undef yywrap +#define yywrap() 1 + +#define yyterminate() return token::END_OF_FILE +#define YY_NO_UNISTD_H 1 + +#line 38 "script-scanner.ll" +#define YY_USER_ACTION yylloc->columns(yyleng); +#line 529 "script-scanner.cc" + +#define INITIAL 0 +#define COMMENT 1 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 40 "script-scanner.ll" + + + typedef yy::script_parser::token token; + + yylloc->step(); + + std::string string_buffer; + +#line 690 "script-scanner.cc" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 75 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 74 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 49 "script-scanner.ll" +{ yylloc->step(); BEGIN(COMMENT); } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 50 "script-scanner.ll" +{ yylloc->step(); BEGIN(COMMENT); } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 51 "script-scanner.ll" +{ yylloc->step(); BEGIN(COMMENT); } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 53 "script-scanner.ll" +return token::TK_IF; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 54 "script-scanner.ll" +return token::TK_THEN; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 55 "script-scanner.ll" +return token::TK_ELSE; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 56 "script-scanner.ll" +return token::TK_ENDIF; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 57 "script-scanner.ll" +return token::TK_FOR; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 58 "script-scanner.ll" +return token::TK_TO; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 59 "script-scanner.ll" +return token::TK_NEXT; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 60 "script-scanner.ll" +return token::TK_WHILE; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 61 "script-scanner.ll" +return token::TK_WEND; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 62 "script-scanner.ll" +return token::TK_END; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 63 "script-scanner.ll" +return token::TK_RAND; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 64 "script-scanner.ll" +return token::TK_PRINT; + YY_BREAK +case 16: +/* rule 16 can match eol */ +YY_RULE_SETUP +#line 66 "script-scanner.ll" +yylloc->lines(); + YY_BREAK +case 17: +YY_RULE_SETUP +#line 68 "script-scanner.ll" +return token::TK_NEWLINE; + YY_BREAK +case 18: +/* rule 18 can match eol */ +YY_RULE_SETUP +#line 69 "script-scanner.ll" +{ yylloc->lines(); return token::TK_NEWLINE; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 70 "script-scanner.ll" +return yy::script_parser::token_type(yytext[0]); + YY_BREAK +case 20: +YY_RULE_SETUP +#line 72 "script-scanner.ll" +return token::TK_EQ; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 73 "script-scanner.ll" +return token::TK_NE; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 74 "script-scanner.ll" +return token::TK_GE; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 75 "script-scanner.ll" +return token::TK_LE; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 77 "script-scanner.ll" +yylloc->step(); + YY_BREAK +case 25: +YY_RULE_SETUP +#line 78 "script-scanner.ll" +{ + errno = 0; + long n = strtol(yytext, NULL, 10); + if (n < LONG_MIN || n > LONG_MAX || errno == ERANGE) + driver.error(*yylloc, "整数が範囲外です。"); + yylval->ival = n; + return token::TK_IVAL; + } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 86 "script-scanner.ll" +{ + yylval->ival = 0; + return token::TK_IVAL; + } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 90 "script-scanner.ll" +{ + yylval->sval = new std::string(yytext); + return token::TK_IDENTIFIER; + } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 94 "script-scanner.ll" +driver.error(*yylloc, "この文字を識別子で使用することはできません。"); + YY_BREAK + + +case 29: +YY_RULE_SETUP +#line 97 "script-scanner.ll" + + YY_BREAK +case 30: +/* rule 30 can match eol */ +YY_RULE_SETUP +#line 98 "script-scanner.ll" +{ + yylloc->lines(); + yylloc->step(); + BEGIN(INITIAL); + } + YY_BREAK + +case 31: +YY_RULE_SETUP +#line 104 "script-scanner.ll" +ECHO; + YY_BREAK +#line 947 "script-scanner.cc" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(COMMENT): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 75 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 75 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 74); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 104 "script-scanner.ll" + + + +void compiler::scan_begin() +{ + if ((yyin = fopen(file.c_str(), "r")) == 0) + error(file + " がオープンできません。"); +} + +void compiler::scan_end() +{ + fclose(yyin); + yylex_destroy(); +} + diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script-scanner.ll --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script-scanner.ll Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,116 @@ +%{ +#include +#include +#include +#include +#include "compiler.h" +#include "script-parser.hh" + +#ifdef _MSC_VER +#pragma warning(disable:4018) +#pragma warning(disable:4102) +#pragma warning(disable:4244) +#pragma warning(disable:4267) +#pragma warning(disable:4996) +#endif + +#undef yywrap +#define yywrap() 1 + +#define yyterminate() return token::END_OF_FILE +%} + +%option noyywrap nounput batch +%option never-interactive +%option noyy_scan_buffer +%option noyy_scan_bytes +%option noyy_scan_string +%option 8bit +%option nounistd + +id [a-zA-Z_][a-zA-Z_0-9]* +int [1-9][0-9]* +blank [ \t] + +%x COMMENT + +%{ +#define YY_USER_ACTION yylloc->columns(yyleng); +%} +%% +%{ + typedef yy::script_parser::token token; + + yylloc->step(); + + std::string string_buffer; +%} +{ + "^#" { yylloc->step(); BEGIN(COMMENT); } + "'" { yylloc->step(); BEGIN(COMMENT); } + "rem" { yylloc->step(); BEGIN(COMMENT); } + + "if" return token::TK_IF; + "then" return token::TK_THEN; + "else" return token::TK_ELSE; + "endif" return token::TK_ENDIF; + "for" return token::TK_FOR; + "to" return token::TK_TO; + "next" return token::TK_NEXT; + "while" return token::TK_WHILE; + "wend" return token::TK_WEND; + "end" return token::TK_END; + "rand" return token::TK_RAND; + "print" return token::TK_PRINT; + + \\\n yylloc->lines(); + + : return token::TK_NEWLINE; + \n { yylloc->lines(); return token::TK_NEWLINE; } + [-+*/%=,()<>] return yy::script_parser::token_type(yytext[0]); + + "==" return token::TK_EQ; + "!=" return token::TK_NE; + ">=" return token::TK_GE; + "<=" return token::TK_LE; + + {blank}+ yylloc->step(); + {int} { + errno = 0; + long n = strtol(yytext, NULL, 10); + if (n < LONG_MIN || n > LONG_MAX || errno == ERANGE) + driver.error(*yylloc, "整数が範囲外です。"); + yylval->ival = n; + return token::TK_IVAL; + } + "0" { + yylval->ival = 0; + return token::TK_IVAL; + } + {id} { + yylval->sval = new std::string(yytext); + return token::TK_IDENTIFIER; + } + . driver.error(*yylloc, "この文字を識別子で使用することはできません。"); +} +{ + [^\n]* + \n { + yylloc->lines(); + yylloc->step(); + BEGIN(INITIAL); + } +} +%% + +void compiler::scan_begin() +{ + if ((yyin = fopen(file.c_str(), "r")) == 0) + error(file + " がオープンできません。"); +} + +void compiler::scan_end() +{ + fclose(yyin); + yylex_destroy(); +} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/script.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/script.cpp Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,25 @@ +#include +#include "compiler.h" +#include "vm.h" + +int main(int argc, char *argv[]) +{ + for (++argv; argv[0]; ++argv) { + vm::data data; + bool compile_result; + { + compiler driver; + compile_result = driver.compile(*argv, data); +#ifdef _DEBUG + if (compile_result) + driver.debug_dump(); +#endif + } + if (compile_result) { + vm::vcpu machine(data); + int result = machine.run(); + std::cout << "result = " << result << std::endl; + } + } + return 0; +} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/stack.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/stack.hh Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,129 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Stack handling for Bison parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef BISON_STACK_HH +# define BISON_STACK_HH + +#include + +namespace yy +{ + template > + class stack + { + public: + + // Hide our reversed order. + typedef typename S::reverse_iterator iterator; + typedef typename S::const_reverse_iterator const_iterator; + + stack () : seq_ () + { + } + + stack (unsigned int n) : seq_ (n) + { + } + + inline + T& + operator [] (unsigned int i) + { + return seq_[i]; + } + + inline + const T& + operator [] (unsigned int i) const + { + return seq_[i]; + } + + inline + void + push (const T& t) + { + seq_.push_front (t); + } + + inline + void + pop (unsigned int n = 1) + { + for (; n; --n) + seq_.pop_front (); + } + + inline + unsigned int + height () const + { + return seq_.size (); + } + + inline const_iterator begin () const { return seq_.rbegin (); } + inline const_iterator end () const { return seq_.rend (); } + + private: + + S seq_; + }; + + /// Present a slice of the top of a stack. + template > + class slice + { + public: + + slice (const S& stack, + unsigned int range) : stack_ (stack), + range_ (range) + { + } + + inline + const T& + operator [] (unsigned int i) const + { + return stack_[range_ - i]; + } + + private: + + const S& stack_; + unsigned int range_; + }; +} + +#endif // not BISON_STACK_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/vm.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/vm.cpp Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,222 @@ +// +// 仮想CPU +// +// 関数ポインタベースでの実装例 +// +// (c)2008 Chihiro.SAKAMOTO HyperWorks +// +#include +#include "vm.h" + +namespace vm { + + // 0除算例外 + class devide_by_zero: public std::exception { + public: + const char *what() const throw() + { + return "devide by zero"; + } + } ; + + void (vcpu::*vcpu::cmd_[])() = { + #define VM_EXECTABLE + #include "vm_code.h" + #undef VM_EXECTABLE + } ; + + // 実行 + int vcpu::run() + { + command_ = data_.command_; // プログラム格納位置 + command_size_ = data_.command_size_; // プログラムの大きさ + + global_value.resize(data_.value_size_); // 外部変数テーブル確保 + command_ptr_ = command_; // プログラムカウンター初期化 + + active = true; // Haltしていない + + try { + while (active) { // Haltするまでループ + int op = *command_ptr_++; + (this->*cmd_[op])(); + } + } + catch (const std::exception &e) { + std::cerr << "例外発生(" << e.what() << ")" << std::endl; + return -1; + } + return 0; + } + + // 定数Push + void vcpu::PushConst() + { + push(value()); + } + + // 変数Push + void vcpu::PushValue() + { + push(global_value[value()]); + } + + // 変数にPop + void vcpu::PopValue() + { + global_value[value()] = top(); pop(); + } + + // 空Pop(スタックトップを捨てる) + void vcpu::OpPop() + { + pop(); + } + + // 単項マイナス + void vcpu::OpNeg() + { + top() = -top(); + } + + // == + void vcpu::OpEq() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs == rhs); + } + + // != + void vcpu::OpNe() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs != rhs); + } + + // > + void vcpu::OpGt() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs > rhs); + } + + // >= + void vcpu::OpGe() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs >= rhs); + } + + // < + void vcpu::OpLt() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs < rhs); + } + + // <= + void vcpu::OpLe() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs <= rhs); + } + + // + + void vcpu::OpAdd() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs + rhs); + } + + // - + void vcpu::OpSub() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs - rhs); + } + + // * + void vcpu::OpMul() + { + int rhs = top(); pop(); + int lhs = top(); pop(); + push(lhs * rhs); + } + + // / + void vcpu::OpDiv() + { + int rhs = top(); pop(); + if (rhs == 0) + throw devide_by_zero(); + int lhs = top(); pop(); + push(lhs / rhs); + } + + // % + void vcpu::OpMod() + { + int rhs = top(); pop(); + if (rhs == 0) + throw devide_by_zero(); + int lhs = top(); pop(); + push(lhs % rhs); + } + + // 無条件ジャンプ + void vcpu::OpJmp() + { + jmp(value()); + } + + // 真の時ジャンプ + void vcpu::OpJmpC() + { + int addr = value(); + int cond = top(); pop(); + if (cond) + jmp(addr); + } + + // 偽の時ジャンプ + void vcpu::OpJmpNC() + { + int addr = value(); + int cond = top(); pop(); + if (!cond) + jmp(addr); + } + + // 仮想CPUプログラム停止 + void vcpu::OpHalt() + { + active = false; + } + + void vcpu::OpRand() + { + int range = top(); pop(); + int value = (range <= 0)? 0: (rand() % range); + push(value); + } + + void vcpu::OpPrint() + { + int count = value(); + while (count--) { + std::cout << top(); + pop(); + if (count) + std::cout << ", "; + } + std::cout << std::endl; + } +} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/vm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/vm.h Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,76 @@ +#ifndef __VM_H__ +#define __VM_H__ + +#include +#include "vm_value.h" + +#define VM_ENUMDEF +enum { +#include "vm_code.h" + VM_MAXCOMMAND, +} ; +#undef VM_ENUMDEF + +namespace vm { + + class data { + public: + data(): command_(0) + { + } + ~data() + { + delete[] command_; + } + + public: + unsigned char *command_; // コマンドテーブル + int command_size_; // コマンドサイズ + int value_size_; // グローバル変数サイズ + } ; + + class vcpu { + public: + const static int STACK_SIZE = 1000; + + public: + vcpu(data &mem) + : data_(mem) + { + } + ~vcpu() + { + } + + int run(); + + private: +#define VM_EXEC +#include "vm_code.h" +#undef VM_EXEC + + private: + int value() { int v = *(int *)command_ptr_; command_ptr_ += 4; return v; } + int addr() const { return (int)(command_ptr_ - command_); } + void jmp(int addr) { command_ptr_ = command_ + addr; } + void push(int v) { stack.push(v); } + void pop() { stack.pop(); } + const int top() const { return stack.top(); } + int &top() { return stack.top(); } + + private: + data &data_; + unsigned char *command_; + unsigned char *command_ptr_; + int command_size_; + bool active; + + vm::stack stack; + std::vector global_value; + + static void (vcpu::*cmd_[])(); + } ; + +} + +#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/vm_code.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/vm_code.h Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,46 @@ +#ifdef VM_ENUMDEF +#define VMCODE0(code_, name_) code_, +#define VMCODE1(code_, name_) code_, +#endif +#ifdef VM_CREATE +#define VMCODE0(code_, name_) void name_() { statement.push_back(CVMCode(code_)); } +#define VMCODE1(code_, name_) void name_(int arg1) { statement.push_back(CVMCode(code_, arg1)); } +#endif +#ifdef VM_EXEC +#define VMCODE0(code_, name_) void name_(); +#define VMCODE1(code_, name_) void name_(); +#endif +#ifdef VM_EXECTABLE +#define VMCODE0(code_, name_) &vcpu::name_, +#define VMCODE1(code_, name_) &vcpu::name_, +#endif +#ifdef VM_NAMETABLE +#define VMCODE0(code_, name_) #name_, +#define VMCODE1(code_, name_) #name_, +#endif + +VMCODE1(VM_PUSHCONST, PushConst) +VMCODE1(VM_PUSHVALUE, PushValue) +VMCODE1(VM_POPVALUE, PopValue) +VMCODE0(VM_POP, OpPop) +VMCODE0(VM_NEG, OpNeg) +VMCODE0(VM_EQ, OpEq) +VMCODE0(VM_NE, OpNe) +VMCODE0(VM_GT, OpGt) +VMCODE0(VM_GE, OpGe) +VMCODE0(VM_LT, OpLt) +VMCODE0(VM_LE, OpLe) +VMCODE0(VM_ADD, OpAdd) +VMCODE0(VM_SUB, OpSub) +VMCODE0(VM_MUL, OpMul) +VMCODE0(VM_DIV, OpDiv) +VMCODE0(VM_MOD, OpMod) +VMCODE1(VM_JMP, OpJmp) +VMCODE1(VM_JMPC, OpJmpC) +VMCODE1(VM_JMPNC, OpJmpNC) +VMCODE1(VM_PRINT, OpPrint) +VMCODE0(VM_RAND, OpRand) +VMCODE0(VM_HALT, OpHalt) + +#undef VMCODE0 +#undef VMCODE1 diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/BasicCompiler-StackBase/vm_value.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/vm_value.h Tue May 10 06:26:08 2011 +0900 @@ -0,0 +1,83 @@ +#ifndef __vm_value_h__ +#define __vm_value_h__ + +#include +#include + +namespace vm { + + class stack_overflow: public std::exception { + public: + const char *what() const throw() + { + return "stack overflow"; + } + } ; + + // 固定サイズのスタック + // スタックオーバーフローの場合は例外を送出 + + template< typename Ty, int Size > + class stack { + public: + stack(): size_(0) + { + } + + ~stack() + { + resize(0); + } + + void push(const Ty& value) + { + if (Size <= size_) + throw stack_overflow(); + *(::new(data_[size_++]) Ty) = value; + } + + void pop() + { + ((Ty *)data_[--size_])->~Ty(); + } + + void pop(int count) + { + resize(size_ - count); + } + + void resize(int newsize) + { + int oldsize = size_; + + if (oldsize > newsize) { + for (int i = newsize; i < oldsize; ++i) + ((Ty *)data_[i])->~Ty(); + } + if (oldsize < newsize) { + if (Size < newsize) + throw stack_overflow(); + for (int i = oldsize; i < newsize; ++i) + ::new(data_[i]) Ty; + } + size_ = newsize; + } + + const Ty& top() const { return *(const Ty *)data_[size_ - 1]; } + Ty& top() { return *(Ty *)data_[size_ - 1]; } + + bool overflow() const { return size_ >= Size; } + bool empty() const { return size_ == 0; } + int size() const { return size_; } + + const Ty& operator[](int index) const { return *(const Ty *)data_[index]; } + Ty& operator[](int index) { return *(Ty *)data_[index]; } + + protected: + char data_[Size][sizeof(Ty)]; + int size_; + } ; + +} // namespace + +#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/.#file.txt --- a/Bison-Flex/EUC/.#file.txt Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -aotokage@dimo.local.68364 \ No newline at end of file diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/.#script-parser.cc --- a/Bison-Flex/EUC/.#script-parser.cc Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -aotokage@dimo.local.68364 \ No newline at end of file diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/.#script-parser.hh --- a/Bison-Flex/EUC/.#script-parser.hh Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -aotokage@dimo.local.68364 \ No newline at end of file diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/Makefile --- a/Bison-Flex/EUC/Makefile Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -SOURCES = script.cpp compiler.cpp node.cpp vm.cpp script-parser.yy script-scanner.ll -HEADERS = compiler.h node.h vm.h vm_code.h vm_value.h -OBJ = script.o compiler.o node.o vm.o script-parser.o script-scanner.o -BISON_OUTPUT = script-parser.cc script-parser.hh location.hh position.hh - -#CFLAGS = -O2 -CFLAGS = -g3 -O0 - -all: script - -convert: $(SOURCES) $(HEADERS) - -.SUFFIXES: -.SUFFIXES: .cpp .cc .ll .yy .o - -script: $(OBJ) - $(CC) $(LDFLAGS) -o $@ $(OBJ) -lstdc++ - -.cpp.o: - $(CC) -c $(CFLAGS) -o $@ $< - -.cc.o: - $(CC) -c $(CFLAGS) -o $@ $< - -$(BISON_OUTPUT): script-parser.yy - bison -d -ra -oscript-parser.cc script-parser.yy - -script-scanner.cc: script-scanner.ll - flex -8 -oscript-scanner.cc script-scanner.ll - -script-parser.o: $(BISON_OUTPUT) -script-scanner.o: script-scanner.cc - -script.cpp: ../script.cpp - nkf --unix $< > $@ - -compiler.cpp: ../compiler.cpp - nkf --unix $< > $@ - -node.cpp: ../node.cpp - nkf --unix $< > $@ - -vm.cpp: ../vm.cpp - nkf --unix $< > $@ - -script-parser.yy: ../script-parser.yy - nkf --unix $< > $@ - -script-scanner.ll: ../script-scanner.ll - nkf --unix $< > $@ - -vm_code.h: ../vm_code.h - nkf --unix $< > $@ - -vm_value.h: ../vm_value.h - nkf --unix $< > $@ - -vm.h: ../vm.h - nkf --unix $< > $@ - -node.h: ../node.h - nkf --unix $< > $@ - -compiler.h: ../compiler.h - nkf --unix $< > $@ - -depend: - makedepend -- $(CFLAGS) -- $(SOURCES) - -script.o: script-parser.hh -node.o: location.hh - -# DO NOT DELETE - -script.o: compiler.h script-parser.hh stack.hh node.h location.hh position.hh -script.o: vm.h vm_value.h vm_code.h -compiler.o: script-parser.hh stack.hh node.h location.hh position.hh vm.h -compiler.o: vm_value.h vm_code.h compiler.h -node.o: node.h location.hh position.hh vm.h vm_value.h vm_code.h compiler.h -node.o: script-parser.hh stack.hh -vm.o: vm.h vm_value.h vm_code.h -script-parser.o: node.h location.hh position.hh vm.h vm_value.h vm_code.h -script-parser.o: compiler.h script-parser.hh stack.hh -#script-scanner.o: /usr/include/errno.h /usr/include/features.h -#script-scanner.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h -#script-scanner.o: /usr/include/bits/errno.h /usr/include/linux/errno.h -#script-scanner.o: /usr/include/asm/errno.h /usr/include/asm-i486/errno.h -#script-scanner.o: /usr/include/asm-generic/errno.h -#script-scanner.o: /usr/include/asm-generic/errno-base.h /usr/include/limits.h -#script-scanner.o: /usr/include/bits/posix1_lim.h -#script-scanner.o: /usr/include/bits/local_lim.h /usr/include/linux/limits.h -#script-scanner.o: /usr/include/bits/posix2_lim.h compiler.h script-parser.hh -script-scanner.o: stack.hh node.h location.hh position.hh vm.h vm_value.h -script-scanner.o: vm_code.h diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/compiler.cpp --- a/Bison-Flex/EUC/compiler.cpp Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,426 +0,0 @@ -#include -#include -#include "script-parser.hh" -#include "compiler.h" - -#ifdef _MSC_VER -#pragma warning(disable: 4996) -#endif - -// コンストラクタ - -compiler::compiler() - : error_count(0) -{ -} - -// デストラクタ - -compiler::~compiler() -{ -} - -// コンパイル - -bool compiler::compile(const std::string &f, vm::data &data) -{ - // システムコールの設定 - - file = f; - scan_begin(); // スキャナー初期化 - yy::script_parser parser(*this); // パーサー構築 - int result = parser.parse(); // 構文解析 - scan_end(); // スキャナー終了 - - if (result != 0) - return false; // パーサーエラー - - // ステートスタックが空ではないならば、if, for, whileが - // 閉じていない - while (!state_stack.empty()) { - CState &state = state_stack.top(); - switch (state.state_) { - case STATE_IF: - error(state.l_, "ifに対応するendifが有りません"); - break; - - case STATE_FOR: - error(state.l_, "forに対応するnextが有りません"); - delete state.start_; - delete state.end_; - delete state.step_; - break; - - case STATE_WHILE: - error(state.l_, "whileに対応するwendが有りません"); - break; - } - state_stack.pop(); - } - - // 番兵用HALTコマンドを追加 - const CVMCode &code = statement.back(); - if (code.op_ != VM_HALT) // haltが無いならば - OpHalt(); // haltを追加 - - int code_size = LabelSetting(); // ラベルにアドレスを設定 - CraeteData(data, code_size); // バイナリ生成 - - return error_count == 0; -} - -// エラーメッセージを出力 - -void compiler::error(const yy::location& l, const std::string& m) -{ - std::cerr << l << ": " << m << std::endl; - error_count++; -} - -// エラーメッセージを出力 - -void compiler::error(const std::string& m) -{ - std::cerr << m << std::endl; - error_count++; -} - -// 命令文の登録 - -// 代入文 -void compiler::AssignStatement(const yy::location& l, CAssign *assign) -{ - assign->analyze(this); - delete assign; -} - -// if文 -// -// if expr then -// A -// endif -// -// > push expr -// > jmp_nc L1 -// > A -// > L1: -// -// if expr then -// A -// else -// B -// endif -// -// > push expr -// > jmp_nc L1 -// > A -// > jmp L2 -// > L1: -// > B -// > L2: -// -void compiler::IfStatement(const yy::location& l, CNode *expr) -{ - expr->push(this); - int label = MakeLabel(); - OpJmpNC(label); // 偽の時の飛び先 - - state_stack.push(CState(l, STATE_IF, label)); - - delete expr; -} - -void compiler::ElseStatement(const yy::location& l) -{ - if (state_stack.empty() || state_stack.top().state_ != STATE_IF) { - error(l, "if文と対応していないelse文が有りました。"); - } - else { - CState &state = state_stack.top(); - int label = MakeLabel(); - OpJmp(label); - SetLabel(state.label1_); // 偽の時の飛び先をここにする - state.label1_ = label; // endifの飛び先を再設定 - } -} - -void compiler::EndifStatement(const yy::location& l) -{ - if (state_stack.empty() || state_stack.top().state_ != STATE_IF) { - error(l, "if文と対応していないendif文が有りました。"); - } - else { - CState &state = state_stack.top(); - SetLabel(state.label1_); // endifの飛び先をここにする - state_stack.pop(); // ステートスタックをpop - } -} - -// FOR文 -// -// for value=X to Y step Z -// A -// next -// -// > push X : value = X -// > pop value -// > L1: -// > A -// > push value : if (value == Y) goto L2 -// > push Y -// > eq -// > jmp_c L2 -// > push value : value = value + Z -// > push Z -// > add -// > pop value -// > jmp L1 -// > L2: -// -void compiler::ForStatement(const yy::location& l, CAssign *start, CNode *end, CNode *step) -{ - int label = MakeLabel(); - - start->analyze(this); - SetLabel(label); - - state_stack.push(CState(l, STATE_FOR, label, start, end, step)); -} - -void compiler::NextStatement(const yy::location& l) -{ - if (state_stack.empty() || state_stack.top().state_ != STATE_FOR) { - error(l, "for文と対応していないnext文が有りました。"); - } - else { - CState &state = state_stack.top(); - int label = MakeLabel(); - - // ループ終了のチェック - state.start_->push_value(this); - state.end_->push(this); - OpEq(); - OpJmpC(label); // 終了時飛び先 - - // カウンター増分 - state.start_->push_value(this); - if (state.step_) - state.step_->push(this); - else - PushConst(1); - - OpAdd(); - state.start_->pop_value(this); - - // ループ - OpJmp(state.label1_); - - // ループ終了 - SetLabel(label); - - // 後始末 - delete state.start_; - delete state.end_; - delete state.step_; - - state_stack.pop(); - } -} - -// while文 -// -// while (expr) A -// > L1: -// > push expr -// > jmp_nc L2 -// > A -// > jmp L1 -// > L2: -// -void compiler::WhileStatement(const yy::location& l, CNode *expr) -{ - int label1 = MakeLabel(); - int label2 = MakeLabel(); - - SetLabel(label1); - expr->push(this); - OpJmpNC(label2); - - state_stack.push(CState(l, STATE_WHILE, label1, label2)); - - delete expr; -} - -void compiler::WendStatement(const yy::location& l) -{ - if (state_stack.empty() || state_stack.top().state_ != STATE_WHILE) { - error(l, "while文と対応していないwend文が有りました。"); - } - else { - CState &state = state_stack.top(); - OpJmp(state.label1_); - SetLabel(state.label2_); - state_stack.pop(); - } -} - -// end文 -// -// > halt -// -void compiler::EndStatement(const yy::location& l) -{ - OpHalt(); -} - -// print文 -// -// print a, b, c -// -// > push c -// > push b -// > push a -// > print 3 -// -void compiler::PrintStatement(const yy::location& l, CArgs *args) -{ - int arg_count = 0; - if (args) { - args->for_each_rev(std::bind2nd(std::mem_fun(&CNode::push), this)); - arg_count = args->size(); - } - - OpPrint(arg_count); - - delete args; -} - -// ラベル生成 - -int compiler::MakeLabel() -{ - int index = (int)labels.size(); - labels.push_back(CLabel(index)); - return index; -} - -// ラベルのダミーコマンドをステートメントリストに登録する - -void compiler::SetLabel(int label) -{ - statement.push_back(CVMCode(VM_MAXCOMMAND, label)); -} - -// ラベル解決 -// -// 1.アドレスを生成する -// 2.ダミーのラベルコマンドが有ったアドレスを、ラベルテーブルに登録する -// 3.Jmpコマンドの飛び先をラベルテーブルに登録されたアドレスにする - -// note: -// GCCでは、関数オブジェクトを関数内に書けないので、ここに記述する。 -// VC++9.0(VS2008)では関数内に書くことで、スコープを封じ込める事が可能。 - -// アドレス計算関数オブジェクト -struct calc_addr { - std::vector &labels_; - int &pos_; - calc_addr(std::vector &labels, int &pos): labels_(labels), pos_(pos) - { - } - void operator()(const CVMCode &code) - { - if (code.op_ == VM_MAXCOMMAND) { // ラベルのダミーコマンド - labels_[code.arg1_].pos_ = pos_; - } - else { - pos_ += code.size_; - } - } -} ; - -// ジャンプアドレス設定関数オブジェクト -struct set_addr { - std::vector &labels_; - set_addr(std::vector &labels): labels_(labels) - { - } - void operator()(CVMCode &code) - { - switch (code.op_) { - case VM_JMP: - case VM_JMPC: - case VM_JMPNC: - code.arg1_ = labels_[code.arg1_].pos_; - break; - } - } -} ; - -int compiler::LabelSetting() -{ - // アドレス計算 - int pos = 0; - std::for_each(statement.begin(), statement.end(), calc_addr(labels, pos)); - // ジャンプアドレス設定 - std::for_each(statement.begin(), statement.end(), set_addr(labels)); - - return pos; -} - -// バイナリデータ生成 - -// 関数オブジェクト -struct copy_code { - unsigned char *p; - copy_code(unsigned char *code): p(code) - { - } - void operator()(const CVMCode &code) - { - p = code.Get(p); - } -} ; - -bool compiler::CraeteData(vm::data &data, int code_size) -{ - data.command_ = new unsigned char[code_size]; - data.command_size_ = code_size; - data.value_size_ = (int)variables.size(); - - std::for_each(statement.begin(), statement.end(), copy_code(data.command_)); - - return true; -} - -// デバッグダンプ -#ifdef _DEBUG -void compiler::debug_dump() -{ - std::cout << "---variables---" << std::endl; - variables.dump(); - - static const char *op_name[] = { -#define VM_NAMETABLE -#include "vm_code.h" -#undef VM_NAMETABLE - "LABEL", - } ; - std::cout << "---code---" << std::endl; - - int pos = 0; - size_t size = statement.size(); - for (size_t i=0; i < size; i++) { - std::cout << std::setw(6) << pos << ": " << op_name[statement[i].op_]; - if (statement[i].size_ > 1) { - std::cout << ", " << statement[i].arg1_; - } - std::cout << std::endl; - - if (statement[i].op_ != VM_MAXCOMMAND) { - pos += statement[i].size_; - } - } - std::cout << "---" << std::endl; -} -#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/compiler.h --- a/Bison-Flex/EUC/compiler.h Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,254 +0,0 @@ -#ifndef __COMPILER_H__ -#define __COMPILER_H__ - -#include -#include "script-parser.hh" -#include "vm.h" -#include "node.h" - -// Forward declarations. -class compiler; - -// flexの関数宣言 -#define YY_DECL \ - yy::script_parser::token_type \ - yylex(yy::script_parser::semantic_type* yylval, \ - yy::script_parser::location_type* yylloc, \ - compiler& driver) - -YY_DECL; - -// 仮想マシンコード生成用 - -class CVMCode { - public: - CVMCode(unsigned char op) - : size_(1), op_(op), arg1_(0) - { - } - CVMCode(unsigned char op, int arg1) - : size_(5), op_(op), arg1_(arg1) - { - } - - unsigned char *Get(unsigned char *p) const - { - if (op_ != VM_MAXCOMMAND) { // ラベルのダミーコマンド - *p++ = op_; - if (size_ > 1) { - *(int *)p = arg1_; - p += 4; - } - } - return p; - } - - public: - unsigned char size_; - unsigned char op_; - int arg1_; -} ; - -// ラベル - -class CLabel { - public: - CLabel(int index) - : index_(index), pos_(0) - { - } - ~CLabel() - { - } - - public: - int index_; - int pos_; -} ; - -// 変数テーブル - -class CValueTag { - public: - CValueTag(): addr_(-1), size_(1) - { - } - CValueTag(int addr, int size) - : addr_(addr), size_(size) - { - } - - public: - int addr_; - int size_; -} ; - -class CValueTable { - private: - typedef std::map::iterator iter; - typedef std::map::const_iterator const_iter; - - public: - CValueTable(int start_addr=0): addr_(start_addr) - { - } - - bool add(const std::string &name, int size=1) - { - std::pair result = variables_.insert(make_pair(name, CValueTag(addr_, size))); - if (result.second) { - addr_ += size; - return true; - } - return false; - } - - const CValueTag *find(const std::string &name) const - { - const_iter it = variables_.find(name); - if (it != variables_.end()) - return &it->second; - return NULL; - } - - bool add_arg(const std::string &name, int addr) - { - std::pair result = variables_.insert(make_pair(name, CValueTag(addr, 1))); - return result.second; - } - - int size() const { return addr_; } - void clear() - { - variables_.clear(); - addr_ = 0; - } - -#ifdef _DEBUG - struct dump_action { - void operator()(const std::pair &it) - { - std::cout << it.first << ", addr = " << it.second.addr_ << ", size = " << it.second.size_ << std::endl; - } - } ; - - void dump() const - { - std::for_each(variables_.begin(), variables_.end(), dump_action()); - } -#endif - - private: - std::map variables_; - int addr_; -} ; - -// コンパイラ - -class compiler { - private: - enum STACK_STATE { - STATE_IF, - STATE_FOR, - STATE_WHILE, - } ; - - class CState { - public: - CState(const yy::location& l, int state, int label) - : l_(l), state_(state), label1_(label), label2_(0), start_(0), end_(0), step_(0) - { - } - CState(const yy::location& l, int state, int label1, int label2) - : l_(l), state_(state), label1_(label1), label2_(label2), start_(0), end_(0), step_(0) - { - } - CState(const yy::location& l, int state, int label, CAssign *start, CNode *end, CNode *step) - : l_(l), state_(state), label1_(label), label2_(0), start_(start), end_(end), step_(step) - { - } - - public: - yy::location l_; - int state_; - int label1_; - int label2_; - CAssign *start_; - CNode *end_; - CNode *step_; - } ; - - public: - compiler(); - virtual ~compiler(); - - std::string &get_filename() { return file; } - bool compile(const std::string &f, vm::data &data); -#ifdef _DEBUG - void debug_dump(); -#endif - - // 文 - // 代入文 - void AssignStatement(const yy::location& l, CAssign *assign); - // if文 - void IfStatement(const yy::location& l, CNode *expr); - void ElseStatement(const yy::location& l); - void EndifStatement(const yy::location& l); - // for文 - void ForStatement(const yy::location& l, CAssign *start, CNode *end, CNode *step); - void NextStatement(const yy::location& l); - // while文 - void WhileStatement(const yy::location& l, CNode *expr); - void WendStatement(const yy::location& l); - // end文 - void EndStatement(const yy::location& l); - // print文 - void PrintStatement(const yy::location& l, CArgs *args); - - const CValueTag *GetValueTag(const std::string &name) const - { - return variables.find(name); - } - - const CValueTag *AddValue(const std::string &name) - { - if (variables.add(name, 1)) { - return variables.find(name); - } - return NULL; - } - - // for code generator. -#define VM_CREATE -#include "vm_code.h" -#undef VM_CREATE - - int LabelSetting(); - - int MakeLabel(); - - void SetLabel(int label); - - bool CraeteData(vm::data &data, int code_size); - - // Error handling. - void error(const yy::location& l, const std::string& m); - void error(const std::string& m); - - private: - void scan_begin(); - void scan_end(); - - private: - CValueTable variables; - std::vector statement; - std::vector labels; - std::stack state_stack; - - int error_count; - - std::string file; -} ; - -#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/file.txt --- a/Bison-Flex/EUC/file.txt Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -a = 20 -b = 30 -print a + b diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/location.hh --- a/Bison-Flex/EUC/location.hh Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.3. */ - -/* Locations for Bison parsers in C++ - - Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/** - ** \file location.hh - ** Define the yy::location class. - */ - -#ifndef BISON_LOCATION_HH -# define BISON_LOCATION_HH - -# include -# include -# include "position.hh" - -namespace yy -{ - - /// Abstract a location. - class location - { - public: - - /// Construct a location. - location () - : begin (), end () - { - } - - - /// Initialization. - inline void initialize (std::string* fn) - { - begin.initialize (fn); - end = begin; - } - - /** \name Line and Column related manipulators - ** \{ */ - public: - /// Reset initial location to final location. - inline void step () - { - begin = end; - } - - /// Extend the current location to the COUNT next columns. - inline void columns (unsigned int count = 1) - { - end += count; - } - - /// Extend the current location to the COUNT next lines. - inline void lines (unsigned int count = 1) - { - end.lines (count); - } - /** \} */ - - - public: - /// Beginning of the located region. - position begin; - /// End of the located region. - position end; - }; - - /// Join two location objects to create a location. - inline const location operator+ (const location& begin, const location& end) - { - location res = begin; - res.end = end.end; - return res; - } - - /// Add two location objects. - inline const location operator+ (const location& begin, unsigned int width) - { - location res = begin; - res.columns (width); - return res; - } - - /// Add and assign a location. - inline location& operator+= (location& res, unsigned int width) - { - res.columns (width); - return res; - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param loc a reference to the location to redirect - ** - ** Avoid duplicate information. - */ - inline std::ostream& operator<< (std::ostream& ostr, const location& loc) - { - position last = loc.end - 1; - ostr << loc.begin; - if (last.filename - && (!loc.begin.filename - || *loc.begin.filename != *last.filename)) - ostr << '-' << last; - else if (loc.begin.line != last.line) - ostr << '-' << last.line << '.' << last.column; - else if (loc.begin.column != last.column) - ostr << '-' << last.column; - return ostr; - } - -} - -#endif // not BISON_LOCATION_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/node.cpp --- a/Bison-Flex/EUC/node.cpp Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,213 +0,0 @@ -#include -#include -#include -#include "node.h" -#include "compiler.h" -#include "script-parser.hh" - -// ノード生成 -// ただし、定数同士の計算は、leftノードに結果を代入し、それを返す - -CNode *CNode::MakeNode(compiler &c, const yy::location& l, int op, CNode *left, CNode *right) -{ - if (right == 0) { - switch (op) { - case OP_NEG: - if (left->op_ == OP_CONST) { // 定数演算を計算する - left->value_ = -left->value_; - return left; - } - break; - } - return new CNode(l, op, left); - } - - // 定数演算を計算する - if (left->op_ == OP_CONST && right->op_ == OP_CONST) { - switch (op) { - case OP_EQ: - left->value_ = (left->value_ == right->value_)? 1: 0; - break; - - case OP_NE: - left->value_ = (left->value_ != right->value_)? 1: 0; - break; - - case OP_GT: - left->value_ = (left->value_ > right->value_)? 1: 0; - break; - - case OP_GE: - left->value_ = (left->value_ >= right->value_)? 1: 0; - break; - - case OP_LT: - left->value_ = (left->value_ < right->value_)? 1: 0; - break; - - case OP_LE: - left->value_ = (left->value_ <= right->value_)? 1: 0; - break; - - case OP_MINUS: - left->value_ -= right->value_; - break; - - case OP_PLUS: - left->value_ += right->value_; - break; - - case OP_TIMES: - left->value_ *= right->value_; - break; - - case OP_DIVIDE: - if (right->value_ == 0) { - c.error(l, "定数計算を0で除算しました。"); - } - else { - left->value_ /= right->value_; - } - break; - - case OP_MOD: - if (right->value_ == 0) { - c.error(l, "定数計算を0で除算しました。"); - } - else { - left->value_ %= right->value_; - } - break; - - default: - return new CNode(l, op, left, right); - } - delete right; - return left; - } - return new CNode(l, op, left, right); -} - -void CNode::push(compiler *c) const -{ - switch (op_) { - case OP_NEG: - left_->push(c); - c->OpNeg(); - return; - - case OP_RANDFUNC: - left_->push(c); - c->OpRand(); - return; - - case OP_CONST: - c->PushConst(value_); - return; - } - - left_->push(c); - right_->push(c); - - // 整数計算ノードの処理 - switch (op_) { - case OP_EQ: - c->OpEq(); - break; - - case OP_NE: - c->OpNe(); - break; - - case OP_GT: - c->OpGt(); - break; - - case OP_GE: - c->OpGe(); - break; - - case OP_LT: - c->OpLt(); - break; - - case OP_LE: - c->OpLe(); - break; - - case OP_MINUS: - c->OpSub(); - break; - - case OP_PLUS: - c->OpAdd(); - break; - - case OP_TIMES: - c->OpMul(); - break; - - case OP_DIVIDE: - c->OpDiv(); - break; - - case OP_MOD: - c->OpMod(); - break; - - default: - c->error(l_, "内部エラー:処理できない計算ノードがありました。"); - break; - } -} - -void CNode::pop(compiler *c) const -{ - c->error(l_, "内部エラー:計算ノードをpopしています。"); -} - -void CValueNode::push(compiler *c) const -{ - if (op_ != OP_VALUE) { - c->error(l_, "内部エラー:変数ノードに変数以外が登録されています。"); - } - else { - const CValueTag *tag = c->GetValueTag(*string_); - if (tag == 0) { - c->error(l_, "変数 " + *string_ + " は定義されていません。"); - } - else { - c->PushValue(tag->addr_); - } - } -} - -void CValueNode::pop(compiler *c) const -{ - if (op_ != OP_VALUE) { - c->error(l_, "内部エラー:変数ノードに変数以外が登録されています。"); - } - else { - const CValueTag *tag = c->GetValueTag(*string_); - if (tag == 0) { - tag = c->AddValue(*string_); - } - if (tag == 0) { - c->error(l_, "変数 " + *string_ + " が定義できません。"); - } - else { - c->PopValue(tag->addr_); - } - } -} - -// 代入命令を生成 -// -// > push b -// > pop a -// -void CAssign::analyze(compiler *c) -{ - expr_->push(c); - value_->pop(c); -} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/node.h --- a/Bison-Flex/EUC/node.h Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -#ifndef __NODE_H__ -#define __NODE_H__ - -#include -#include -#include -#include -#include -#include "location.hh" -#include "vm.h" - -class compiler; -class CNode; -class CValueNode; -class CArgDef; - -// 配列 - -template -class CNodeList { - struct delete_object { - void operator()(T *ptr){ delete ptr; } - } ; - - public: - CNodeList(const yy::location& l, T *node) - { - args.push_back(node); - } - ~CNodeList() - { - std::for_each(args.begin(), args.end(), delete_object()); - } - - CNodeList *Add(const yy::location& l, T *add) - { - args.push_back(add); - return this; - } - - template - void for_each(const Fn &func) - { - std::for_each(args.begin(), args.end(), func); - } - - template - void for_each_rev(const Fn &func) - { - std::for_each(args.rbegin(), args.rend(), func); - } - - void analyze(compiler *c) - { - std::for_each(args.begin(), args.end(), std::bind2nd(std::mem_fun(&T::analyze), c)); - } - - size_t size() const { return args.size(); } - T *get(size_t idx) { return args[idx]; } - T *operator[](size_t idx) { return args[idx]; } - const T *get(size_t idx) const { return args[idx]; } - const T *operator[](size_t idx) const { return args[idx]; } - - private: - std::vector args; -} ; - -typedef CNodeList CArgs; - -// ノードの命令 -enum { - OP_NEG, - OP_PLUS, - OP_MINUS, - OP_TIMES, - OP_DIVIDE, - OP_MOD, - OP_EQ, - OP_NE, - OP_GT, - OP_GE, - OP_LT, - OP_LE, - OP_VALUE, - OP_CONST, - OP_RANDFUNC, -} ; - -// ノード - -class CNode { - public: - CNode(const yy::location& l, int op, CNode *left, CNode *right=0) - : l_(l), op_(op), left_(left), right_(right), value_(0), string_(0) - { - } - CNode(const yy::location& l, int op, int value) - : l_(l), op_(op), left_(0), right_(0), value_(value), string_(0) - { - } - CNode(const yy::location& l, int op, std::string *str) - : l_(l), op_(op), left_(0), right_(0), value_(0), string_(str) - { - } - CNode(const yy::location& l, int op, std::string *str, CNode *node) - : l_(l), op_(op), left_(node), right_(0), value_(0), string_(str) - { - } - virtual ~CNode() - { - delete left_; - delete right_; - delete string_; - } - - virtual void push(compiler *c) const; - virtual void pop(compiler *c) const; - - const yy::location &location() const { return l_; } - int op() const { return op_; } - int value() const { return value_; } - const std::string &string() const { return *string_; } - const CNode *left() const { return left_; } - const CNode *right() const { return right_; } - - static CNode *MakeNode(compiler &c, const yy::location& l, int op, CNode *left, CNode *right=0); - - protected: - const yy::location l_; - int op_; - int value_; - std::string *string_; - CNode *left_; - CNode *right_; -} ; - -// 変数ノード - -class CValueNode: public CNode { - public: - CValueNode(const yy::location& l, std::string *name, CNode *node=NULL) - : CNode(l, OP_VALUE, name, node) - { - } - - void push(compiler *c) const; - void pop(compiler *c) const; -} ; - -// 代入文用 - -class CAssign { - public: - CAssign(const yy::location& l, int op, CNode *value, CNode *expr) - : l_(l), op_(op), value_(value), expr_(expr) - { - } - ~CAssign() - { - delete value_; - delete expr_; - } - - void analyze(compiler *c); - void push_value(compiler *c) - { - value_->push(c); - } - void pop_value(compiler *c) - { - value_->pop(c); - } - - private: - const yy::location l_; - int op_; - CNode *value_; - CNode *expr_; -} ; - -#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/position.hh --- a/Bison-Flex/EUC/position.hh Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.3. */ - -/* Positions for Bison parsers in C++ - - Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/** - ** \file position.hh - ** Define the yy::position class. - */ - -#ifndef BISON_POSITION_HH -# define BISON_POSITION_HH - -# include -# include - -namespace yy -{ - /// Abstract a position. - class position - { - public: - - /// Construct a position. - position () - : filename (0), line (1), column (0) - { - } - - - /// Initialization. - inline void initialize (std::string* fn) - { - filename = fn; - line = 1; - column = 0; - } - - /** \name Line and Column related manipulators - ** \{ */ - public: - /// (line related) Advance to the COUNT next lines. - inline void lines (int count = 1) - { - column = 0; - line += count; - } - - /// (column related) Advance to the COUNT next columns. - inline void columns (int count = 1) - { - int leftmost = 0; - int current = column; - if (leftmost <= current + count) - column += count; - else - column = 0; - } - /** \} */ - - public: - /// File name to which this position refers. - std::string* filename; - /// Current line number. - unsigned int line; - /// Current column number. - unsigned int column; - }; - - /// Add and assign a position. - inline const position& - operator+= (position& res, const int width) - { - res.columns (width); - return res; - } - - /// Add two position objects. - inline const position - operator+ (const position& begin, const int width) - { - position res = begin; - return res += width; - } - - /// Add and assign a position. - inline const position& - operator-= (position& res, const int width) - { - return res += -width; - } - - /// Add two position objects. - inline const position - operator- (const position& begin, const int width) - { - return begin + -width; - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param pos a reference to the position to redirect - */ - inline std::ostream& - operator<< (std::ostream& ostr, const position& pos) - { - if (pos.filename) - ostr << *pos.filename << ':'; - return ostr << pos.line << '.' << pos.column; - } - -} -#endif // not BISON_POSITION_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script Binary file Bison-Flex/EUC/script has changed diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-parser.cc --- a/Bison-Flex/EUC/script-parser.cc Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1070 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.3. */ - -/* Skeleton implementation for Bison LALR(1) parsers in C++ - - Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - - -#include "script-parser.hh" - -/* User implementation prologue. */ -#line 36 "script-parser.yy" - -#include "compiler.h" - - -/* Line 317 of lalr1.cc. */ -#line 46 "script-parser.cc" - -#ifndef YY_ -# if YYENABLE_NLS -# if ENABLE_NLS -# include /* FIXME: INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) -# endif -# endif -# ifndef YY_ -# define YY_(msgid) msgid -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#define YYUSE(e) ((void) (e)) - -/* A pseudo ostream that takes yydebug_ into account. */ -# define YYCDEBUG \ - for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ - (*yycdebug_) - -/* Enable debugging if requested. */ -#if YYDEBUG - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug_) \ - { \ - *yycdebug_ << Title << ' '; \ - yy_symbol_print_ ((Type), (Value), (Location)); \ - *yycdebug_ << std::endl; \ - } \ -} while (false) - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug_) \ - yy_reduce_print_ (Rule); \ -} while (false) - -# define YY_STACK_PRINT() \ -do { \ - if (yydebug_) \ - yystack_print_ (); \ -} while (false) - -#else /* !YYDEBUG */ - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_REDUCE_PRINT(Rule) -# define YY_STACK_PRINT() - -#endif /* !YYDEBUG */ - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - -namespace yy -{ -#if YYERROR_VERBOSE - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - script_parser::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr = ""; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - -#endif - - /// Build a parser object. - script_parser::script_parser (compiler& driver_yyarg) - : yydebug_ (false), - yycdebug_ (&std::cerr), - driver (driver_yyarg) - { - } - - script_parser::~script_parser () - { - } - -#if YYDEBUG - /*--------------------------------. - | Print this symbol on YYOUTPUT. | - `--------------------------------*/ - - inline void - script_parser::yy_symbol_value_print_ (int yytype, - const semantic_type* yyvaluep, const location_type* yylocationp) - { - YYUSE (yylocationp); - YYUSE (yyvaluep); - switch (yytype) - { - default: - break; - } - } - - - void - script_parser::yy_symbol_print_ (int yytype, - const semantic_type* yyvaluep, const location_type* yylocationp) - { - *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " (" - << *yylocationp << ": "; - yy_symbol_value_print_ (yytype, yyvaluep, yylocationp); - *yycdebug_ << ')'; - } -#endif /* ! YYDEBUG */ - - void - script_parser::yydestruct_ (const char* yymsg, - int yytype, semantic_type* yyvaluep, location_type* yylocationp) - { - YYUSE (yylocationp); - YYUSE (yymsg); - YYUSE (yyvaluep); - - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - switch (yytype) - { - case 4: /* "\"identifier\"" */ -#line 68 "script-parser.yy" - { delete (yyvaluep->sval); }; -#line 206 "script-parser.cc" - break; - case 39: /* "assign" */ -#line 71 "script-parser.yy" - { delete (yyvaluep->assign); }; -#line 211 "script-parser.cc" - break; - case 40: /* "comp_expr" */ -#line 74 "script-parser.yy" - { delete (yyvaluep->expr); }; -#line 216 "script-parser.cc" - break; - case 41: /* "expr" */ -#line 73 "script-parser.yy" - { delete (yyvaluep->expr); }; -#line 221 "script-parser.cc" - break; - case 42: /* "value" */ -#line 72 "script-parser.yy" - { delete (yyvaluep->expr); }; -#line 226 "script-parser.cc" - break; - case 43: /* "args" */ -#line 70 "script-parser.yy" - { delete (yyvaluep->args); }; -#line 231 "script-parser.cc" - break; - - default: - break; - } - } - - void - script_parser::yypop_ (unsigned int n) - { - yystate_stack_.pop (n); - yysemantic_stack_.pop (n); - yylocation_stack_.pop (n); - } - - std::ostream& - script_parser::debug_stream () const - { - return *yycdebug_; - } - - void - script_parser::set_debug_stream (std::ostream& o) - { - yycdebug_ = &o; - } - - - script_parser::debug_level_type - script_parser::debug_level () const - { - return yydebug_; - } - - void - script_parser::set_debug_level (debug_level_type l) - { - yydebug_ = l; - } - - - int - script_parser::parse () - { - /// Look-ahead and look-ahead in internal form. - int yychar = yyempty_; - int yytoken = 0; - - /* State. */ - int yyn; - int yylen = 0; - int yystate = 0; - - /* Error handling. */ - int yynerrs_ = 0; - int yyerrstatus_ = 0; - - /// Semantic value of the look-ahead. - semantic_type yylval; - /// Location of the look-ahead. - location_type yylloc; - /// The locations where the error started and ended. - location yyerror_range[2]; - - /// $$. - semantic_type yyval; - /// @$. - location_type yyloc; - - int yyresult; - - YYCDEBUG << "Starting parse" << std::endl; - - - /* User initialization code. */ - #line 20 "script-parser.yy" -{ - // ロケーション初期化 - yylloc.begin.filename = yylloc.end.filename = &driver.get_filename(); -} - /* Line 547 of yacc.c. */ -#line 313 "script-parser.cc" - /* Initialize the stacks. The initial state will be pushed in - yynewstate, since the latter expects the semantical and the - location values to have been already stored, initialize these - stacks with a primary value. */ - yystate_stack_ = state_stack_type (0); - yysemantic_stack_ = semantic_stack_type (0); - yylocation_stack_ = location_stack_type (0); - yysemantic_stack_.push (yylval); - yylocation_stack_.push (yylloc); - - /* New state. */ - yynewstate: - yystate_stack_.push (yystate); - YYCDEBUG << "Entering state " << yystate << std::endl; - goto yybackup; - - /* Backup. */ - yybackup: - - /* Try to take a decision without look-ahead. */ - yyn = yypact_[yystate]; - if (yyn == yypact_ninf_) - goto yydefault; - - /* Read a look-ahead token. */ - if (yychar == yyempty_) - { - YYCDEBUG << "Reading a token: "; - yychar = yylex (&yylval, &yylloc, driver); - } - - - /* Convert token to internal form. */ - if (yychar <= yyeof_) - { - yychar = yytoken = yyeof_; - YYCDEBUG << "Now at end of input." << std::endl; - } - else - { - yytoken = yytranslate_ (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) - goto yydefault; - - /* Reduce or error. */ - yyn = yytable_[yyn]; - if (yyn <= 0) - { - if (yyn == 0 || yyn == yytable_ninf_) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Accept? */ - if (yyn == yyfinal_) - goto yyacceptlab; - - /* Shift the look-ahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the token being shifted unless it is eof. */ - if (yychar != yyeof_) - yychar = yyempty_; - - yysemantic_stack_.push (yylval); - yylocation_stack_.push (yylloc); - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus_) - --yyerrstatus_; - - yystate = yyn; - goto yynewstate; - - /*-----------------------------------------------------------. - | yydefault -- do the default action for the current state. | - `-----------------------------------------------------------*/ - yydefault: - yyn = yydefact_[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - /*-----------------------------. - | yyreduce -- Do a reduction. | - `-----------------------------*/ - yyreduce: - yylen = yyr2_[yyn]; - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. Otherwise, use the top of the stack. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. */ - if (yylen) - yyval = yysemantic_stack_[yylen - 1]; - else - yyval = yysemantic_stack_[0]; - - { - slice slice (yylocation_stack_, yylen); - YYLLOC_DEFAULT (yyloc, slice, yylen); - } - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 6: -#line 90 "script-parser.yy" - { driver.EndStatement((yylocation_stack_[(1) - (1)])); ;} - break; - - case 7: -#line 91 "script-parser.yy" - { driver.AssignStatement((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].assign)); ;} - break; - - case 8: -#line 92 "script-parser.yy" - { driver.IfStatement((yylocation_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (2)].expr)); ;} - break; - - case 9: -#line 93 "script-parser.yy" - { driver.ElseStatement((yylocation_stack_[(1) - (1)])); ;} - break; - - case 10: -#line 94 "script-parser.yy" - { driver.EndifStatement((yylocation_stack_[(1) - (1)])); ;} - break; - - case 11: -#line 95 "script-parser.yy" - { driver.ForStatement((yylocation_stack_[(6) - (1)]), (yysemantic_stack_[(6) - (2)].assign), (yysemantic_stack_[(6) - (4)].expr), (yysemantic_stack_[(6) - (6)].expr)); ;} - break; - - case 12: -#line 96 "script-parser.yy" - { driver.ForStatement((yylocation_stack_[(4) - (1)]), (yysemantic_stack_[(4) - (2)].assign), (yysemantic_stack_[(4) - (4)].expr), NULL); ;} - break; - - case 13: -#line 97 "script-parser.yy" - { driver.NextStatement((yylocation_stack_[(1) - (1)])); ;} - break; - - case 14: -#line 98 "script-parser.yy" - { driver.WhileStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].expr)); ;} - break; - - case 15: -#line 99 "script-parser.yy" - { driver.WendStatement((yylocation_stack_[(1) - (1)])); ;} - break; - - case 16: -#line 100 "script-parser.yy" - { driver.PrintStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].args)); ;} - break; - - case 18: -#line 104 "script-parser.yy" - { (yyval.assign) = new CAssign((yylocation_stack_[(3) - (1)]), '=', (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 19: -#line 107 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_EQ, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 20: -#line 108 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_NE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 21: -#line 109 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 22: -#line 110 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 23: -#line 111 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 24: -#line 112 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 25: -#line 115 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MINUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 26: -#line 116 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_PLUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 27: -#line 117 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_TIMES, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 28: -#line 118 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_DIVIDE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 29: -#line 119 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MOD, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - case 30: -#line 120 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(2) - (1)]), OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;} - break; - - case 31: -#line 121 "script-parser.yy" - { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;} - break; - - case 32: -#line 122 "script-parser.yy" - { (yyval.expr) = (yysemantic_stack_[(1) - (1)].expr); ;} - break; - - case 33: -#line 123 "script-parser.yy" - { (yyval.expr) = new CNode((yylocation_stack_[(1) - (1)]), OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;} - break; - - case 34: -#line 124 "script-parser.yy" - { (yyval.expr) = new CNode((yylocation_stack_[(4) - (1)]), OP_RANDFUNC, (yysemantic_stack_[(4) - (3)].expr)); ;} - break; - - case 35: -#line 127 "script-parser.yy" - { (yyval.expr) = new CValueNode((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].sval)); ;} - break; - - case 36: -#line 130 "script-parser.yy" - { (yyval.args) = new CArgs((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].expr)); ;} - break; - - case 37: -#line 131 "script-parser.yy" - { (yyval.args) = (yysemantic_stack_[(3) - (1)].args)->Add((yylocation_stack_[(3) - (3)]), (yysemantic_stack_[(3) - (3)].expr)); ;} - break; - - - /* Line 675 of lalr1.cc. */ -#line 585 "script-parser.cc" - default: break; - } - YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); - - yypop_ (yylen); - yylen = 0; - YY_STACK_PRINT (); - - yysemantic_stack_.push (yyval); - yylocation_stack_.push (yyloc); - - /* Shift the result of the reduction. */ - yyn = yyr1_[yyn]; - yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0]; - if (0 <= yystate && yystate <= yylast_ - && yycheck_[yystate] == yystate_stack_[0]) - yystate = yytable_[yystate]; - else - yystate = yydefgoto_[yyn - yyntokens_]; - goto yynewstate; - - /*------------------------------------. - | yyerrlab -- here on detecting error | - `------------------------------------*/ - yyerrlab: - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus_) - { - ++yynerrs_; - error (yylloc, yysyntax_error_ (yystate, yytoken)); - } - - yyerror_range[0] = yylloc; - if (yyerrstatus_ == 3) - { - /* If just tried and failed to reuse look-ahead token after an - error, discard it. */ - - if (yychar <= yyeof_) - { - /* Return failure if at end of input. */ - if (yychar == yyeof_) - YYABORT; - } - else - { - yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); - yychar = yyempty_; - } - } - - /* Else will try to reuse look-ahead token after shifting the error - token. */ - goto yyerrlab1; - - - /*---------------------------------------------------. - | yyerrorlab -- error raised explicitly by YYERROR. | - `---------------------------------------------------*/ - yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (false) - goto yyerrorlab; - - yyerror_range[0] = yylocation_stack_[yylen - 1]; - /* Do not reclaim the symbols of the rule which action triggered - this YYERROR. */ - yypop_ (yylen); - yylen = 0; - yystate = yystate_stack_[0]; - goto yyerrlab1; - - /*-------------------------------------------------------------. - | yyerrlab1 -- common code for both syntax error and YYERROR. | - `-------------------------------------------------------------*/ - yyerrlab1: - yyerrstatus_ = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact_[yystate]; - if (yyn != yypact_ninf_) - { - yyn += yyterror_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yystate_stack_.height () == 1) - YYABORT; - - yyerror_range[0] = yylocation_stack_[0]; - yydestruct_ ("Error: popping", - yystos_[yystate], - &yysemantic_stack_[0], &yylocation_stack_[0]); - yypop_ (); - yystate = yystate_stack_[0]; - YY_STACK_PRINT (); - } - - if (yyn == yyfinal_) - goto yyacceptlab; - - yyerror_range[1] = yylloc; - // Using YYLLOC is tempting, but would change the location of - // the look-ahead. YYLOC is available though. - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); - yysemantic_stack_.push (yylval); - yylocation_stack_.push (yyloc); - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], - &yysemantic_stack_[0], &yylocation_stack_[0]); - - yystate = yyn; - goto yynewstate; - - /* Accept. */ - yyacceptlab: - yyresult = 0; - goto yyreturn; - - /* Abort. */ - yyabortlab: - yyresult = 1; - goto yyreturn; - - yyreturn: - if (yychar != yyeof_ && yychar != yyempty_) - yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); - - /* Do not reclaim the symbols of the rule which action triggered - this YYABORT or YYACCEPT. */ - yypop_ (yylen); - while (yystate_stack_.height () != 1) - { - yydestruct_ ("Cleanup: popping", - yystos_[yystate_stack_[0]], - &yysemantic_stack_[0], - &yylocation_stack_[0]); - yypop_ (); - } - - return yyresult; - } - - // Generate an error message. - std::string - script_parser::yysyntax_error_ (int yystate, int tok) - { - std::string res; - YYUSE (yystate); -#if YYERROR_VERBOSE - int yyn = yypact_[yystate]; - if (yypact_ninf_ < yyn && yyn <= yylast_) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - int count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - ++count; - - // FIXME: This method of building the message is not compatible - // with internationalization. It should work like yacc.c does it. - // That is, first build a string that looks like this: - // "syntax error, unexpected %s or %s or %s" - // Then, invoke YY_ on this string. - // Finally, use the string as a format to output - // yytname_[tok], etc. - // Until this gets fixed, this message appears in English only. - res = "syntax error, unexpected "; - res += yytnamerr_ (yytname_[tok]); - if (count < 5) - { - count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - { - res += (!count++) ? ", expecting " : " or "; - res += yytnamerr_ (yytname_[x]); - } - } - } - else -#endif - res = YY_("syntax error"); - return res; - } - - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ - const signed char script_parser::yypact_ninf_ = -23; - const signed char - script_parser::yypact_[] = - { - 85, -23, -23, -23, 19, -23, -23, -3, -23, 19, - -23, -23, 19, 66, -23, -7, -23, -22, -23, -14, - 19, 19, 8, 38, -23, 9, -23, 103, 4, -23, - -23, -23, 19, 19, -23, 86, -23, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 103, 91, -23, 103, 103, 103, 103, -20, -20, -23, - -23, -23, 103, 103, -11, 103, -23, 19, 103 - }; - - /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE - doesn't specify something else to do. Zero means the default is an - error. */ - const unsigned char - script_parser::yydefact_[] = - { - 0, 17, 35, 5, 0, 9, 10, 0, 13, 0, - 15, 6, 0, 0, 2, 0, 7, 0, 33, 0, - 0, 0, 0, 0, 32, 0, 14, 36, 16, 1, - 3, 4, 0, 0, 30, 0, 8, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 18, 0, 31, 19, 20, 22, 24, 26, 25, 27, - 28, 29, 21, 23, 12, 37, 34, 0, 11 - }; - - /* YYPGOTO[NTERM-NUM]. */ - const signed char - script_parser::yypgoto_[] = - { - -23, -23, 27, -23, 34, 39, -12, 3, -23 - }; - - /* YYDEFGOTO[NTERM-NUM]. */ - const signed char - script_parser::yydefgoto_[] = - { - -1, 13, 14, 15, 16, 22, 23, 24, 28 - }; - - /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. */ - const signed char script_parser::yytable_ninf_ = -1; - const unsigned char - script_parser::yytable_[] = - { - 27, 2, 31, 17, 43, 44, 45, 32, 34, 35, - 17, 41, 42, 43, 44, 45, 17, 67, 33, 36, - 50, 51, 18, 2, 48, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 49, 19, - 30, 25, 20, 37, 38, 39, 40, 0, 26, 0, - 0, 21, 0, 0, 0, 68, 0, 0, 0, 0, - 41, 42, 43, 44, 45, 0, 29, 1, 46, 47, - 2, 0, 0, 0, 0, 3, 4, 0, 5, 6, - 7, 0, 8, 9, 10, 11, 1, 12, 0, 2, - 0, 0, 0, 0, 3, 4, 0, 5, 6, 7, - 0, 8, 9, 10, 11, 0, 12, 0, 41, 42, - 43, 44, 45, 41, 42, 43, 44, 45, 0, 52, - 0, 0, 0, 0, 66, 41, 42, 43, 44, 45 - }; - - /* YYCHECK. */ - const signed char - script_parser::yycheck_[] = - { - 12, 4, 9, 0, 24, 25, 26, 29, 20, 21, - 7, 22, 23, 24, 25, 26, 13, 28, 32, 11, - 32, 33, 3, 4, 15, 37, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 34, 20, - 13, 7, 23, 5, 6, 7, 8, -1, 9, -1, - -1, 32, -1, -1, -1, 67, -1, -1, -1, -1, - 22, 23, 24, 25, 26, -1, 0, 1, 30, 31, - 4, -1, -1, -1, -1, 9, 10, -1, 12, 13, - 14, -1, 16, 17, 18, 19, 1, 21, -1, 4, - -1, -1, -1, -1, 9, 10, -1, 12, 13, 14, - -1, 16, 17, 18, 19, -1, 21, -1, 22, 23, - 24, 25, 26, 22, 23, 24, 25, 26, -1, 33, - -1, -1, -1, -1, 33, 22, 23, 24, 25, 26 - }; - - /* STOS_[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ - const unsigned char - script_parser::yystos_[] = - { - 0, 1, 4, 9, 10, 12, 13, 14, 16, 17, - 18, 19, 21, 36, 37, 38, 39, 42, 3, 20, - 23, 32, 40, 41, 42, 39, 40, 41, 43, 0, - 37, 9, 29, 32, 41, 41, 11, 5, 6, 7, - 8, 22, 23, 24, 25, 26, 30, 31, 15, 34, - 41, 41, 33, 41, 41, 41, 41, 41, 41, 41, - 41, 41, 41, 41, 41, 41, 33, 28, 41 - }; - -#if YYDEBUG - /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding - to YYLEX-NUM. */ - const unsigned short int - script_parser::yytoken_number_[] = - { - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 43, 45, 42, 47, 37, 277, 278, 61, - 62, 60, 40, 41, 44 - }; -#endif - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ - const unsigned char - script_parser::yyr1_[] = - { - 0, 35, 36, 36, 37, 37, 38, 38, 38, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 39, 40, - 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, - 41, 41, 41, 41, 41, 42, 43, 43 - }; - - /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ - const unsigned char - script_parser::yyr2_[] = - { - 0, 2, 1, 2, 2, 1, 1, 1, 3, 1, - 1, 6, 4, 1, 2, 1, 2, 1, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 3, 1, 1, 4, 1, 1, 3 - }; - -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE - /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at \a yyntokens_, nonterminals. */ - const char* - const script_parser::yytname_[] = - { - "\"end of file\"", "error", "$undefined", "\"ival\"", "\"identifier\"", - "\"==\"", "\"!=\"", "\">=\"", "\"<=\"", "\"\\n\"", "\"if\"", "\"then\"", - "\"else\"", "\"endif\"", "\"for\"", "\"to\"", "\"next\"", "\"while\"", - "\"wend\"", "\"end\"", "\"rand\"", "\"print\"", "'+'", "'-'", "'*'", - "'/'", "'%'", "NEG", "\"step\"", "'='", "'>'", "'<'", "'('", "')'", - "','", "$accept", "unit", "states", "statement", "assign", "comp_expr", - "expr", "value", "args", 0 - }; -#endif - -#if YYDEBUG - /* YYRHS -- A `-1'-separated list of the rules' RHS. */ - const script_parser::rhs_number_type - script_parser::yyrhs_[] = - { - 36, 0, -1, 37, -1, 36, 37, -1, 38, 9, - -1, 9, -1, 19, -1, 39, -1, 10, 40, 11, - -1, 12, -1, 13, -1, 14, 39, 15, 41, 28, - 41, -1, 14, 39, 15, 41, -1, 16, -1, 17, - 40, -1, 18, -1, 21, 43, -1, 1, -1, 42, - 29, 41, -1, 41, 5, 41, -1, 41, 6, 41, - -1, 41, 30, 41, -1, 41, 7, 41, -1, 41, - 31, 41, -1, 41, 8, 41, -1, 41, 23, 41, - -1, 41, 22, 41, -1, 41, 24, 41, -1, 41, - 25, 41, -1, 41, 26, 41, -1, 23, 41, -1, - 32, 41, 33, -1, 42, -1, 3, -1, 20, 32, - 41, 33, -1, 4, -1, 41, -1, 43, 34, 41, - -1 - }; - - /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ - const unsigned char - script_parser::yyprhs_[] = - { - 0, 0, 3, 5, 8, 11, 13, 15, 17, 21, - 23, 25, 32, 37, 39, 42, 44, 47, 49, 53, - 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, - 97, 100, 104, 106, 108, 113, 115, 117 - }; - - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ - const unsigned char - script_parser::yyrline_[] = - { - 0, 82, 82, 83, 86, 87, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 104, 107, - 108, 109, 110, 111, 112, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 127, 130, 131 - }; - - // Print the state stack on the debug stream. - void - script_parser::yystack_print_ () - { - *yycdebug_ << "Stack now"; - for (state_stack_type::const_iterator i = yystate_stack_.begin (); - i != yystate_stack_.end (); ++i) - *yycdebug_ << ' ' << *i; - *yycdebug_ << std::endl; - } - - // Report on the debug stream that the rule \a yyrule is going to be reduced. - void - script_parser::yy_reduce_print_ (int yyrule) - { - unsigned int yylno = yyrline_[yyrule]; - int yynrhs = yyr2_[yyrule]; - /* Print the symbols being reduced, and their result. */ - *yycdebug_ << "Reducing stack by rule " << yyrule - 1 - << " (line " << yylno << "), "; - /* The symbols being reduced. */ - for (int yyi = 0; yyi < yynrhs; yyi++) - YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", - yyrhs_[yyprhs_[yyrule] + yyi], - &(yysemantic_stack_[(yynrhs) - (yyi + 1)]), - &(yylocation_stack_[(yynrhs) - (yyi + 1)])); - } -#endif // YYDEBUG - - /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ - script_parser::token_number_type - script_parser::yytranslate_ (int t) - { - static - const token_number_type - translate_table[] = - { - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 26, 2, 2, - 32, 33, 24, 22, 34, 23, 2, 25, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 31, 29, 30, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 27, 28 - }; - if ((unsigned int) t <= yyuser_token_number_max_) - return translate_table[t]; - else - return yyundef_token_; - } - - const int script_parser::yyeof_ = 0; - const int script_parser::yylast_ = 129; - const int script_parser::yynnts_ = 9; - const int script_parser::yyempty_ = -2; - const int script_parser::yyfinal_ = 29; - const int script_parser::yyterror_ = 1; - const int script_parser::yyerrcode_ = 256; - const int script_parser::yyntokens_ = 35; - - const unsigned int script_parser::yyuser_token_number_max_ = 278; - const script_parser::token_number_type script_parser::yyundef_token_ = 2; - -} // namespace yy - -#line 134 "script-parser.yy" - -void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) -{ - driver.error(l, m); -} - diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-parser.hh --- a/Bison-Flex/EUC/script-parser.hh Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,329 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.3. */ - -/* Skeleton interface for Bison LALR(1) parsers in C++ - - Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C++ LALR(1) parser skeleton written by Akim Demaille. */ - -#ifndef PARSER_HEADER_H -# define PARSER_HEADER_H - -#include -#include -#include "stack.hh" - -namespace yy -{ - class position; - class location; -} - -/* First part of user declarations. */ -#line 4 "script-parser.yy" - -#ifdef _MSC_VER -#pragma warning(disable: 4800) -#pragma warning(disable: 4267) -#endif - -#include -#include "node.h" -class compiler; - - -/* Line 35 of lalr1.cc. */ -#line 65 "script-parser.hh" - -#include "location.hh" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 1 -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ -do { \ - if (N) \ - { \ - (Current).begin = (Rhs)[1].begin; \ - (Current).end = (Rhs)[N].end; \ - } \ - else \ - { \ - (Current).begin = (Current).end = (Rhs)[0].end; \ - } \ -} while (false) -#endif - -namespace yy -{ - - /// A Bison parser. - class script_parser - { - public: - /// Symbol semantic values. -#ifndef YYSTYPE - union semantic_type -#line 28 "script-parser.yy" -{ - int ival; - std::string *sval; - - CArgs *args; - CNode *expr; - CAssign *assign; -} -/* Line 35 of lalr1.cc. */ -#line 126 "script-parser.hh" - ; -#else - typedef YYSTYPE semantic_type; -#endif - /// Symbol locations. - typedef location location_type; - /// Tokens. - struct token - { - /* Tokens. */ - enum yytokentype { - END_OF_FILE = 0, - TK_IVAL = 258, - TK_IDENTIFIER = 259, - TK_EQ = 260, - TK_NE = 261, - TK_GE = 262, - TK_LE = 263, - TK_NEWLINE = 264, - TK_IF = 265, - TK_THEN = 266, - TK_ELSE = 267, - TK_ENDIF = 268, - TK_FOR = 269, - TK_TO = 270, - TK_NEXT = 271, - TK_WHILE = 272, - TK_WEND = 273, - TK_END = 274, - TK_RAND = 275, - TK_PRINT = 276, - NEG = 277 - }; - - }; - /// Token type. - typedef token::yytokentype token_type; - - /// Build a parser object. - script_parser (compiler& driver_yyarg); - virtual ~script_parser (); - - /// Parse. - /// \returns 0 iff parsing succeeded. - virtual int parse (); - - /// The current debugging stream. - std::ostream& debug_stream () const; - /// Set the current debugging stream. - void set_debug_stream (std::ostream &); - - /// Type for debugging levels. - typedef int debug_level_type; - /// The current debugging level. - debug_level_type debug_level () const; - /// Set the current debugging level. - void set_debug_level (debug_level_type l); - - private: - /// Report a syntax error. - /// \param loc where the syntax error is found. - /// \param msg a description of the syntax error. - virtual void error (const location_type& loc, const std::string& msg); - - /// Generate an error message. - /// \param state the state where the error occurred. - /// \param tok the look-ahead token. - virtual std::string yysyntax_error_ (int yystate, int tok); - -#if YYDEBUG - /// \brief Report a symbol value on the debug stream. - /// \param yytype The token type. - /// \param yyvaluep Its semantic value. - /// \param yylocationp Its location. - virtual void yy_symbol_value_print_ (int yytype, - const semantic_type* yyvaluep, - const location_type* yylocationp); - /// \brief Report a symbol on the debug stream. - /// \param yytype The token type. - /// \param yyvaluep Its semantic value. - /// \param yylocationp Its location. - virtual void yy_symbol_print_ (int yytype, - const semantic_type* yyvaluep, - const location_type* yylocationp); -#endif /* ! YYDEBUG */ - - - /// State numbers. - typedef int state_type; - /// State stack type. - typedef stack state_stack_type; - /// Semantic value stack type. - typedef stack semantic_stack_type; - /// location stack type. - typedef stack location_stack_type; - - /// The state stack. - state_stack_type yystate_stack_; - /// The semantic value stack. - semantic_stack_type yysemantic_stack_; - /// The location stack. - location_stack_type yylocation_stack_; - - /// Internal symbol numbers. - typedef unsigned char token_number_type; - /* Tables. */ - /// For a state, the index in \a yytable_ of its portion. - static const signed char yypact_[]; - static const signed char yypact_ninf_; - - /// For a state, default rule to reduce. - /// Unless\a yytable_ specifies something else to do. - /// Zero means the default is an error. - static const unsigned char yydefact_[]; - - static const signed char yypgoto_[]; - static const signed char yydefgoto_[]; - - /// What to do in a state. - /// \a yytable_[yypact_[s]]: what to do in state \a s. - /// - if positive, shift that token. - /// - if negative, reduce the rule which number is the opposite. - /// - if zero, do what YYDEFACT says. - static const unsigned char yytable_[]; - static const signed char yytable_ninf_; - - static const signed char yycheck_[]; - - /// For a state, its accessing symbol. - static const unsigned char yystos_[]; - - /// For a rule, its LHS. - static const unsigned char yyr1_[]; - /// For a rule, its RHS length. - static const unsigned char yyr2_[]; - -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE - /// For a symbol, its name in clear. - static const char* const yytname_[]; -#endif - -#if YYERROR_VERBOSE - /// Convert the symbol name \a n to a form suitable for a diagnostic. - virtual std::string yytnamerr_ (const char *n); -#endif - -#if YYDEBUG - /// A type to store symbol numbers and -1. - typedef signed char rhs_number_type; - /// A `-1'-separated list of the rules' RHS. - static const rhs_number_type yyrhs_[]; - /// For each rule, the index of the first RHS symbol in \a yyrhs_. - static const unsigned char yyprhs_[]; - /// For each rule, its source line number. - static const unsigned char yyrline_[]; - /// For each scanner token number, its symbol number. - static const unsigned short int yytoken_number_[]; - /// Report on the debug stream that the rule \a r is going to be reduced. - virtual void yy_reduce_print_ (int r); - /// Print the state stack on the debug stream. - virtual void yystack_print_ (); -#endif - - /// Convert a scanner token number \a t to a symbol number. - token_number_type yytranslate_ (int t); - - /// \brief Reclaim the memory associated to a symbol. - /// \param yymsg Why this token is reclaimed. - /// \param yytype The symbol type. - /// \param yyvaluep Its semantic value. - /// \param yylocationp Its location. - inline void yydestruct_ (const char* yymsg, - int yytype, - semantic_type* yyvaluep, - location_type* yylocationp); - - /// Pop \a n symbols the three stacks. - inline void yypop_ (unsigned int n = 1); - - /* Constants. */ - static const int yyeof_; - /* LAST_ -- Last index in TABLE_. */ - static const int yylast_; - static const int yynnts_; - static const int yyempty_; - static const int yyfinal_; - static const int yyterror_; - static const int yyerrcode_; - static const int yyntokens_; - static const unsigned int yyuser_token_number_max_; - static const token_number_type yyundef_token_; - - /* Debugging. */ - int yydebug_; - std::ostream* yycdebug_; - - - /* User arguments. */ - compiler& driver; - }; -} - - -#endif /* ! defined PARSER_HEADER_H */ diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-parser.output --- a/Bison-Flex/EUC/script-parser.output Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1303 +0,0 @@ -文法 - - 0 $accept: unit "end of file" - - 1 unit: states - 2 | unit states - - 3 states: statement "\n" - 4 | "\n" - - 5 statement: "end" - 6 | assign - 7 | "if" comp_expr "then" - 8 | "else" - 9 | "endif" - 10 | "for" assign "to" expr "step" expr - 11 | "for" assign "to" expr - 12 | "next" - 13 | "while" comp_expr - 14 | "wend" - 15 | "print" args - 16 | error - - 17 assign: value '=' expr - - 18 comp_expr: expr "==" expr - 19 | expr "!=" expr - 20 | expr '>' expr - 21 | expr ">=" expr - 22 | expr '<' expr - 23 | expr "<=" expr - - 24 expr: expr '-' expr - 25 | expr '+' expr - 26 | expr '*' expr - 27 | expr '/' expr - 28 | expr '%' expr - 29 | '-' expr - 30 | '(' expr ')' - 31 | value - 32 | "ival" - 33 | "rand" '(' expr ')' - - 34 value: "identifier" - - 35 args: expr - 36 | args ',' expr - - -出現位置の規則による終端 - -"end of file" (0) 0 -'%' (37) 28 -'(' (40) 30 33 -')' (41) 30 33 -'*' (42) 26 -'+' (43) 25 -',' (44) 36 -'-' (45) 24 29 -'/' (47) 27 -'<' (60) 22 -'=' (61) 17 -'>' (62) 20 -error (256) 16 -"ival" (258) 32 -"identifier" (259) 34 -"==" (260) 18 -"!=" (261) 19 -">=" (262) 21 -"<=" (263) 23 -"\n" (264) 3 4 -"if" (265) 7 -"then" (266) 7 -"else" (267) 8 -"endif" (268) 9 -"for" (269) 10 11 -"to" (270) 10 11 -"next" (271) 12 -"while" (272) 13 -"wend" (273) 14 -"end" (274) 5 -"rand" (275) 33 -"print" (276) 15 -NEG (277) -"step" (278) 10 - - -出現位置の規則による非終端 - -$accept (35) - 左辺: 0 -unit (36) - 左辺: 1 2, 右辺: 0 2 -states (37) - 左辺: 3 4, 右辺: 1 2 -statement (38) - 左辺: 5 6 7 8 9 10 11 12 13 14 15 16, 右辺: 3 -assign (39) - 左辺: 17, 右辺: 6 10 11 -comp_expr (40) - 左辺: 18 19 20 21 22 23, 右辺: 7 13 -expr (41) - 左辺: 24 25 26 27 28 29 30 31 32 33, 右辺: 10 11 17 18 19 20 - 21 22 23 24 25 26 27 28 29 30 33 35 36 -value (42) - 左辺: 34, 右辺: 17 31 -args (43) - 左辺: 35 36, 右辺: 15 36 - - -状態 0 - - 0 $accept: . unit "end of file" - 1 unit: . states - 2 | . unit states - 3 states: . statement "\n" - 4 | . "\n" - 5 statement: . "end" - 6 | . assign - 7 | . "if" comp_expr "then" - 8 | . "else" - 9 | . "endif" - 10 | . "for" assign "to" expr "step" expr - 11 | . "for" assign "to" expr - 12 | . "next" - 13 | . "while" comp_expr - 14 | . "wend" - 15 | . "print" args - 16 | . error - 17 assign: . value '=' expr - 34 value: . "identifier" - - error shift, and go to state 1 - "identifier" shift, and go to state 2 - "\n" shift, and go to state 3 - "if" shift, and go to state 4 - "else" shift, and go to state 5 - "endif" shift, and go to state 6 - "for" shift, and go to state 7 - "next" shift, and go to state 8 - "while" shift, and go to state 9 - "wend" shift, and go to state 10 - "end" shift, and go to state 11 - "print" shift, and go to state 12 - - unit go to state 13 - states go to state 14 - statement go to state 15 - assign go to state 16 - value go to state 17 - - -状態 1 - - 16 statement: error . - - $default reduce using rule 16 (statement) - - -状態 2 - - 34 value: "identifier" . - - $default reduce using rule 34 (value) - - -状態 3 - - 4 states: "\n" . - - $default reduce using rule 4 (states) - - -状態 4 - - 7 statement: "if" . comp_expr "then" - 18 comp_expr: . expr "==" expr - 19 | . expr "!=" expr - 20 | . expr '>' expr - 21 | . expr ">=" expr - 22 | . expr '<' expr - 23 | . expr "<=" expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - comp_expr go to state 22 - expr go to state 23 - value go to state 24 - - -状態 5 - - 8 statement: "else" . - - $default reduce using rule 8 (statement) - - -状態 6 - - 9 statement: "endif" . - - $default reduce using rule 9 (statement) - - -状態 7 - - 10 statement: "for" . assign "to" expr "step" expr - 11 | "for" . assign "to" expr - 17 assign: . value '=' expr - 34 value: . "identifier" - - "identifier" shift, and go to state 2 - - assign go to state 25 - value go to state 17 - - -状態 8 - - 12 statement: "next" . - - $default reduce using rule 12 (statement) - - -状態 9 - - 13 statement: "while" . comp_expr - 18 comp_expr: . expr "==" expr - 19 | . expr "!=" expr - 20 | . expr '>' expr - 21 | . expr ">=" expr - 22 | . expr '<' expr - 23 | . expr "<=" expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - comp_expr go to state 26 - expr go to state 23 - value go to state 24 - - -状態 10 - - 14 statement: "wend" . - - $default reduce using rule 14 (statement) - - -状態 11 - - 5 statement: "end" . - - $default reduce using rule 5 (statement) - - -状態 12 - - 15 statement: "print" . args - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - 35 args: . expr - 36 | . args ',' expr - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 27 - value go to state 24 - args go to state 28 - - -状態 13 - - 0 $accept: unit . "end of file" - 2 unit: unit . states - 3 states: . statement "\n" - 4 | . "\n" - 5 statement: . "end" - 6 | . assign - 7 | . "if" comp_expr "then" - 8 | . "else" - 9 | . "endif" - 10 | . "for" assign "to" expr "step" expr - 11 | . "for" assign "to" expr - 12 | . "next" - 13 | . "while" comp_expr - 14 | . "wend" - 15 | . "print" args - 16 | . error - 17 assign: . value '=' expr - 34 value: . "identifier" - - "end of file" shift, and go to state 29 - error shift, and go to state 1 - "identifier" shift, and go to state 2 - "\n" shift, and go to state 3 - "if" shift, and go to state 4 - "else" shift, and go to state 5 - "endif" shift, and go to state 6 - "for" shift, and go to state 7 - "next" shift, and go to state 8 - "while" shift, and go to state 9 - "wend" shift, and go to state 10 - "end" shift, and go to state 11 - "print" shift, and go to state 12 - - states go to state 30 - statement go to state 15 - assign go to state 16 - value go to state 17 - - -状態 14 - - 1 unit: states . - - $default reduce using rule 1 (unit) - - -状態 15 - - 3 states: statement . "\n" - - "\n" shift, and go to state 31 - - -状態 16 - - 6 statement: assign . - - $default reduce using rule 6 (statement) - - -状態 17 - - 17 assign: value . '=' expr - - '=' shift, and go to state 32 - - -状態 18 - - 32 expr: "ival" . - - $default reduce using rule 32 (expr) - - -状態 19 - - 33 expr: "rand" . '(' expr ')' - - '(' shift, and go to state 33 - - -状態 20 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 29 | '-' . expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 34 - value go to state 24 - - -状態 21 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 30 | '(' . expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 35 - value go to state 24 - - -状態 22 - - 7 statement: "if" comp_expr . "then" - - "then" shift, and go to state 36 - - -状態 23 - - 18 comp_expr: expr . "==" expr - 19 | expr . "!=" expr - 20 | expr . '>' expr - 21 | expr . ">=" expr - 22 | expr . '<' expr - 23 | expr . "<=" expr - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - "==" shift, and go to state 37 - "!=" shift, and go to state 38 - ">=" shift, and go to state 39 - "<=" shift, and go to state 40 - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - '>' shift, and go to state 46 - '<' shift, and go to state 47 - - -状態 24 - - 31 expr: value . - - $default reduce using rule 31 (expr) - - -状態 25 - - 10 statement: "for" assign . "to" expr "step" expr - 11 | "for" assign . "to" expr - - "to" shift, and go to state 48 - - -状態 26 - - 13 statement: "while" comp_expr . - - $default reduce using rule 13 (statement) - - -状態 27 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 35 args: expr . ["\n", ','] - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 35 (args) - - -状態 28 - - 15 statement: "print" args . ["\n"] - 36 args: args . ',' expr - - ',' shift, and go to state 49 - - $default reduce using rule 15 (statement) - - -状態 29 - - 0 $accept: unit "end of file" . - - $default accept - - -状態 30 - - 2 unit: unit states . - - $default reduce using rule 2 (unit) - - -状態 31 - - 3 states: statement "\n" . - - $default reduce using rule 3 (states) - - -状態 32 - - 17 assign: value '=' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 50 - value go to state 24 - - -状態 33 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 33 | "rand" '(' . expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 51 - value go to state 24 - - -状態 34 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 29 | '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - - $default reduce using rule 29 (expr) - - Conflict between rule 29 and token '+' resolved as reduce ('+' < NEG). - Conflict between rule 29 and token '-' resolved as reduce ('-' < NEG). - Conflict between rule 29 and token '*' resolved as reduce ('*' < NEG). - Conflict between rule 29 and token '/' resolved as reduce ('/' < NEG). - Conflict between rule 29 and token '%' resolved as reduce ('%' < NEG). - - -状態 35 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 30 | '(' expr . ')' - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - ')' shift, and go to state 52 - - -状態 36 - - 7 statement: "if" comp_expr "then" . - - $default reduce using rule 7 (statement) - - -状態 37 - - 18 comp_expr: expr "==" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 53 - value go to state 24 - - -状態 38 - - 19 comp_expr: expr "!=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 54 - value go to state 24 - - -状態 39 - - 21 comp_expr: expr ">=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 55 - value go to state 24 - - -状態 40 - - 23 comp_expr: expr "<=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 56 - value go to state 24 - - -状態 41 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 25 | expr '+' . expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 57 - value go to state 24 - - -状態 42 - - 24 expr: . expr '-' expr - 24 | expr '-' . expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 58 - value go to state 24 - - -状態 43 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 26 | expr '*' . expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 59 - value go to state 24 - - -状態 44 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 27 | expr '/' . expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 60 - value go to state 24 - - -状態 45 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 28 | expr '%' . expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 61 - value go to state 24 - - -状態 46 - - 20 comp_expr: expr '>' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 62 - value go to state 24 - - -状態 47 - - 22 comp_expr: expr '<' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 63 - value go to state 24 - - -状態 48 - - 10 statement: "for" assign "to" . expr "step" expr - 11 | "for" assign "to" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 64 - value go to state 24 - - -状態 49 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - 36 args: args ',' . expr - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 65 - value go to state 24 - - -状態 50 - - 17 assign: value '=' expr . ["\n", "to"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 17 (assign) - - -状態 51 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 33 | "rand" '(' expr . ')' - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - ')' shift, and go to state 66 - - -状態 52 - - 30 expr: '(' expr ')' . - - $default reduce using rule 30 (expr) - - -状態 53 - - 18 comp_expr: expr "==" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 18 (comp_expr) - - -状態 54 - - 19 comp_expr: expr "!=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 19 (comp_expr) - - -状態 55 - - 21 comp_expr: expr ">=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 21 (comp_expr) - - -状態 56 - - 23 comp_expr: expr "<=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 23 (comp_expr) - - -状態 57 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 25 | expr '+' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 25 (expr) - - Conflict between rule 25 and token '+' resolved as reduce (%left '+'). - Conflict between rule 25 and token '-' resolved as reduce (%left '-'). - Conflict between rule 25 and token '*' resolved as shift ('+' < '*'). - Conflict between rule 25 and token '/' resolved as shift ('+' < '/'). - Conflict between rule 25 and token '%' resolved as shift ('+' < '%'). - - -状態 58 - - 24 expr: expr . '-' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 24 | expr '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 24 (expr) - - Conflict between rule 24 and token '+' resolved as reduce (%left '+'). - Conflict between rule 24 and token '-' resolved as reduce (%left '-'). - Conflict between rule 24 and token '*' resolved as shift ('-' < '*'). - Conflict between rule 24 and token '/' resolved as shift ('-' < '/'). - Conflict between rule 24 and token '%' resolved as shift ('-' < '%'). - - -状態 59 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 26 | expr '*' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 27 | expr . '/' expr - 28 | expr . '%' expr - - $default reduce using rule 26 (expr) - - Conflict between rule 26 and token '+' resolved as reduce ('+' < '*'). - Conflict between rule 26 and token '-' resolved as reduce ('-' < '*'). - Conflict between rule 26 and token '*' resolved as reduce (%left '*'). - Conflict between rule 26 and token '/' resolved as reduce (%left '/'). - Conflict between rule 26 and token '%' resolved as reduce (%left '%'). - - -状態 60 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 27 | expr '/' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 28 | expr . '%' expr - - $default reduce using rule 27 (expr) - - Conflict between rule 27 and token '+' resolved as reduce ('+' < '/'). - Conflict between rule 27 and token '-' resolved as reduce ('-' < '/'). - Conflict between rule 27 and token '*' resolved as reduce (%left '*'). - Conflict between rule 27 and token '/' resolved as reduce (%left '/'). - Conflict between rule 27 and token '%' resolved as reduce (%left '%'). - - -状態 61 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 28 | expr '%' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - - $default reduce using rule 28 (expr) - - Conflict between rule 28 and token '+' resolved as reduce ('+' < '%'). - Conflict between rule 28 and token '-' resolved as reduce ('-' < '%'). - Conflict between rule 28 and token '*' resolved as reduce (%left '*'). - Conflict between rule 28 and token '/' resolved as reduce (%left '/'). - Conflict between rule 28 and token '%' resolved as reduce (%left '%'). - - -状態 62 - - 20 comp_expr: expr '>' expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 20 (comp_expr) - - -状態 63 - - 22 comp_expr: expr '<' expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 22 (comp_expr) - - -状態 64 - - 10 statement: "for" assign "to" expr . "step" expr - 11 | "for" assign "to" expr . ["\n"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - "step" shift, and go to state 67 - - $default reduce using rule 11 (statement) - - -状態 65 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 36 args: args ',' expr . ["\n", ','] - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 36 (args) - - -状態 66 - - 33 expr: "rand" '(' expr ')' . - - $default reduce using rule 33 (expr) - - -状態 67 - - 10 statement: "for" assign "to" expr "step" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 - - expr go to state 68 - value go to state 24 - - -状態 68 - - 10 statement: "for" assign "to" expr "step" expr . ["\n"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 10 (statement) diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-parser.yy --- a/Bison-Flex/EUC/script-parser.yy Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -%skeleton "lalr1.cc" -%define "parser_class_name" "script_parser" -%defines -%{ -#ifdef _MSC_VER -#pragma warning(disable: 4800) -#pragma warning(disable: 4267) -#endif - -#include -#include "node.h" -class compiler; -%} -// The parsing context. -%parse-param { compiler& driver } -%lex-param { compiler& driver } -%locations -//%expect 7 -%initial-action -{ - // ロケーション初期化 - @$.begin.filename = @$.end.filename = &driver.get_filename(); -}; -// %debug -%error-verbose -// Symbols. -%union -{ - int ival; - std::string *sval; - - CArgs *args; - CNode *expr; - CAssign *assign; -} -%{ -#include "compiler.h" -%} - -%token END_OF_FILE 0 "end of file" -%token TK_IVAL "ival" -%token TK_IDENTIFIER "identifier" -%token TK_EQ "==" -%token TK_NE "!=" -%token TK_GE ">=" -%token TK_LE "<=" -%token TK_NEWLINE "\n" - -%token TK_IF "if" -%token TK_THEN "then" -%token TK_ELSE "else" -%token TK_ENDIF "endif" -%token TK_FOR "for" -%token TK_TO "to" -%token TK_NEXT "next" -%token TK_WHILE "while" -%token TK_WEND "wend" -%token TK_END "end" -%token TK_RAND "rand" -%token TK_PRINT "print" - -%type expr -%type comp_expr -%type value -%type assign -%type args - -%destructor { delete $$; } "identifier" - -%destructor { delete $$; } args -%destructor { delete $$; } assign -%destructor { delete $$; } value -%destructor { delete $$; } expr -%destructor { delete $$; } comp_expr - -%left '+' '-'; -%left '*' '/' '%'; -%left NEG; -%% -%start unit; - -unit : states - | unit states - ; - -states : statement "\n" - | "\n" - ; - -statement : "end" { driver.EndStatement(@1); } - | assign { driver.AssignStatement(@1, $1); } - | "if" comp_expr "then" { driver.IfStatement(@1, $2); } - | "else" { driver.ElseStatement(@1); } - | "endif" { driver.EndifStatement(@1); } - | "for" assign "to" expr "step" expr { driver.ForStatement(@1, $2, $4, $6); } - | "for" assign "to" expr { driver.ForStatement(@1, $2, $4, NULL); } - | "next" { driver.NextStatement(@1); } - | "while" comp_expr { driver.WhileStatement(@1, $2); } - | "wend" { driver.WendStatement(@1); } - | "print" args { driver.PrintStatement(@1, $2); } - | error /* エラーの場合 */ - ; - -assign : value '=' expr { $$ = new CAssign(@1, '=', $1, $3); } - ; - -comp_expr : expr "==" expr { $$ = CNode::MakeNode(driver, @1, OP_EQ, $1, $3); } - | expr "!=" expr { $$ = CNode::MakeNode(driver, @1, OP_NE, $1, $3); } - | expr '>' expr { $$ = CNode::MakeNode(driver, @1, OP_GT, $1, $3); } - | expr ">=" expr { $$ = CNode::MakeNode(driver, @1, OP_GE, $1, $3); } - | expr '<' expr { $$ = CNode::MakeNode(driver, @1, OP_LT, $1, $3); } - | expr "<=" expr { $$ = CNode::MakeNode(driver, @1, OP_LE, $1, $3); } - ; - -expr : expr '-' expr { $$ = CNode::MakeNode(driver, @1, OP_MINUS, $1, $3); } - | expr '+' expr { $$ = CNode::MakeNode(driver, @1, OP_PLUS, $1, $3); } - | expr '*' expr { $$ = CNode::MakeNode(driver, @1, OP_TIMES, $1, $3); } - | expr '/' expr { $$ = CNode::MakeNode(driver, @1, OP_DIVIDE, $1, $3); } - | expr '%' expr { $$ = CNode::MakeNode(driver, @1, OP_MOD, $1, $3); } - | '-' expr %prec NEG { $$ = CNode::MakeNode(driver, @1, OP_NEG, $2); } - | '(' expr ')' { $$ = $2; } - | value { $$ = $1; } - | "ival" { $$ = new CNode(@1, OP_CONST, $1); } - | "rand" '(' expr ')' { $$ = new CNode(@1, OP_RANDFUNC, $3); } - ; - -value : "identifier" { $$ = new CValueNode(@1, $1); } - ; - -args : expr { $$ = new CArgs(@1, $1); } - | args ',' expr { $$ = $1->Add(@3, $3); } - ; - -%% -void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) -{ - driver.error(l, m); -} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-scanner.cc --- a/Bison-Flex/EUC/script-scanner.cc Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1822 +0,0 @@ -#line 2 "script-scanner.cc" - -#line 4 "script-scanner.cc" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 33 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#define YY_BUF_SIZE 16384 -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() 1 -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 31 -#define YY_END_OF_BUFFER 32 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[75] = - { 0, - 0, 0, 29, 29, 32, 28, 24, 18, 28, 19, - 2, 26, 25, 17, 19, 19, 19, 27, 28, 28, - 27, 27, 27, 27, 27, 27, 27, 27, 29, 30, - 24, 21, 25, 23, 20, 22, 27, 16, 1, 27, - 27, 27, 4, 27, 27, 27, 27, 27, 9, 27, - 27, 29, 27, 13, 8, 27, 27, 27, 3, 27, - 27, 27, 6, 27, 10, 27, 14, 5, 12, 27, - 7, 15, 11, 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 1, 5, 1, 6, 1, 7, 6, - 6, 6, 6, 6, 6, 1, 6, 8, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 10, 1, 11, - 12, 13, 1, 1, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 1, 15, 1, 16, 14, 1, 17, 14, 14, 18, - - 19, 20, 14, 21, 22, 14, 14, 23, 24, 25, - 26, 27, 14, 28, 29, 30, 14, 14, 31, 32, - 14, 14, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[33] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 3, 3, 1, - 1, 1, 1, 3, 1, 1, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3 - } ; - -static yyconst flex_int16_t yy_base[78] = - { 0, - 0, 0, 83, 82, 84, 87, 81, 87, 70, 87, - 87, 87, 25, 87, 69, 68, 67, 0, 75, 72, - 12, 50, 55, 55, 45, 19, 18, 21, 0, 87, - 70, 87, 37, 87, 87, 87, 0, 87, 87, 42, - 52, 41, 0, 36, 45, 41, 41, 45, 0, 38, - 40, 0, 42, 38, 0, 29, 33, 39, 0, 31, - 37, 31, 0, 33, 0, 21, 0, 0, 0, 24, - 0, 0, 0, 87, 46, 38, 49 - } ; - -static yyconst flex_int16_t yy_def[78] = - { 0, - 74, 1, 75, 75, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 76, 74, 74, - 76, 76, 76, 76, 76, 76, 76, 76, 77, 74, - 74, 74, 74, 74, 74, 74, 76, 74, 74, 76, - 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 77, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 76, 76, 0, 74, 74, 74 - } ; - -static yyconst flex_int16_t yy_nxt[120] = - { 0, - 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 18, 18, 21, 22, - 18, 23, 18, 18, 24, 18, 25, 26, 18, 27, - 28, 18, 33, 33, 40, 46, 41, 47, 48, 50, - 37, 51, 73, 49, 33, 33, 29, 29, 29, 52, - 72, 52, 71, 70, 69, 68, 67, 66, 65, 64, - 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, - 53, 31, 45, 44, 43, 42, 39, 38, 36, 35, - 34, 32, 31, 74, 30, 30, 5, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74 - } ; - -static yyconst flex_int16_t yy_chk[120] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 13, 13, 21, 26, 21, 26, 27, 28, - 76, 28, 70, 27, 33, 33, 75, 75, 75, 77, - 66, 77, 64, 62, 61, 60, 58, 57, 56, 54, - 53, 51, 50, 48, 47, 46, 45, 44, 42, 41, - 40, 31, 25, 24, 23, 22, 20, 19, 17, 16, - 15, 9, 7, 5, 4, 3, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "script-scanner.ll" -#line 2 "script-scanner.ll" -#include -#include -#include -#include -#include "compiler.h" -#include "script-parser.hh" - -#ifdef _MSC_VER -#pragma warning(disable:4018) -#pragma warning(disable:4102) -#pragma warning(disable:4244) -#pragma warning(disable:4267) -#pragma warning(disable:4996) -#endif - -#undef yywrap -#define yywrap() 1 - -#define yyterminate() return token::END_OF_FILE -#define YY_NO_UNISTD_H 1 - -#line 38 "script-scanner.ll" -#define YY_USER_ACTION yylloc->columns(yyleng); -#line 529 "script-scanner.cc" - -#define INITIAL 0 -#define COMMENT 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 40 "script-scanner.ll" - - - typedef yy::script_parser::token token; - - yylloc->step(); - - std::string string_buffer; - -#line 690 "script-scanner.cc" - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_current_state != 74 ); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 49 "script-scanner.ll" -{ yylloc->step(); BEGIN(COMMENT); } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 50 "script-scanner.ll" -{ yylloc->step(); BEGIN(COMMENT); } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 51 "script-scanner.ll" -{ yylloc->step(); BEGIN(COMMENT); } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 53 "script-scanner.ll" -return token::TK_IF; - YY_BREAK -case 5: -YY_RULE_SETUP -#line 54 "script-scanner.ll" -return token::TK_THEN; - YY_BREAK -case 6: -YY_RULE_SETUP -#line 55 "script-scanner.ll" -return token::TK_ELSE; - YY_BREAK -case 7: -YY_RULE_SETUP -#line 56 "script-scanner.ll" -return token::TK_ENDIF; - YY_BREAK -case 8: -YY_RULE_SETUP -#line 57 "script-scanner.ll" -return token::TK_FOR; - YY_BREAK -case 9: -YY_RULE_SETUP -#line 58 "script-scanner.ll" -return token::TK_TO; - YY_BREAK -case 10: -YY_RULE_SETUP -#line 59 "script-scanner.ll" -return token::TK_NEXT; - YY_BREAK -case 11: -YY_RULE_SETUP -#line 60 "script-scanner.ll" -return token::TK_WHILE; - YY_BREAK -case 12: -YY_RULE_SETUP -#line 61 "script-scanner.ll" -return token::TK_WEND; - YY_BREAK -case 13: -YY_RULE_SETUP -#line 62 "script-scanner.ll" -return token::TK_END; - YY_BREAK -case 14: -YY_RULE_SETUP -#line 63 "script-scanner.ll" -return token::TK_RAND; - YY_BREAK -case 15: -YY_RULE_SETUP -#line 64 "script-scanner.ll" -return token::TK_PRINT; - YY_BREAK -case 16: -/* rule 16 can match eol */ -YY_RULE_SETUP -#line 66 "script-scanner.ll" -yylloc->lines(); - YY_BREAK -case 17: -YY_RULE_SETUP -#line 68 "script-scanner.ll" -return token::TK_NEWLINE; - YY_BREAK -case 18: -/* rule 18 can match eol */ -YY_RULE_SETUP -#line 69 "script-scanner.ll" -{ yylloc->lines(); return token::TK_NEWLINE; } - YY_BREAK -case 19: -YY_RULE_SETUP -#line 70 "script-scanner.ll" -return yy::script_parser::token_type(yytext[0]); - YY_BREAK -case 20: -YY_RULE_SETUP -#line 72 "script-scanner.ll" -return token::TK_EQ; - YY_BREAK -case 21: -YY_RULE_SETUP -#line 73 "script-scanner.ll" -return token::TK_NE; - YY_BREAK -case 22: -YY_RULE_SETUP -#line 74 "script-scanner.ll" -return token::TK_GE; - YY_BREAK -case 23: -YY_RULE_SETUP -#line 75 "script-scanner.ll" -return token::TK_LE; - YY_BREAK -case 24: -YY_RULE_SETUP -#line 77 "script-scanner.ll" -yylloc->step(); - YY_BREAK -case 25: -YY_RULE_SETUP -#line 78 "script-scanner.ll" -{ - errno = 0; - long n = strtol(yytext, NULL, 10); - if (n < LONG_MIN || n > LONG_MAX || errno == ERANGE) - driver.error(*yylloc, "整数が範囲外です。"); - yylval->ival = n; - return token::TK_IVAL; - } - YY_BREAK -case 26: -YY_RULE_SETUP -#line 86 "script-scanner.ll" -{ - yylval->ival = 0; - return token::TK_IVAL; - } - YY_BREAK -case 27: -YY_RULE_SETUP -#line 90 "script-scanner.ll" -{ - yylval->sval = new std::string(yytext); - return token::TK_IDENTIFIER; - } - YY_BREAK -case 28: -YY_RULE_SETUP -#line 94 "script-scanner.ll" -driver.error(*yylloc, "この文字を識別子で使用することはできません。"); - YY_BREAK - - -case 29: -YY_RULE_SETUP -#line 97 "script-scanner.ll" - - YY_BREAK -case 30: -/* rule 30 can match eol */ -YY_RULE_SETUP -#line 98 "script-scanner.ll" -{ - yylloc->lines(); - yylloc->step(); - BEGIN(INITIAL); - } - YY_BREAK - -case 31: -YY_RULE_SETUP -#line 104 "script-scanner.ll" -ECHO; - YY_BREAK -#line 947 "script-scanner.cc" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(COMMENT): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 74); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - int num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param line_number - * - */ -void yyset_lineno (int line_number ) -{ - - yylineno = line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * in_str ) -{ - yyin = in_str ; -} - -void yyset_out (FILE * out_str ) -{ - yyout = out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int bdebug ) -{ - yy_flex_debug = bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 104 "script-scanner.ll" - - - -void compiler::scan_begin() -{ - if ((yyin = fopen(file.c_str(), "r")) == 0) - error(file + " がオープンできません。"); -} - -void compiler::scan_end() -{ - fclose(yyin); - yylex_destroy(); -} - diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script-scanner.ll --- a/Bison-Flex/EUC/script-scanner.ll Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -%{ -#include -#include -#include -#include -#include "compiler.h" -#include "script-parser.hh" - -#ifdef _MSC_VER -#pragma warning(disable:4018) -#pragma warning(disable:4102) -#pragma warning(disable:4244) -#pragma warning(disable:4267) -#pragma warning(disable:4996) -#endif - -#undef yywrap -#define yywrap() 1 - -#define yyterminate() return token::END_OF_FILE -%} - -%option noyywrap nounput batch -%option never-interactive -%option noyy_scan_buffer -%option noyy_scan_bytes -%option noyy_scan_string -%option 8bit -%option nounistd - -id [a-zA-Z_][a-zA-Z_0-9]* -int [1-9][0-9]* -blank [ \t] - -%x COMMENT - -%{ -#define YY_USER_ACTION yylloc->columns(yyleng); -%} -%% -%{ - typedef yy::script_parser::token token; - - yylloc->step(); - - std::string string_buffer; -%} -{ - "^#" { yylloc->step(); BEGIN(COMMENT); } - "'" { yylloc->step(); BEGIN(COMMENT); } - "rem" { yylloc->step(); BEGIN(COMMENT); } - - "if" return token::TK_IF; - "then" return token::TK_THEN; - "else" return token::TK_ELSE; - "endif" return token::TK_ENDIF; - "for" return token::TK_FOR; - "to" return token::TK_TO; - "next" return token::TK_NEXT; - "while" return token::TK_WHILE; - "wend" return token::TK_WEND; - "end" return token::TK_END; - "rand" return token::TK_RAND; - "print" return token::TK_PRINT; - - \\\n yylloc->lines(); - - : return token::TK_NEWLINE; - \n { yylloc->lines(); return token::TK_NEWLINE; } - [-+*/%=,()<>] return yy::script_parser::token_type(yytext[0]); - - "==" return token::TK_EQ; - "!=" return token::TK_NE; - ">=" return token::TK_GE; - "<=" return token::TK_LE; - - {blank}+ yylloc->step(); - {int} { - errno = 0; - long n = strtol(yytext, NULL, 10); - if (n < LONG_MIN || n > LONG_MAX || errno == ERANGE) - driver.error(*yylloc, "整数が範囲外です。"); - yylval->ival = n; - return token::TK_IVAL; - } - "0" { - yylval->ival = 0; - return token::TK_IVAL; - } - {id} { - yylval->sval = new std::string(yytext); - return token::TK_IDENTIFIER; - } - . driver.error(*yylloc, "この文字を識別子で使用することはできません。"); -} -{ - [^\n]* - \n { - yylloc->lines(); - yylloc->step(); - BEGIN(INITIAL); - } -} -%% - -void compiler::scan_begin() -{ - if ((yyin = fopen(file.c_str(), "r")) == 0) - error(file + " がオープンできません。"); -} - -void compiler::scan_end() -{ - fclose(yyin); - yylex_destroy(); -} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/script.cpp --- a/Bison-Flex/EUC/script.cpp Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#include -#include "compiler.h" -#include "vm.h" - -int main(int argc, char *argv[]) -{ - for (++argv; argv[0]; ++argv) { - vm::data data; - bool compile_result; - { - compiler driver; - compile_result = driver.compile(*argv, data); -#ifdef _DEBUG - if (compile_result) - driver.debug_dump(); -#endif - } - if (compile_result) { - vm::vcpu machine(data); - int result = machine.run(); - std::cout << "result = " << result << std::endl; - } - } - return 0; -} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/stack.hh --- a/Bison-Flex/EUC/stack.hh Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.3. */ - -/* Stack handling for Bison parsers in C++ - - Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -#ifndef BISON_STACK_HH -# define BISON_STACK_HH - -#include - -namespace yy -{ - template > - class stack - { - public: - - // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; - - stack () : seq_ () - { - } - - stack (unsigned int n) : seq_ (n) - { - } - - inline - T& - operator [] (unsigned int i) - { - return seq_[i]; - } - - inline - const T& - operator [] (unsigned int i) const - { - return seq_[i]; - } - - inline - void - push (const T& t) - { - seq_.push_front (t); - } - - inline - void - pop (unsigned int n = 1) - { - for (; n; --n) - seq_.pop_front (); - } - - inline - unsigned int - height () const - { - return seq_.size (); - } - - inline const_iterator begin () const { return seq_.rbegin (); } - inline const_iterator end () const { return seq_.rend (); } - - private: - - S seq_; - }; - - /// Present a slice of the top of a stack. - template > - class slice - { - public: - - slice (const S& stack, - unsigned int range) : stack_ (stack), - range_ (range) - { - } - - inline - const T& - operator [] (unsigned int i) const - { - return stack_[range_ - i]; - } - - private: - - const S& stack_; - unsigned int range_; - }; -} - -#endif // not BISON_STACK_HH diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/vm.cpp --- a/Bison-Flex/EUC/vm.cpp Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,222 +0,0 @@ -// -// 仮想CPU -// -// 関数ポインタベースでの実装例 -// -// (c)2008 Chihiro.SAKAMOTO HyperWorks -// -#include -#include "vm.h" - -namespace vm { - - // 0除算例外 - class devide_by_zero: public std::exception { - public: - const char *what() const throw() - { - return "devide by zero"; - } - } ; - - void (vcpu::*vcpu::cmd_[])() = { - #define VM_EXECTABLE - #include "vm_code.h" - #undef VM_EXECTABLE - } ; - - // 実行 - int vcpu::run() - { - command_ = data_.command_; // プログラム格納位置 - command_size_ = data_.command_size_; // プログラムの大きさ - - global_value.resize(data_.value_size_); // 外部変数テーブル確保 - command_ptr_ = command_; // プログラムカウンター初期化 - - active = true; // Haltしていない - - try { - while (active) { // Haltするまでループ - int op = *command_ptr_++; - (this->*cmd_[op])(); - } - } - catch (const std::exception &e) { - std::cerr << "例外発生(" << e.what() << ")" << std::endl; - return -1; - } - return 0; - } - - // 定数Push - void vcpu::PushConst() - { - push(value()); - } - - // 変数Push - void vcpu::PushValue() - { - push(global_value[value()]); - } - - // 変数にPop - void vcpu::PopValue() - { - global_value[value()] = top(); pop(); - } - - // 空Pop(スタックトップを捨てる) - void vcpu::OpPop() - { - pop(); - } - - // 単項マイナス - void vcpu::OpNeg() - { - top() = -top(); - } - - // == - void vcpu::OpEq() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs == rhs); - } - - // != - void vcpu::OpNe() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs != rhs); - } - - // > - void vcpu::OpGt() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs > rhs); - } - - // >= - void vcpu::OpGe() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs >= rhs); - } - - // < - void vcpu::OpLt() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs < rhs); - } - - // <= - void vcpu::OpLe() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs <= rhs); - } - - // + - void vcpu::OpAdd() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs + rhs); - } - - // - - void vcpu::OpSub() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs - rhs); - } - - // * - void vcpu::OpMul() - { - int rhs = top(); pop(); - int lhs = top(); pop(); - push(lhs * rhs); - } - - // / - void vcpu::OpDiv() - { - int rhs = top(); pop(); - if (rhs == 0) - throw devide_by_zero(); - int lhs = top(); pop(); - push(lhs / rhs); - } - - // % - void vcpu::OpMod() - { - int rhs = top(); pop(); - if (rhs == 0) - throw devide_by_zero(); - int lhs = top(); pop(); - push(lhs % rhs); - } - - // 無条件ジャンプ - void vcpu::OpJmp() - { - jmp(value()); - } - - // 真の時ジャンプ - void vcpu::OpJmpC() - { - int addr = value(); - int cond = top(); pop(); - if (cond) - jmp(addr); - } - - // 偽の時ジャンプ - void vcpu::OpJmpNC() - { - int addr = value(); - int cond = top(); pop(); - if (!cond) - jmp(addr); - } - - // 仮想CPUプログラム停止 - void vcpu::OpHalt() - { - active = false; - } - - void vcpu::OpRand() - { - int range = top(); pop(); - int value = (range <= 0)? 0: (rand() % range); - push(value); - } - - void vcpu::OpPrint() - { - int count = value(); - while (count--) { - std::cout << top(); - pop(); - if (count) - std::cout << ", "; - } - std::cout << std::endl; - } -} diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/vm.h --- a/Bison-Flex/EUC/vm.h Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -#ifndef __VM_H__ -#define __VM_H__ - -#include -#include "vm_value.h" - -#define VM_ENUMDEF -enum { -#include "vm_code.h" - VM_MAXCOMMAND, -} ; -#undef VM_ENUMDEF - -namespace vm { - - class data { - public: - data(): command_(0) - { - } - ~data() - { - delete[] command_; - } - - public: - unsigned char *command_; // コマンドテーブル - int command_size_; // コマンドサイズ - int value_size_; // グローバル変数サイズ - } ; - - class vcpu { - public: - const static int STACK_SIZE = 1000; - - public: - vcpu(data &mem) - : data_(mem) - { - } - ~vcpu() - { - } - - int run(); - - private: -#define VM_EXEC -#include "vm_code.h" -#undef VM_EXEC - - private: - int value() { int v = *(int *)command_ptr_; command_ptr_ += 4; return v; } - int addr() const { return (int)(command_ptr_ - command_); } - void jmp(int addr) { command_ptr_ = command_ + addr; } - void push(int v) { stack.push(v); } - void pop() { stack.pop(); } - const int top() const { return stack.top(); } - int &top() { return stack.top(); } - - private: - data &data_; - unsigned char *command_; - unsigned char *command_ptr_; - int command_size_; - bool active; - - vm::stack stack; - std::vector global_value; - - static void (vcpu::*cmd_[])(); - } ; - -} - -#endif diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/vm_code.h --- a/Bison-Flex/EUC/vm_code.h Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -#ifdef VM_ENUMDEF -#define VMCODE0(code_, name_) code_, -#define VMCODE1(code_, name_) code_, -#endif -#ifdef VM_CREATE -#define VMCODE0(code_, name_) void name_() { statement.push_back(CVMCode(code_)); } -#define VMCODE1(code_, name_) void name_(int arg1) { statement.push_back(CVMCode(code_, arg1)); } -#endif -#ifdef VM_EXEC -#define VMCODE0(code_, name_) void name_(); -#define VMCODE1(code_, name_) void name_(); -#endif -#ifdef VM_EXECTABLE -#define VMCODE0(code_, name_) &vcpu::name_, -#define VMCODE1(code_, name_) &vcpu::name_, -#endif -#ifdef VM_NAMETABLE -#define VMCODE0(code_, name_) #name_, -#define VMCODE1(code_, name_) #name_, -#endif - -VMCODE1(VM_PUSHCONST, PushConst) -VMCODE1(VM_PUSHVALUE, PushValue) -VMCODE1(VM_POPVALUE, PopValue) -VMCODE0(VM_POP, OpPop) -VMCODE0(VM_NEG, OpNeg) -VMCODE0(VM_EQ, OpEq) -VMCODE0(VM_NE, OpNe) -VMCODE0(VM_GT, OpGt) -VMCODE0(VM_GE, OpGe) -VMCODE0(VM_LT, OpLt) -VMCODE0(VM_LE, OpLe) -VMCODE0(VM_ADD, OpAdd) -VMCODE0(VM_SUB, OpSub) -VMCODE0(VM_MUL, OpMul) -VMCODE0(VM_DIV, OpDiv) -VMCODE0(VM_MOD, OpMod) -VMCODE1(VM_JMP, OpJmp) -VMCODE1(VM_JMPC, OpJmpC) -VMCODE1(VM_JMPNC, OpJmpNC) -VMCODE1(VM_PRINT, OpPrint) -VMCODE0(VM_RAND, OpRand) -VMCODE0(VM_HALT, OpHalt) - -#undef VMCODE0 -#undef VMCODE1 diff -r 3f4ade70b4d2 -r a3ea4c73696b Bison-Flex/EUC/vm_value.h --- a/Bison-Flex/EUC/vm_value.h Tue May 10 06:19:04 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -#ifndef __vm_value_h__ -#define __vm_value_h__ - -#include -#include - -namespace vm { - - class stack_overflow: public std::exception { - public: - const char *what() const throw() - { - return "stack overflow"; - } - } ; - - // 固定サイズのスタック - // スタックオーバーフローの場合は例外を送出 - - template< typename Ty, int Size > - class stack { - public: - stack(): size_(0) - { - } - - ~stack() - { - resize(0); - } - - void push(const Ty& value) - { - if (Size <= size_) - throw stack_overflow(); - *(::new(data_[size_++]) Ty) = value; - } - - void pop() - { - ((Ty *)data_[--size_])->~Ty(); - } - - void pop(int count) - { - resize(size_ - count); - } - - void resize(int newsize) - { - int oldsize = size_; - - if (oldsize > newsize) { - for (int i = newsize; i < oldsize; ++i) - ((Ty *)data_[i])->~Ty(); - } - if (oldsize < newsize) { - if (Size < newsize) - throw stack_overflow(); - for (int i = oldsize; i < newsize; ++i) - ::new(data_[i]) Ty; - } - size_ = newsize; - } - - const Ty& top() const { return *(const Ty *)data_[size_ - 1]; } - Ty& top() { return *(Ty *)data_[size_ - 1]; } - - bool overflow() const { return size_ >= Size; } - bool empty() const { return size_ == 0; } - int size() const { return size_; } - - const Ty& operator[](int index) const { return *(const Ty *)data_[index]; } - Ty& operator[](int index) { return *(Ty *)data_[index]; } - - protected: - char data_[Size][sizeof(Ty)]; - int size_; - } ; - -} // namespace - -#endif