diff --git a/include/BasicBlock.h b/include/BasicBlock.h index b8d6b78..92bcb22 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -14,14 +14,21 @@ using std::set; class Function; class Instruction; -class BaseBlock +class BaseBlock :public Value { public: enum BlockType { Basic, If, - While, + While + }; + + const map name = + { + {Basic,"Basic"}, + {If,"If"}, + {While,"While"} }; void addInst(Instruction* inst) { insrList.push_back(inst); }; @@ -32,9 +39,9 @@ class BaseBlock std::vector insrList; std::vector pre_bbs_; std::vector succ_bbs_; - void debugPrint() {}; + void debugPrint(); - BaseBlock() + BaseBlock():Value(voidType) { parent = nullptr; } diff --git a/include/ConstantValue.h b/include/ConstantValue.h index 12207f2..43e757a 100644 --- a/include/ConstantValue.h +++ b/include/ConstantValue.h @@ -11,14 +11,14 @@ class ConstantValue:public Value typeInt, typeArray, }; - constantValueType type; + constantValueType ctype; }; class ConstantInt :public ConstantValue { public: - ConstantInt(int val) :value(val) { type = typeInt; }; + ConstantInt(int val) :value(val) { ctype = typeInt; type = new Type(intType); isConstant = true; } int value; }; @@ -26,6 +26,6 @@ class ConstantInt :public ConstantValue class ConstantArray : public ConstantValue { public: - ConstantArray(vector val) :value(val) { type = typeArray; }; + ConstantArray(vector val) :value(val) { ctype = typeArray; type = new Type(arrayType); isConstant = true;} vector value; }; \ No newline at end of file diff --git a/include/Function.h b/include/Function.h index 5d2395e..4731f55 100644 --- a/include/Function.h +++ b/include/Function.h @@ -18,10 +18,6 @@ class Instruction; class Function :public User { public: - void addBasicBlock(BaseBlock* p); - - void removeBasicBlock(BaseBlock* p); - void getFromStatment(NStmtList stmtList); void getFromBlock(NBlockStmt* block); @@ -30,17 +26,19 @@ class Function :public User void getFromIf(NIfStmt* ifstmt); - static void addSymbol(string name, Value* val) { symbolTable.insert(make_pair(name, val)); } + void addSymbol(string name, Value* val); - Value* findValue(string name, BaseBlock* p) { return (symbolTable.find(name))->second; } + Value* findValue(string name); Instruction* getInstFromExp(NExp* p); - Function(Type* type) :User(type) {}; + Function(Type* type); - static Function* makeFunction(Type* returnVal, vectorarg, vector paraName); + static Function* makeFunction(Type* returnVal, vectorarg, vector paraName); + //block结束,将recoverTable中的符号重新写回symbolTable中 + void RecoverSymBol(); void debugPrint(); @@ -54,11 +52,10 @@ class Function :public User this->parent = p; } - static map symbolTable; - static map recoverTable; + map symbolTable; + map recoverTable; string name; BaseBlock* entry; BaseBlock* last; Module* parent; - }; diff --git a/include/Instruction.h b/include/Instruction.h index 775e8d4..e887b6e 100644 --- a/include/Instruction.h +++ b/include/Instruction.h @@ -1,12 +1,20 @@ #pragma once - +#include +#include #include"User.h" #include"Value.h" #include"BasicBlock.h" +#include"ConstantValue.h" +#include"Module.h" +using namespace std; class BaseBlock; class BaseBlock; class Function; +class ConstantInt; + + + class Instruction :public User { @@ -26,6 +34,7 @@ class Instruction :public User Add, Sub, RSub, // Reverse Subtract + Mod, Mul, Div, Rem, @@ -42,8 +51,15 @@ class Instruction :public User Shl, // << AShr, // arithmetic >> LShr, // logical >> - // Other operators Cmp, + //Cmp + EQ, //== + NE, //!= + GT, //> + GE, //>= + LT, //< + LE, //<= + // Other operators PHI, Call, GEP, // GetElementPtr @@ -53,12 +69,63 @@ class Instruction :public User VectorAdd }; - Instruction(OpID id, int argNum):id(id),User(intType) {}; - Instruction() :User(intType) {}; + const std::map name = { + {constant,"constant"}, + // High IR + {Break,"Break"}, + {Continue, "Continue"}, + // Terminator Instructions + {Ret, "Ret"}, + {Br, "Br"}, + {Jmp, "Jmp"}, + // Standard unary operators + {Neg, "Neg"}, + // Standard binary operators + {Add, "Add"}, + {Sub, "Sub"}, + {RSub, "RSub"}, // Reverse Subtract + {Mul, "Mul"}, + {Div, "Div"}, + {Rem, "Rem"}, + {AddAddr, "AddAddr"}, // deprecated + // Logical operators + {And, "And"}, + {Or, "Or"}, + {Not, "Not"}, + // Memory operators + {Alloca, "Alloca"}, + {Load, "Load"}, + {Store, "Store"}, + // Shift operators + {Shl, "Shl"}, // << + {AShr, "Ashr"}, // arithmetic >> + {LShr, "LShr"}, // logical >> + // Other operators + {Cmp, "Cmp"}, + {PHI, "PHI"}, + {Call, "Call"}, + {GEP, "GEP"}, // GetElementPtr + {ZExt, "ZExt"}, // zero extend + {MulAdd, "MulAdd"}, // a*b+c + //多条指令的结果求和 + {VectorAdd, "VectorAdd"}, + {EQ,"EQ"}, //== + {NE,"NE"}, //!= + {GT,"GT"}, //> + {GE,"GE"}, //>= + {LT,"LT"}, //< + {LE,"LE"}, //<= + {Mod,"Mod"} + }; + + + Instruction(OpID id, int argNum):id(id),User(instrType) {}; + Instruction() :User(instrType) {}; void setarg(int num, vector arg) ; void setParent(BaseBlock*); OpID id; void debugPrint(); + bool isconst = false; private: BaseBlock* parent; }; @@ -66,7 +133,7 @@ class Instruction :public User class ConstInst :public Instruction { public: - ConstInst(Value* val); + ConstInst(Value* val) { args.push_back(val); id = constant; }; static ConstInst* createConst(Value* val) { return new ConstInst(val); }; }; @@ -74,7 +141,11 @@ class ConstInst :public Instruction class UnaryInst :public Instruction { public: - UnaryInst(Type* type, Value* val, BaseBlock* block, int OpID) {}; + UnaryInst(Type* type, Value* val, BaseBlock* block, OpID opid) + { + id = opid; + args.push_back(val); + }; static UnaryInst* createNeg(Value* val, BaseBlock* block) { return new UnaryInst(new Type(intType), val, block, Neg); }; static UnaryInst* createNot(Value* val, BaseBlock* block){ return new UnaryInst(new Type(intType), val, block, Not); }; static UnaryInst* createUnary(Value* val, BaseBlock* block,OpID id) { return new UnaryInst(new Type(intType), val, block, id); }; @@ -82,8 +153,13 @@ class UnaryInst :public Instruction class AllocaInst :public Instruction { - AllocaInst(Type* ty) {}; - AllocaInst(Type* ty, int num) {}; + AllocaInst(Type* ty) { id = Alloca; } + AllocaInst(Type* ty, int num) + { + id = Alloca; + ConstantInt* constInt = new ConstantInt(num); + args.push_back(constInt); + } public: static AllocaInst* createAlloca(Type* ty) {return new AllocaInst(ty); } @@ -95,8 +171,21 @@ class StoreInst :public Instruction Value* offset; int address; public: - StoreInst(Value* val, int address):address(address){}; - StoreInst(Value* val, int address, Value* offset) :address(address),offset(offset) {}; //offset可能需要计算才能得到 + StoreInst(Value* val, int address) :address(address) + { + id = Store; + args.push_back(val); + ConstantInt* constInt = new ConstantInt(address); + args.push_back(constInt); + } + StoreInst(Value* val, int address, Value* offset) :address(address),offset(offset) //offset可能需要计算才能得到 + { + id = Store; + args.push_back(val); + ConstantInt* constInt = new ConstantInt(address); + args.push_back(constInt); + args.push_back(offset); + } static StoreInst* createStore(Value* val, int address) { return new StoreInst(val, address); @@ -107,24 +196,32 @@ class StoreInst :public Instruction }; }; +//arg第一个是地址,第二个是偏移量 class LoadInst :public Instruction { - LoadInst(Type* ty, int address):address(address) { }; - LoadInst(Type* ty, int address, Value* offset) :address(address), offset(offset) {}; - Value* offset; - int address; + LoadInst(int address) + { + id = Load; + args.push_back(new ConstantInt(address)); + }; + LoadInst(int address, Value* offset) + { + id = Load; + args.push_back(new ConstantInt(address)); + args.push_back(offset); + }; public: - static LoadInst* createLoad(Type* ty, int address) + static LoadInst* createLoad(int address) { - return new LoadInst(ty, address); - }; - static LoadInst* createLoad(Type* ty, int address, Value* offset) { - return new LoadInst(ty, address, offset); + return new LoadInst(address); } + static LoadInst* createLoad(int address, Value* offset) + { + return new LoadInst(address,offset); -}; - + } +}; class BinaryInst :public Instruction @@ -133,11 +230,15 @@ class BinaryInst :public Instruction BinaryInst(Value* val1, Value* val2, OpID OpID) { this->id = OpID; + args.push_back(val1); + args.push_back(val2); } BinaryInst(Value* val1, Value* val2, BaseBlock* block, OpID OpID) { this->id = OpID; + args.push_back(val1); + args.push_back(val2); }; void setVal(Value* val, int pos) { setArg(val, pos); }; static BinaryInst* createAdd(Value* val1, Value* val2, BaseBlock* block) { return new BinaryInst(val1, val2, block, Add); }; @@ -153,43 +254,49 @@ class BinaryInst :public Instruction class CmpInst :public Instruction { public: - enum CmpOp - { - EQ, //== - NE, //!= - GT, //> - GE, //>= - LT, //< - LE //<= - }; - CmpInst(Type* type, Value* lhs, Value* rhs, BaseBlock* block, CmpOp cmp); - static CmpInst* createCMP(CmpOp op, Value* lhs, Value* rhs, BaseBlock* bb); + CmpInst(Type* type, Value* lhs, Value* rhs, BaseBlock* block, OpID cmp) + { + id = cmp; + args.push_back(lhs); + args.push_back(rhs); + } + static CmpInst* createCMP(OpID op, Value* lhs, Value* rhs, BaseBlock* bb) { return new CmpInst(new Type(intType), lhs, rhs, bb, op); }; }; class BranchInst : public Instruction { public: BranchInst(Value* cond, BaseBlock* if_true, BaseBlock* if_false, - BaseBlock* bb); - BranchInst(BaseBlock* if_true, BaseBlock* bb); - BranchInst(CmpInst::CmpOp op, Value* lhs, Value* rhs, BaseBlock* if_true, - BaseBlock* if_false, BaseBlock* bb); + BaseBlock* bb) + { + id = Br; + args.push_back(cond); + args.push_back((Value*)if_true); + if(if_false!=nullptr) + args.push_back((Value*)if_false); + } + BranchInst(BaseBlock* if_true, BaseBlock* bb) + { + id = Jmp; + args.push_back((Value*)if_true); + } static BranchInst* createCondBr(Value* cond, BaseBlock* if_true, - BaseBlock* if_false, BaseBlock* bb); - static BranchInst* createBr(BaseBlock* if_true, BaseBlock* bb); - static BranchInst* createCmpBr(CmpInst::CmpOp op, Value* lhs, Value* rhs, - BaseBlock* if_true, BaseBlock* if_false, - BaseBlock* bb); + BaseBlock* if_false, BaseBlock* bb) { + return new BranchInst(cond, if_true, if_false, bb); + }; + + static BranchInst* createBr(BaseBlock* if_true, BaseBlock* bb) { return new BranchInst(if_true, bb); }; + }; class ReturnInst : public Instruction { public: - ReturnInst(Value* val, BaseBlock* bb) {} - ReturnInst(BaseBlock* bb) {} + ReturnInst(Value* val, BaseBlock* bb) { id = Ret; args.push_back(val); } + ReturnInst(BaseBlock* bb) { id = Ret; } static ReturnInst* createRet(Value* val, BaseBlock* bb) { return new ReturnInst(val, bb); } static ReturnInst* createVoidRet(BaseBlock* bb) { return new ReturnInst(bb); } }; @@ -199,7 +306,15 @@ class ReturnInst : public Instruction class CallInst :public Instruction { public: - CallInst(Function* func, std::vector args, BaseBlock* bb) {} + CallInst(Function* func, std::vector args, BaseBlock* bb) + { + id = Call; + args.push_back((Value*)func); + for (int i = 0; i < args.size(); i++) + { + this->args.push_back(args[i]); + } + } static CallInst* createCall(Function* func, std::vector args, BaseBlock* bb) @@ -221,6 +336,13 @@ class vectorInst :public Instruction { public: vector vec; - vectorInst(vector vals, BaseBlock* bb):vec(vals) {}; + vectorInst(vector vals, BaseBlock* bb):vec(vals) + { + id = VectorAdd; + for (int i = 0; i < vals.size(); i++) + { + args.push_back(vals[i]); + } + } static vectorInst* createVectorInst(vector vec) { return new vectorInst(vec,nullptr); }; }; \ No newline at end of file diff --git a/include/Module.h b/include/Module.h index 6d67ea9..76b8729 100644 --- a/include/Module.h +++ b/include/Module.h @@ -18,10 +18,12 @@ class Function; class Module { public: - void addFunction(Function* f) { funcList.push_back(f); }; - void removeFunction(Function* f){}; + static void addFunction(Function* f) { funcList.push_back(f); }; + static void removeFunction(Function* f){}; Function* getFunction(string funcName); - + vector getFunctionList(){ + return funcList; + }; Value* getGlobalValue(string name) { @@ -49,17 +51,24 @@ class Module void addGlobalVar(string name, Value* val) { globalVar.insert(make_pair(name, val)); } void addConstantValue(Value* val, ConstantValue* cVal) { valueTable.insert(make_pair(val, cVal)); }; void ASTTranslate(NCompUnit* cu); - string getName(Value*); + static void addName(Value* val,string name); + static string getName(Value*); void addAddress(Value* p, int add) { addressTable.insert(make_pair(p, add)); }; - int getAddress(Value* p) { return (addressTable.find(p))->second; }; + int getAddress(Value* p) + { + auto iter = addressTable.find(p); + if (iter != addressTable.end()) + return iter->second; + else return 0; + } int address = 0; private: mapglobalVar; - vector funcList; + static vector funcList; map valueTable; map addressTable; - map nameTable; + static map nameTable; }; diff --git a/include/Pass.h b/include/Pass.h index f17dc2e..f58b2fb 100644 --- a/include/Pass.h +++ b/include/Pass.h @@ -2,8 +2,7 @@ #pragma once #include"Module.h" - - +/* class Pass { public: @@ -12,16 +11,26 @@ class Pass private: vector method; -}; - +};*/ class PassMethod { public: - void setModule(Module*); - void run(); + void setModule(Module module) + { + mod = module; + }; + virtual void run(){}; + +protected: + Module mod; +}; +class loopDetection : public PassMethod { private: - Module* mod; + vector InstructionList; //最终的大指令序列 +public: + loopDetection(); + ~loopDetection(); + void run(); }; - diff --git a/include/Type.h b/include/Type.h index dc08550..045098d 100644 --- a/include/Type.h +++ b/include/Type.h @@ -8,6 +8,8 @@ enum typeName intType, functionType, arrayType, + ptrType, + instrType }; class Type @@ -28,7 +30,7 @@ class IntType :public Type class FunctionType :public Type { public: - explicit FunctionType(Type* returnType, vector args):Type(functionType) {}; + explicit FunctionType(Type* returnType, vector args) :Type(functionType) { this->returnType = returnType; this->args = args; }; Type* returnType; vector args; }; @@ -41,3 +43,10 @@ class ArrayType :public Type int num; }; +class ptrType +{ + +}; + +class instrType +{}; \ No newline at end of file diff --git a/include/Value.h b/include/Value.h index ceaf505..a8947ca 100644 --- a/include/Value.h +++ b/include/Value.h @@ -10,7 +10,7 @@ class Value { public: Value(Type* type) :type(type) { isConstant = false; }; - Value(typeName tName) { type = new Type(tName); }; + Value(typeName tName) { type = new Type(tName); isConstant = false; }; Value() { isConstant = false; }; list& getUseList() { return useList; }; void addUse(Value* val, int useNo); @@ -21,15 +21,16 @@ class Value void removeUse(Value* val, int useNo); //just for debug - void debugPrint(); + virtual void debugPrint() {}; bool isArray() { return type->tName == arrayType; }; bool isInt() { return type->tName == intType; }; + + bool isInstr() { return type->tName == instrType; } bool isConstant; -private: - Type* type; +private: list useList; }; diff --git a/include/node.h b/include/node.h index a571229..cd63093 100644 --- a/include/node.h +++ b/include/node.h @@ -32,7 +32,7 @@ struct Index { return true; } - else if (name < x.name) + else if (scope==x.scope && name < x.name) { return true; } @@ -67,7 +67,7 @@ class SymbolTable public: SymbolTable() { - functionTable[0] = "Global"; + functionTable[0] = "Global"; } void AddSymbol(NIdentifier& ident, int scope, NExpList lengths, NExp* initvalue, bool isconst, NVarDecl* parent); @@ -141,8 +141,8 @@ class NCompUnit : public Node this->scope = 0; for (auto NDecl : declarations) { - NDecl->SetParentAndScope(this, this->scope); - NDecl->GenSymbolTable(); + NDecl->SetParentAndScope(this, this->scope); + NDecl->GenSymbolTable(); } for (auto NDecl : declarations) { @@ -219,30 +219,41 @@ class NVarDecl : public NDecl NExpList lengths; NExp* initvalue; IntList* finalInitValue; - + // 洢ijʼб IntList* dimensionLength; - + // 洢ĸάϢsizeij int size; + bool is_array = false; public: NVarDecl(NIdentifier& identifier, NExpList& lengths, NExp* initvalue) : identifier(identifier), lengths(lengths), initvalue(initvalue) { init = true; + if (lengths.size() != 0) + { + this->is_array = true; + } } NVarDecl(NIdentifier& identifier, NExpList& lengths) : identifier(identifier), lengths(lengths) { init = false; initvalue = NULL; + if (lengths.size() != 0) + { + this->is_array = true; + } } NVarDecl(const string& type, NIdentifier& identifier) : type(type), identifier(identifier) { init = false; + this->is_array = false; } NVarDecl(const string& type, NIdentifier& identifier, NExpList& lengths) : type(type), identifier(identifier), lengths(lengths) { init = false; initvalue = NULL; + this->is_array = true; } void setTypeforConst() @@ -250,6 +261,7 @@ class NVarDecl : public NDecl isconst = true; } + void Print(); void GenSymbolTable() { @@ -265,7 +277,7 @@ class NVarDecl : public NDecl { if (lengths.size() != 0) { - + // ĸάȽе this->dimensionLength = new IntList(); this->size = 1; for (auto NExp : lengths) @@ -274,7 +286,7 @@ class NVarDecl : public NDecl dimensionLength->push_back(NExp->GetValue()); } - + // ijʼбе; if (this->init) { this->finalInitValue = new IntList(this->size, 0); @@ -300,6 +312,7 @@ class NVarDecl : public NDecl } }; + class NFuncDecl : public NDecl { public: @@ -311,7 +324,7 @@ class NFuncDecl : public NDecl public: NFuncDecl(const string& type, NIdentifier& function_name, NVarDeclList& parameters, NStmtList& statements) : type(type), function_name(function_name), parameters(parameters), statements(statements) { - + int index = this->symboltb.AddFunction(function_name.name); for (auto param : parameters) { @@ -517,7 +530,7 @@ class NBinaryExp : public NExp public: NBinaryExp(NExp& lhs, int op, NExp& rhs) : lhs(lhs), op(op), rhs(rhs) {} - int GetValue(); + int GetValue(); void SetParentAndScope(Node* parent, int scope) { this->parent = parent; @@ -575,4 +588,15 @@ class NIdentifierExp : public NExp this->parent = parent; this->scope = scope; } -}; + + IntList* GetDimensions() + { + IntList* dimensions = new IntList(); + if (array_def.size() != 0) + { + // array + return this->symboltb.GetSymbol(this->name, this->scope)->parent->dimensionLength; + } + return dimensions; + } +}; \ No newline at end of file diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp new file mode 100644 index 0000000..d13f073 --- /dev/null +++ b/src/BasicBlock.cpp @@ -0,0 +1,14 @@ +#include "../include/BasicBlock.h" + +void BaseBlock::debugPrint() +{ + cout << " BlockType "; + cout << name.at(blockType) << " "; + Instruction* inst; + cout << "InstructionListLength = " << insrList.size() << endl; + for (auto inst : insrList) + { + inst->debugPrint(); + cout << endl; + } +} \ No newline at end of file diff --git a/src/Function.cpp b/src/Function.cpp index 44cb788..0327860 100644 --- a/src/Function.cpp +++ b/src/Function.cpp @@ -1,10 +1,15 @@ #include"../include/Function.h" +#include +using std::stack; -map Function::symbolTable; -map Function::recoverTable; SymbolTable Node::symboltb; +stack whileIn; +stack whileOut; + + +extern vector t; bool isReturnStmt(NStmt* p) { if (dynamic_cast(p) == nullptr) @@ -41,6 +46,15 @@ bool isWhileStmt(NStmt* p) else return true; } +bool isExpStmt(NStmt* p) +{ + if (dynamic_cast(p) == nullptr) + { + return false; + } + else return true; +} + bool isBlockStmt(NStmt* p) { if (dynamic_cast(p) == nullptr) @@ -113,11 +127,62 @@ bool isCallExp(NExp* p) else return true; } +bool isInteger(NExp* p) +{ + if (dynamic_cast(p) == nullptr) + { + return false; + } + else return true; +} + + Instruction::OpID getOpId(int op) { - return Instruction::Add; + switch (op) + { + case 267: + return Instruction::EQ; break; + case 268: + return Instruction::NE; break; + case 269: + return Instruction::LE; break; + case 270: + return Instruction::GE; break; + case 271: + return Instruction::LT; break; + case 272: + return Instruction::GT; break; + case 273: + return Instruction::Not; break; + case 274: + return Instruction::And; break; + case 275: + return Instruction::Or; break; + case 276: + return Instruction::Add; break; + case 277: + return Instruction::Sub; break; + case 278: + return Instruction::Mul; break; + case 279: + return Instruction::Div; break; + case 280: + return Instruction::Mod; break; + case 281: + return Instruction::Div; break; + } } +bool isPreDefinedFunc(string name) +{ + for (auto i : t) + { + if (name == i) + return true; + } + return false; +} int judgeExp(NExp* exp) { @@ -129,6 +194,8 @@ int judgeExp(NExp* exp) return 3; if (isCallExp(exp)) return 4; + if (isInteger(exp)) + return 5; } Instruction* Function::getInstFromExp(NExp* p) @@ -141,13 +208,35 @@ Instruction* Function::getInstFromExp(NExp* p) string name = ident->name.name; if (ident->array_def.size() != 0)//array { + IntList dim = *(ident->GetDimensions()); + vectormult;//记录数组各维度的乘积,方便将高维访问转化为低维访问 + int init = 1; + mult.push_back(init); + for (int i = 1; i < dim.size(); i++) + { + init *= dim[i]; + mult.push_back(init); + } + //数组定义为a[3][2][2],访问a[2][1][1],转化为a[3*2*2]访问a[2*4+1*2+1*1] + //2*4+1*2+1*1需要多条指令来计算 + vector computeOffset; + int size = ident->array_def.size(); + for (int i = 0; i < size; i++) + { + Value* val1 = new ConstantInt(mult[size-1-i]); + Instruction* val2 = getInstFromExp(ident->array_def[i]); + Instruction* instr = BinaryInst::createMul(val1, val2,last); + computeOffset.push_back(instr); + } + Instruction* instr = vectorInst::createVectorInst(computeOffset); + return instr; } else //int { - Value* val = findValue(name, last); + Value* val = findValue(name); int address = parent->getAddress(val); - Instruction* instr = LoadInst::createLoad(new Type(intType), address); + Instruction* instr = LoadInst::createLoad(address); return instr; } } @@ -156,7 +245,10 @@ Instruction* Function::getInstFromExp(NExp* p) NBinaryExp* bi = dynamic_cast(p); Instruction* left = getInstFromExp(&(bi->lhs)); Instruction* right = getInstFromExp(&(bi->rhs)); - Instruction* instr = BinaryInst::createBinary(left, right, getOpId(bi->op)); + Instruction* instr; + if (bi->op <= 272) + instr = CmpInst::createCMP(getOpId(bi->op),left,right,nullptr); + else instr = BinaryInst::createBinary(left, right, getOpId(bi->op)); return instr; } case 3: @@ -170,8 +262,9 @@ Instruction* Function::getInstFromExp(NExp* p) { NCallExp* bi = dynamic_cast(p); string funcName = bi->function_name.name; - Function* func = parent->getFunction(funcName); - vector para; //дValue*ʵ涼Instruction* + Function* func; + func = parent->getFunction(funcName); + vector para; //写的是Value*,实际上里面都是Instruction* for (int i = 0; i < bi->parameters.size(); i++) { para.push_back(getInstFromExp(bi->parameters[i])); @@ -179,22 +272,184 @@ Instruction* Function::getInstFromExp(NExp* p) Instruction* instr = CallInst::createCall(func, para, nullptr); return instr; } + + case 5: + { + NInteger* Int= dynamic_cast(p); + ConstantInt* constint = new ConstantInt(Int->GetValue()); + Instruction* instr = ConstInst::createConst(constint); + instr->isConstant = true; + instr->isconst = true; + return instr; + } } } +Function::Function(Type* type):User(type) +{ + entry = last = new BaseBlock(); +} + void Function::getFromIf(NIfStmt* ifstmt) { + Instruction* instr = getInstFromExp(&ifstmt->condition); + BaseBlock* now = last; + BaseBlock* next = new BaseBlock(); + + BaseBlock* trueLast; + BaseBlock* falseLast; + BaseBlock* falseStart; + BaseBlock* trueStart=new BaseBlock; + + last->succ_bbs_.push_back(trueStart); + last->succ_bbs_.push_back(next); + + + + bool False = (ifstmt->false_statement != nullptr); + Instruction* branch; + if (False) //False存在 + { + falseStart = new BaseBlock(); + last->succ_bbs_[1] = falseStart; + branch = BranchInst::createCondBr(instr, trueStart, falseStart,nullptr); + } + else branch = BranchInst::createCondBr(instr, trueStart, next, nullptr); + + last->addInst(branch); + + //处理True分支 + trueStart->pre_bbs_.push_back(now); + last = trueStart; + NStmt* trueStmt = &(ifstmt->true_statement); + NBlockStmt* b = dynamic_cast(trueStmt); + if (b!=nullptr) + { + getFromBlock(b); + last->succ_bbs_.push_back(next); + trueLast = last; + } + else + { + //单条指令仍然要新开一个block放 + trueStart->pre_bbs_.push_back(now); + NStmtList p; + p.push_back(trueStmt); + getFromStatment(p); + trueStart->succ_bbs_.push_back(next); + trueLast = last; + } + + RecoverSymBol(); + + if (False) + { + falseStart->pre_bbs_.push_back(now); + last = falseStart; + NStmt* trueStmt = ifstmt->false_statement; + NBlockStmt* b = dynamic_cast(trueStmt); + if (b != nullptr) + { + getFromBlock(b); + last->succ_bbs_.push_back(next); + falseLast = last; + } + else + { + //单条指令 + NStmtList p; + p.push_back(trueStmt); + getFromStatment(p); + falseStart->succ_bbs_.push_back(next); + falseLast = last; + } + RecoverSymBol(); + + } + + if (False) + { + next->pre_bbs_.push_back(trueLast); + next->pre_bbs_.push_back(falseStart); + } + else + { + next->pre_bbs_.push_back(trueLast); + next->pre_bbs_.push_back(now); + } + last = next; } void Function::getFromWhile(NWhileStmt* whileStmt) -{} +{ + Instruction* condition = getInstFromExp(&whileStmt->condition); + Instruction* p = UnaryInst::createNot(condition, nullptr); //条件为假时,p为真,跳到out执行 + BaseBlock* out = new BaseBlock();//while结束后下一个block + BaseBlock* next = new BaseBlock();//while内容block + Instruction* branch = BranchInst::createCondBr(p, out, nullptr, nullptr);//满足条件 + Instruction* jmp = BranchInst::createBr(next, nullptr);//结束后跳回 + + last->succ_bbs_.push_back(next); + next->pre_bbs_.push_back(last); + next->addInst(branch); + last = next; + whileIn.push(next); + whileOut.push(out); + NBlockStmt* b = dynamic_cast(&whileStmt->statement); + if (b != nullptr) + { + getFromBlock(b); + last->succ_bbs_.push_back(whileIn.top()); + last->addInst(jmp); + + } + else + { + //单条指令 + NStmtList p; + p.push_back(&whileStmt->statement); + getFromStatment(p); + last->succ_bbs_.push_back(whileIn.top()); + last->addInst(jmp); + out->pre_bbs_.push_back(whileIn.top()); + } + + RecoverSymBol(); + last = out; +} void Function::getFromBlock(NBlockStmt* block) -{} +{ + BaseBlock* p; + if (last->insrList.size() == 0) + p = last; + else + { + p = new BaseBlock(); + p->pre_bbs_.push_back(last); + last->succ_bbs_.push_back(p); + last = p; + } + getFromStatment(block->block); + RecoverSymBol(); + BaseBlock* next; + if (last->insrList.size() == 0) + { + next = last; + } + else + { + next = new BaseBlock(); + last->succ_bbs_.push_back(next); + next->pre_bbs_.push_back(last); + } + + last = next; +} @@ -216,6 +471,8 @@ int judgeStmt(NStmt* p) return 7; if (iscontinueStmt(p)) return 8; + if (isExpStmt(p)) + return 9; } void Function::getFromStatment(NStmtList stmtList) @@ -232,7 +489,8 @@ void Function::getFromStatment(NStmtList stmtList) { NReturnStmt* ret = dynamic_cast(stmt); Instruction* instr = getInstFromExp(ret->return_value); - now->insrList.push_back(instr); + Instruction* retInstr = ReturnInst::createRet(instr, nullptr); + last->addInst(retInstr); break; } case 2: @@ -246,26 +504,29 @@ void Function::getFromStatment(NStmtList stmtList) for (auto decl : declList) { auto dec = dynamic_cast(decl); - if (dec->size == 0) //int + if (dec->is_array==false) //int { - Type* p = new IntType(); - Instruction* instr = AllocaInst::createAlloca(p); - Value* newVal = new Value(p); + Instruction* instr = AllocaInst::createAlloca(new Type(intType)); + Value* newVal = new Value(intType); string name = dec->identifier.name; parent->addAddress(newVal, parent->address); - parent->address += 4; - now->addInst(instr); + parent->address += 1; + last->addInst(instr); addSymbol(name, newVal); - int val = 0; + parent->addName(newVal, name); + Value* v; if (dec->init) { - val = dec->initvalue->GetValue(); - newVal->isConstant = true; + NExp* p = dec->initvalue; + v = getInstFromExp(p); + } + else + { + v = new ConstantInt(0); } - ConstantInt* constInt = new ConstantInt(val); int address = this->parent->getAddress(newVal); - instr = StoreInst::createStore(constInt, address - 4); - now->addInst(instr); + instr = StoreInst::createStore(v, address); + last->addInst(instr); } else //array @@ -275,9 +536,10 @@ void Function::getFromStatment(NStmtList stmtList) Value* newVal = new Value(p); string name = dec->identifier.name; parent->addAddress(newVal, parent->address); - parent->address += 4 * dec->size; - now->addInst(instr); + parent->address += dec->size; + last->addInst(instr); addSymbol(name, newVal); + parent->addName(newVal, name); if (dec->init) { newVal->isConstant = true; @@ -286,16 +548,20 @@ void Function::getFromStatment(NStmtList stmtList) int val = (*dec->finalInitValue)[i]; ConstantInt* constInt = new ConstantInt(val); int address = this->parent->getAddress(newVal); - Instruction* instr = StoreInst::createStore(constInt, address - 4 * (dec->size - i)); + Instruction* instr = StoreInst::createStore(constInt, address+i); } } } } + break; } case 4: { getFromWhile(dynamic_cast(stmt)); + last = whileOut.top(); + whileIn.pop(); + whileOut.pop(); break; } case 5: @@ -304,31 +570,43 @@ void Function::getFromStatment(NStmtList stmtList) break; } case 6: - //break ֻwhile֣Բ + //跳出while,跳到WhileOut的栈顶地址 + { + last->succ_bbs_.push_back(whileOut.top()); + Instruction* p = BranchInst::createBr(whileOut.top(), last); + last->addInst(p); + goto breakcontinue; //berak后续的指令不可能执行了,可以不读取直接结束 break; - + } case 7: { NAssignStmt* assign = dynamic_cast(stmt); string name = assign->name.name; - Value* var = findValue(name, now); + Value* var = findValue(name); int address = parent->getAddress(var); - if (var->isArray()) + if (var->isInt()) + { + Instruction* rhs = getInstFromExp(&assign->rhs); + Instruction* store = StoreInst::createStore(rhs, address); + last->addInst(store); + } + + else //数组及指针 { IntList dim = (*assign->GetDimensions()); - vectormult;//¼άȵij˻㽫άתΪά + vectormult;//记录数组各维度的乘积,方便将高维访问转化为低维访问 int init = 1; mult.push_back(init); Instruction* rhs = getInstFromExp(&assign->rhs); - now->addInst(rhs); + last->addInst(rhs); for (int i=1;i computeOffset; int size = assign->lengths.size(); for (int i=0;iaddInst(store); - } - - if (var->isInt()) - { - Instruction* rhs = getInstFromExp(&assign->rhs); - Instruction* store = StoreInst::createStore(rhs, address); - now->addInst(store); + last->addInst(store); } + break; + + } + case 8: + { + last->succ_bbs_.push_back(whileOut.top()); + Instruction* p = BranchInst::createBr(whileOut.top(), last); + last->addInst(p); + goto breakcontinue; //berak后续的指令不可能执行了,可以不读取直接结束 + break; + } + case 9: + { + Instruction* p = getInstFromExp(&((NExpStmt*)stmt)->expression); + last->addInst(p); } - case 8: break; + default: break; } } - return; + breakcontinue :return; } Function* Function::makeFunction(Type* returnVal, vectorarg, vector paraName) @@ -372,35 +658,101 @@ Function* Function::makeFunction(Type* returnVal, vectorarg, vectortName == intType) { Type* type = new IntType; - Instruction* p = AllocaInst::createAlloca(type); - first->addInst(p); Value* val = new Value(type); - addSymbol(paraName[i], val); + p->addSymbol(paraName[i], val); + Module::addName(val, paraName[i]); } else { Type* type = new ArrayType(((ArrayType*)para)->num); - Instruction* p = AllocaInst::createAlloca(type); - first->addInst(p); Value* val = new Value(type); - addSymbol(paraName[i], val); + p->addSymbol(paraName[i], val); + Module::addName(val, paraName[i]); } } return p; } +void Function::RecoverSymBol() +{ + vector earse; + for (auto i : recoverTable) + { + auto iter= symbolTable.find(i.first); + if (iter != symbolTable.end()) + { + string name = iter->first; + Value* val = iter->second; + symbolTable.erase(iter); + symbolTable.insert(make_pair(name, val)); + earse.push_back(name); + } + } + for (auto i : earse) + { + recoverTable.erase(recoverTable.find(i)); + } + +} + + +void Function::addSymbol(string name, Value* val) +{ + auto iter = symbolTable.find(name); + if (iter != symbolTable.end()) + { + recoverTable.insert(make_pair(iter->first,iter->second)); + symbolTable.erase(iter); + symbolTable.insert(make_pair(name, val)); + } + else + { + symbolTable.insert(make_pair(name, val)); + } +} + +Value* Function::findValue(string name) +{ + auto iter = symbolTable.find(name); + if (iter != symbolTable.end()) + { + return iter->second; + } + else + { + auto global = parent->getGlobalValue(name); + if (global != nullptr) + return global; + else return nullptr; + } +} + + void Function::debugPrint() { + vector memberList; cout << "Function: " << name; BaseBlock* p = entry; - while (p->succ_bbs_.size()!=0) - { + cout << " entry = " << p->blockType; + cout << " succ_bbs_= " << p->succ_bbs_.size() << " " << endl; + bool loop = true; + while (p->succ_bbs_.size() != 0 && p->succ_bbs_[0]!=nullptr && loop) + { + for (auto pp : memberList) + { + if (pp == p) + { + loop = false; + cout << "LOOP detected! Exit The LOOP!!!" << endl; + } + } + memberList.push_back(p); p->debugPrint(); p = p->succ_bbs_[0]; } + memberList.push_back(p); + p->debugPrint(); cout << endl; - - } \ No newline at end of file diff --git a/src/Instrucion.cpp b/src/Instrucion.cpp index 787e1f6..2af343e 100644 --- a/src/Instrucion.cpp +++ b/src/Instrucion.cpp @@ -1,11 +1,72 @@ #include"../include/Instruction.h" - void Instruction::debugPrint() { - - - - + cout << " "; + cout << name.at(id) << " "; + cout <<"arg Num:"<< args.size() << " "; + for (Value* arg : args) + { + if (arg->isArray()) + { + cout << "array: "; + if (arg->isConstant) + { + ConstantArray* constantArray = dynamic_cast(arg); + for (int i = 0; i < constantArray->value.size(); i++) + { + cout << constantArray->value[i] << " "; + } + } + else + { + string name = Module::getName(arg); + if (name.size() != 0) + cout << name<<" "; + else cout << "no init "; + } + cout <<" "; + } + else if (arg->isInt()) + { + cout << "int: "; + if (arg->isConstant) + { + ConstantInt* constantInt = dynamic_cast(arg); + if(constantInt!=nullptr) + cout << constantInt->value<<" "; + else + { + ConstInst* p = dynamic_cast(arg); + cout << ((ConstantInt*)p->args[0])->value<<" "; + } + } + else + { + string name = Module::getName(arg); + if (name.size() != 0) + cout << name<<" "; + else cout << "no init "; + } + cout << " "; + } + else if(arg->isInstr()) + { + Instruction* instruction = dynamic_cast(arg); + if (instruction->isconst == true) + { + cout << "int:" << ((ConstantInt*)instruction->args[0])->value<<" "; + continue; + } + cout << endl; + cout << "Instruction: "; + instruction->debugPrint(); + cout << " "; + } + else + { + cout << "Block or something"; + } + } } \ No newline at end of file diff --git a/src/Module.cpp b/src/Module.cpp index f4f701e..53aac6a 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -3,6 +3,25 @@ #include using std::vector; +map Module::nameTable; +vector Module::funcList; +vector t = { "getint","getch","getarray","putint","putch","putarray","putf","starttime","stoptime" }; + + +void makePredefinedFunc() +{ + for (auto i : t) + { + Function* p = new Function(new Type(functionType)); + p->name = i; + Module::addFunction(p); + } +} + + + + + void Module::ASTTranslate(NCompUnit* cu) @@ -32,13 +51,16 @@ void Module::ASTTranslate(NCompUnit* cu) for (auto decl : para) { paraName.push_back(decl->identifier.name); - if (decl->size == 0) + if (!decl->is_array) { Type* paraType = new IntType(); arg.push_back(paraType); } else { + //a[]的情况,数组长度为0 + if (decl->size < 0) + decl->size = 0; Type* paraType = new ArrayType(decl->size); arg.push_back(paraType); } @@ -46,9 +68,9 @@ void Module::ASTTranslate(NCompUnit* cu) Function* func = Function::makeFunction(t, arg,paraName); func->setName(name); func->setParent(this); + NStmtList stmt = p->statements; func->getFromStatment(stmt); - addFunction(func); } @@ -58,18 +80,17 @@ void Module::ASTTranslate(NCompUnit* cu) string name = p->identifier.name; if (len == 0) //int { - Type* type = new Type(); - type->tName == intType; - Value* val = new Value(type); + Value* val = new Value(intType); addAddress(val, address); - address += 4; + address += 1; addGlobalVar(name,val); if (p->init == true) //if init,add value to map { int intVal = p->initvalue->GetValue(); ConstantInt* constInt = new ConstantInt(intVal); addConstantValue(val, constInt); + val->isConstant = true; } } @@ -79,7 +100,7 @@ void Module::ASTTranslate(NCompUnit* cu) Value* val = new Value(type); addAddress(val, address); - address += 4 * ((p->lengths[0])->GetValue()); + address += ((p->lengths[0])->GetValue()); addGlobalVar(name,val); if (p->init == true) @@ -92,20 +113,48 @@ void Module::ASTTranslate(NCompUnit* cu) } ConstantArray* array = new ConstantArray(arrayValue); addConstantValue(val, array); + val->isConstant = true; } } } } } +void Module::addName(Value* val,string name) +{ + nameTable.insert(make_pair(val, name)); +} + +string Module::getName(Value* val) +{ + auto iter = nameTable.find(val); + if (iter != nameTable.end()) + { + return iter->second; + } + return string(); +} + void Module::debugPrint() { - for (auto i : globalVar) + map::iterator iter; + for (iter = globalVar.begin(); iter != globalVar.end(); iter++) { - Value* val = getGlobalValue(i.first); + cout << iter->first << endl; + Value* val = getGlobalValue(iter->first); + /* + cout << val->isArray() << " "; + cout << val->isInt() << " "; + cout << val->isConstant << endl; + */ + /* + cout << iter->second->isArray() << " "; + cout << iter->second->isInt() << " "; + cout << iter->second->isConstant << endl; + */ if (val->isArray()) { - cout << "array: " << i.first; + cout << "array: " << iter->first; if (val->isConstant) { vector value; @@ -119,7 +168,7 @@ void Module::debugPrint() } else if (val->isInt()) { - cout << "int: " << i.first; + cout << "int: " << iter->first; if (val->isConstant) { int value; @@ -129,7 +178,6 @@ void Module::debugPrint() cout << endl; } } - for (auto i : funcList) { i->debugPrint(); diff --git a/src/loop.cpp b/src/loop.cpp new file mode 100644 index 0000000..49a5f32 --- /dev/null +++ b/src/loop.cpp @@ -0,0 +1,32 @@ +#include "../include/Pass.h" +//循环优化 + +//首先需要找到循环 + +/*目前的状况是只能进行暴力优化,在一开始将所有的block打开成为指令序列,然后根据这些指令序列建表 + 在指令序列当中搜索循环,对循环进行优化,可能的话还要对流程进行优化*/ + +loopDetection::loopDetection() +{ +} + +loopDetection::~loopDetection() +{ +} + +void loopDetection::run() +{ + for (auto func : mod.getFunctionList()) { + BaseBlock* p = func->entry; + while (p->succ_bbs_.size() != 0 && p->succ_bbs_[0] != nullptr) { + InstructionList.insert(InstructionList.end(), p->insrList.begin(), p->insrList.end()); + p = p->succ_bbs_[0]; + } + InstructionList.insert(InstructionList.end(), p->insrList.begin(), p->insrList.end()); + } + for (auto inst: InstructionList) + { + inst->debugPrint(); + cout << endl; + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index dab4259..a22ac08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,8 @@ #include #include #include "../include/node.h" -#include"../include/Module.h" -using namespace std; +#include "../include/Module.h" +#include "../include/Pass.h" extern FILE* yyin; extern int yyparse(); @@ -28,7 +28,10 @@ int main(int argc, char* argv[]) } fclose(fp); Module p; + loopDetection pass; p.ASTTranslate(CompUnit); + //pass.setModule(p); + //pass.run(); p.debugPrint(); return 0; } diff --git a/src/node.cpp b/src/node.cpp index 2fdc7e5..b413ef0 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -1,6 +1,6 @@ #include "../include/node.h" #include "parser.hpp" -// node.h ǰ parser.hpp ں +// node.h 在前, parser.hpp 在后, 勿动 int NBinaryExp::GetValue() { @@ -55,7 +55,7 @@ void SymbolTable::AddSymbol(NIdentifier& ident, int scope, NExpList lengths, NEx int SymbolTable::GetSymbolValue(NIdentifier& ident, NExpList& array_def, int scope, Node* parent) { - // ӷűвһŵֵ + // 从符号表中查找一个符号的值 auto result = this->valueTable.find({ scope, ident.name }); if (result != valueTable.end()) @@ -64,7 +64,7 @@ int SymbolTable::GetSymbolValue(NIdentifier& ident, NExpList& array_def, int sco } else if (scope != 0) { - // Ǿֲںδض + // 如果是局部变量且在函数内未被重定义 auto result = this->valueTable.find({ 0, ident.name }); if (result != valueTable.end()) { @@ -87,7 +87,7 @@ int SymbolTable::GetSymbolValue(NIdentifier& ident, NExpList& array_def, int sco Symbol* SymbolTable::GetSymbol(NIdentifier& ident, int scope) { - // ӷűвһŵֵ + // 从符号表中查找一个符号的值 auto result = this->valueTable.find({ scope, ident.name }); if (result != valueTable.end()) @@ -96,7 +96,7 @@ Symbol* SymbolTable::GetSymbol(NIdentifier& ident, int scope) } else if (scope != 0) { - // Ǿֲںδض + // 如果是局部变量且在函数内未被重定义 auto result = this->valueTable.find({ 0, ident.name }); if (result != valueTable.end()) { @@ -125,7 +125,7 @@ int Symbol::GetValue(NExpList array_def) int index = 0; int i = 0; int nowsize = this->parent->size; - // һa[4][2][3], a[2][1][1]ϵʱ2 * size / 4 + 1 * size / 4 / 2 + 1 * size / 4 / 2 / 3 + // 给定一个数组a[4][2][3], 求数组在a[2][1][1]上的引用时用2 * size / 4 + 1 * size / 4 / 2 + 1 * size / 4 / 2 / 3 for (auto dimension : array_def) { auto iterator = this->parent->dimensionLength->begin(); @@ -151,7 +151,7 @@ void SymbolTable::SetValue(NIdentifier& name, NExpList& lengths, NExp& rhs, int } else if (scope != 0) { - // ֲ ȥȫֱв + // 局部变量 还可以去全局变量中查找 auto result = valueTable.find({ 0, name.name }); if (result != valueTable.end()) { diff --git a/src/tokens.cpp b/src/tokens.cpp index a53f3ec..4df1781 100644 --- a/src/tokens.cpp +++ b/src/tokens.cpp @@ -1,163 +1,219 @@ -/* A lexical scanner generated by flex */ +#line 2 "./tokens.cpp" -/* Scanner skeleton version: - * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ - */ -#pragma once +#line 4 "./tokens.cpp" +#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 - -#include -#include"../include/node.h" -#ifndef _UNISTD_H -#define _UNISTD_H -#include -#include -#endif _UNISTD_H - - /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA #endif +/* First, we deal with platform-specific or compiler-specific issues. */ -#ifdef __cplusplus - +/* begin standard C headers. */ +#include +#include +#include #include +#include -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS +/* end standard C headers. */ -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST +/* flex integer type definitions */ -#else /* ! __cplusplus */ +#ifndef FLEXINT_H +#define FLEXINT_H -#if __STDC__ +/* C99 systems have . Non-C99 systems may or may not. */ -#define YY_USE_PROTOS -#define YY_USE_CONST +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ -#pragma warn -rch -#pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS +/* 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 -#ifdef YY_USE_CONST -#define yyconst const +#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 -#define yyconst +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; + +/* 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 + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) #endif +#endif /* ! C99 */ -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define YY_PROTO(proto) () +#define yynoreturn #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. +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. */ -#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 +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) - /* Action number for EOF rule of a given start state. */ +/* 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_NEW_FILE yyrestart( yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif -typedef struct yy_buffer_state* YY_BUFFER_STATE; +/* 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 + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif extern int yyleng; -extern FILE* yyin, * yyout; + +extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - - /* Return all but the first 'n' matched characters back to the input stream. */ - + + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) + #define YY_LINENO_REWIND_TO(dst) \ + do {\ + const char *p;\ + for ( p = yy_cp-1; p >= (dst); --p)\ + if ( *p == '\n' )\ + --yylineno;\ + }while(0) + +/* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ + 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 + n - YY_MORE_ADJ; \ + (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) ) -#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). - */ -typedef unsigned int yy_size_t; - - +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state -{ - FILE* yy_input_file; + { + FILE *yy_input_file; - char* yy_ch_buf; /* input buffer */ - char* yy_buf_pos; /* current position in input buffer */ + 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; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -183,12 +239,16 @@ struct yy_buffer_state */ 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 @@ -202,28 +262,37 @@ struct yy_buffer_state * just pointing yyin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 -}; -static YY_BUFFER_STATE yy_current_buffer = 0; + }; +#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 = NULL; /**< 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_current_buffer - +#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. */ +/* 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 = 1; /* whether we need to initialize */ +static char *yy_c_buf_p = NULL; +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 @@ -231,225 +300,230 @@ static int yy_start = 0; /* start state number */ */ static int yy_did_buffer_switch_on_eof; -void yyrestart YY_PROTO((FILE* input_file)); +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 ); -void yy_switch_to_buffer YY_PROTO((YY_BUFFER_STATE new_buffer)); -void yy_load_buffer_state YY_PROTO((void)); -YY_BUFFER_STATE yy_create_buffer YY_PROTO((FILE* file, int size)); -void yy_delete_buffer YY_PROTO((YY_BUFFER_STATE b)); -void yy_init_buffer YY_PROTO((YY_BUFFER_STATE b, FILE* file)); -void yy_flush_buffer YY_PROTO((YY_BUFFER_STATE b)); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) +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 YY_PROTO((char* base, yy_size_t size)); -YY_BUFFER_STATE yy_scan_string YY_PROTO((yyconst char* yy_str)); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO((yyconst char* bytes, int len)); +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); -static void* yy_flex_alloc YY_PROTO((yy_size_t)); -static void* yy_flex_realloc YY_PROTO((void*, yy_size_t)); -static void yy_flex_free YY_PROTO((void*)); +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 ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_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 ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_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) -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) +/* Begin user sect3 */ +#define yywrap() (/*CONSTCOND*/1) +#define YY_SKIP_YYWRAP +typedef flex_uint8_t YY_CHAR; -#define YY_USES_REJECT +FILE *yyin = NULL, *yyout = NULL; -#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; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #define yytext_ptr yytext -static yy_state_type yy_get_previous_state YY_PROTO((void)); -static yy_state_type yy_try_NUL_trans YY_PROTO((yy_state_type current_state)); -static int yy_get_next_buffer YY_PROTO((void)); -static void yy_fatal_error YY_PROTO((yyconst char msg[])); +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 yynoreturn yy_fatal_error ( const 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; \ + (yytext_ptr) = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ + (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; - + (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 30 #define YY_END_OF_BUFFER 31 -static yyconst short int yy_acclist[123] = -{ 0, - 31, 29, 30, 1, 29, 30, 1, 30, 17, 29, - 30, 24, 29, 30, 29, 30, 22, 29, 30, 20, - 29, 30, 21, 29, 30, 23, 29, 30, 26, 29, - 30, 26, 29, 30, 13, 29, 30, 29, 30, 14, - 29, 30, 25, 29, 30, 25, 29, 30, 25, 29, - 30, 25, 29, 30, 25, 29, 30, 25, 29, 30, - 25, 29, 30, 25, 29, 30, 29, 30, 12, 18, - 27, 26, 26, 26, 16, 11, 15, 25, 25, 25, - 25, 5, 25, 25, 25, 25, 25, 19, 27, 26, - 25, 25, 25, 3, 25, 25, 25, 25, 28, 25, - - 25, 25, 6, 25, 25, 4, 25, 25, 8, 25, - 2, 25, 25, 25, 7, 25, 25, 10, 25, 25, - 9, 25 -}; - -static yyconst short int yy_accept[79] = -{ 0, - 1, 1, 1, 2, 4, 7, 9, 12, 15, 17, - 20, 23, 26, 29, 32, 35, 38, 40, 43, 46, - 49, 52, 55, 58, 61, 64, 67, 69, 70, 71, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 84, 85, 86, 87, 88, 89, 89, 89, - 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, - 100, 101, 102, 103, 105, 106, 108, 109, 111, 113, - 114, 115, 117, 118, 120, 121, 123, 123 -}; - -static yyconst int yy_ec[256] = -{ 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 1, 1, 1, 5, 6, 1, 1, - 1, 7, 8, 1, 9, 1, 10, 11, 12, 12, - 12, 12, 12, 12, 12, 13, 13, 1, 1, 14, - 15, 16, 1, 1, 17, 17, 17, 17, 17, 17, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 19, 18, 18, - 1, 1, 1, 1, 18, 1, 20, 21, 22, 23, - - 24, 25, 18, 26, 27, 18, 28, 29, 18, 30, - 31, 18, 18, 32, 33, 34, 35, 36, 37, 19, - 18, 18, 1, 38, 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 int yy_meta[39] = -{ 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 3, 3, 3, 1, 1, 1, 3, 4, 4, 3, - 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 1 -}; - -static yyconst short int yy_base[83] = -{ 0, - 0, 0, 111, 112, 112, 112, 95, 112, 103, 112, - 112, 112, 32, 29, 32, 93, 92, 91, 0, 73, - 73, 74, 21, 78, 70, 74, 61, 112, 112, 40, - 0, 41, 0, 43, 112, 112, 112, 0, 74, 67, - 63, 0, 61, 60, 66, 65, 112, 50, 51, 52, - 0, 0, 71, 30, 66, 0, 54, 65, 58, 112, - 58, 51, 57, 0, 51, 0, 58, 0, 0, 51, - 50, 0, 44, 0, 48, 0, 112, 62, 66, 70, - 46, 74 -}; - -static yyconst short int yy_def[83] = -{ 0, - 77, 1, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, - 78, 78, 78, 78, 78, 78, 77, 77, 77, 79, - 80, 77, 81, 77, 77, 77, 77, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 77, 79, 82, 79, - 80, 81, 78, 78, 78, 78, 78, 78, 78, 77, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 0, 77, 77, 77, - 77, 77 -}; - -static yyconst short int yy_nxt[151] = -{ 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 15, 16, 17, 18, 19, 19, 19, 19, - 20, 21, 19, 22, 19, 19, 23, 19, 19, 19, - 19, 24, 19, 19, 19, 25, 26, 27, 30, 32, - 32, 31, 34, 34, 34, 42, 49, 33, 52, 50, - 43, 32, 32, 34, 34, 34, 49, 49, 49, 50, - 60, 50, 62, 63, 38, 38, 48, 48, 48, 48, - 51, 76, 51, 51, 50, 50, 50, 50, 75, 74, - 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, - 61, 59, 58, 57, 56, 55, 54, 53, 47, 46, - - 45, 44, 41, 40, 39, 37, 36, 35, 29, 28, - 77, 3, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 -}; - -static yyconst short int yy_chk[151] = -{ 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, 1, 1, 1, 1, 1, 1, 13, 14, - 14, 13, 15, 15, 15, 23, 30, 14, 81, 30, - 23, 32, 32, 34, 34, 34, 48, 49, 50, 48, - 49, 50, 54, 54, 78, 78, 79, 79, 79, 79, - 80, 75, 80, 80, 82, 82, 82, 82, 73, 71, - 70, 67, 65, 63, 62, 61, 59, 58, 57, 55, - 53, 46, 45, 44, 43, 41, 40, 39, 27, 26, - - 25, 24, 22, 21, 20, 18, 17, 16, 9, 7, - 3, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 -}; - -static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], * yy_state_ptr; -static char* yy_full_match; -static int yy_lp; -#define REJECT \ -{ \ -*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \ -yy_cp = yy_full_match; /* restore poss. backed-over text */ \ -++yy_lp; \ -goto find_rule; \ -} +/* 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 const flex_int16_t yy_accept[78] = + { 0, + 0, 0, 31, 29, 1, 1, 17, 24, 29, 22, + 20, 21, 23, 26, 26, 13, 29, 14, 25, 25, + 25, 25, 25, 25, 25, 25, 29, 12, 18, 0, + 27, 26, 26, 26, 16, 11, 15, 25, 25, 25, + 25, 5, 25, 25, 25, 25, 19, 0, 0, 0, + 27, 26, 25, 25, 25, 3, 25, 25, 25, 28, + 25, 25, 25, 6, 25, 4, 25, 8, 2, 25, + 25, 7, 25, 10, 25, 9, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 1, 1, 1, 5, 6, 1, 1, + 1, 7, 8, 1, 9, 1, 10, 11, 12, 12, + 12, 12, 12, 12, 12, 13, 13, 1, 1, 14, + 15, 16, 1, 1, 17, 17, 17, 17, 17, 17, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 19, 18, 18, + 1, 1, 1, 1, 18, 1, 20, 21, 22, 23, + + 24, 25, 18, 26, 27, 18, 28, 29, 18, 30, + 31, 18, 18, 32, 33, 34, 35, 36, 37, 19, + 18, 18, 1, 38, 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 const YY_CHAR yy_meta[39] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 3, 1, 1, 1, 3, 4, 4, 3, + 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 1 + } ; + +static const flex_int16_t yy_base[83] = + { 0, + 0, 0, 111, 112, 112, 112, 95, 112, 103, 112, + 112, 112, 32, 29, 32, 93, 92, 91, 0, 73, + 73, 74, 21, 78, 70, 74, 61, 112, 112, 40, + 0, 41, 0, 43, 112, 112, 112, 0, 74, 67, + 63, 0, 61, 60, 66, 65, 112, 50, 51, 52, + 0, 0, 71, 30, 66, 0, 54, 65, 58, 112, + 58, 51, 57, 0, 51, 0, 58, 0, 0, 51, + 50, 0, 44, 0, 48, 0, 112, 62, 66, 70, + 46, 74 + } ; + +static const flex_int16_t yy_def[83] = + { 0, + 77, 1, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, + 78, 78, 78, 78, 78, 78, 77, 77, 77, 79, + 80, 77, 81, 77, 77, 77, 77, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 77, 79, 82, 79, + 80, 81, 78, 78, 78, 78, 78, 78, 78, 77, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 0, 77, 77, 77, + 77, 77 + } ; + +static const flex_int16_t yy_nxt[151] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 15, 16, 17, 18, 19, 19, 19, 19, + 20, 21, 19, 22, 19, 19, 23, 19, 19, 19, + 19, 24, 19, 19, 19, 25, 26, 27, 30, 32, + 32, 31, 34, 34, 34, 42, 49, 33, 52, 50, + 43, 32, 32, 34, 34, 34, 49, 49, 49, 50, + 60, 50, 62, 63, 38, 38, 48, 48, 48, 48, + 51, 76, 51, 51, 50, 50, 50, 50, 75, 74, + 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, + 61, 59, 58, 57, 56, 55, 54, 53, 47, 46, + + 45, 44, 41, 40, 39, 37, 36, 35, 29, 28, + 77, 3, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 + } ; + +static const flex_int16_t yy_chk[151] = + { 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, 1, 1, 1, 1, 1, 1, 13, 14, + 14, 13, 15, 15, 15, 23, 30, 14, 81, 30, + 23, 32, 32, 34, 34, 34, 48, 49, 50, 48, + 49, 50, 54, 54, 78, 78, 79, 79, 79, 79, + 80, 75, 80, 80, 82, 82, 82, 82, 73, 71, + 70, 67, 65, 63, 62, 61, 59, 58, 57, 55, + 53, 46, 45, 44, 43, 41, 40, 39, 27, 26, + + 25, 24, 22, 21, 20, 18, 17, 16, 9, 7, + 3, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 + } ; + +/* Table of booleans, true if rule could match eol. */ +static const flex_int32_t yy_rule_can_match_eol[31] = + { 0, +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, }; + +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 "tokens.l" -#define INITIAL 0 -#line 2 "tokens.l" +char *yytext; +#line 1 "./tokens.l" +#line 2 "./tokens.l" #include #include #include "../include/node.h" @@ -459,7 +533,53 @@ char* yytext; #define STRING_TOKEN yylval.string = new std::string(yytext, yyleng) #define STRING_INT yylval.token = atoi(yytext) #define KEYWORD_TOKEN(t) yylval.token = t -#line 457 "lex.yy.c" +#line 536 "./tokens.cpp" +#line 537 "./tokens.cpp" + +#define INITIAL 0 + +#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 ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( void ); + +int yyget_debug ( void ); + +void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in ( void ); + +void yyset_in ( FILE * _in_str ); + +FILE *yyget_out ( void ); + +void yyset_out ( FILE * _out_str ); + + int yyget_leng ( void ); + +char *yyget_text ( void ); + +int yyget_lineno ( void ); + +void yyset_lineno ( int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -467,89 +587,62 @@ char* yytext; #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap YY_PROTO((void)); +extern "C" int yywrap ( void ); #else -extern int yywrap YY_PROTO((void)); +extern int yywrap ( void ); #endif #endif #ifndef YY_NO_UNPUT -static void yyunput YY_PROTO((int c, char* buf_ptr)); + + static void yyunput ( int c, char *buf_ptr ); + #endif #ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO((char*, yyconst char*, int)); +static void yy_flex_strncpy ( char *, const char *, int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO((yyconst char*)); +static int yy_flex_strlen ( const char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput YY_PROTO((void)); -#else -static int input YY_PROTO((void)); -#endif -#endif - -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int* yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO((int new_state)); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO((void)); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO((void)); -#endif - +static int yyinput ( void ); #else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 +static int input ( void ); #endif -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif #endif - /* Amount of stuff to slurp up with each read. */ +/* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #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 ) +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #endif - /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ +/* 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->yy_is_interactive ) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ - int c = '*', n; \ + int c = '*'; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -559,20 +652,33 @@ YY_MALLOC_DECL YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); -#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. - */ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) 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. */ +/* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif @@ -582,312 +688,326 @@ YY_MALLOC_DECL #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 int yylex YY_PROTO(( void )) -#endif +#define YY_DECL_IS_OURS 1 - /* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ +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. */ +/* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/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 16 "tokens.l" - - -#line 611 "lex.yy.c" - - if (yy_init) + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) { - yy_init = 0; + (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if (!yy_start) - yy_start = 1; /* first start state */ + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ - if (!yyin) + if ( ! yyin ) yyin = stdin; - if (!yyout) + if ( ! yyout ) yyout = stdout; - if (!yy_current_buffer) - yy_current_buffer = - yy_create_buffer(yyin, YY_BUF_SIZE); + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } - yy_load_buffer_state(); + yy_load_buffer_state( ); } - while (1) /* loops until end-of-file is reached */ + { +#line 16 "./tokens.l" + + +#line 757 "./tokens.cpp" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { - yy_cp = yy_c_buf_p; + yy_cp = (yy_c_buf_p); /* Support of yytext. */ - *yy_cp = yy_hold_char; + *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_state_ptr = yy_state_buf; - *yy_state_ptr++ = yy_current_state; + yy_current_state = (yy_start); yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) { - yy_current_state = (int)yy_def[yy_current_state]; - if (yy_current_state >= 78) - yy_c = yy_meta[(unsigned int)yy_c]; + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int)yy_c]; - *yy_state_ptr++ = yy_current_state; + 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 >= 78 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; - } while (yy_base[yy_current_state] != 112); + } + while ( yy_base[yy_current_state] != 112 ); yy_find_action: - yy_current_state = *--yy_state_ptr; - yy_lp = yy_accept[yy_current_state]; -find_rule: /* we branch to this label when backing up */ - for (; ; ) /* until we find what rule we matched */ - { - if (yy_lp && yy_lp < yy_accept[yy_current_state + 1]) - { - yy_act = yy_acclist[yy_lp]; - { - yy_full_match = yy_cp; - break; - } - } - --yy_cp; - yy_current_state = *--yy_state_ptr; - yy_lp = yy_accept[yy_current_state]; + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; - if (yy_act != YY_END_OF_BUFFER) + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) { int yyl; - for (yyl = 0; yyl < yyleng; ++yyl) - if (yytext[yyl] == '\n') - ++yylineno; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + yylineno++; +; } do_action: /* This label is used only to access EOF actions. */ - - switch (yy_act) + 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: +/* rule 1 can match eol */ YY_RULE_SETUP -#line 18 "tokens.l" +#line 18 "./tokens.l" YY_BREAK case 2: YY_RULE_SETUP -#line 20 "tokens.l" +#line 20 "./tokens.l" { STRING_TOKEN; return CONST; } YY_BREAK case 3: YY_RULE_SETUP -#line 22 "tokens.l" +#line 22 "./tokens.l" { STRING_TOKEN; return INT; } YY_BREAK case 4: YY_RULE_SETUP -#line 24 "tokens.l" +#line 24 "./tokens.l" { STRING_TOKEN; return VOID; } YY_BREAK case 5: YY_RULE_SETUP -#line 26 "tokens.l" +#line 26 "./tokens.l" { STRING_TOKEN; return IF; } YY_BREAK case 6: YY_RULE_SETUP -#line 28 "tokens.l" +#line 28 "./tokens.l" { STRING_TOKEN; return ELSE; } YY_BREAK case 7: YY_RULE_SETUP -#line 30 "tokens.l" +#line 30 "./tokens.l" { STRING_TOKEN; return WHILE; } YY_BREAK case 8: YY_RULE_SETUP -#line 32 "tokens.l" +#line 32 "./tokens.l" { STRING_TOKEN; return BREAK; } YY_BREAK case 9: YY_RULE_SETUP -#line 34 "tokens.l" +#line 34 "./tokens.l" { STRING_TOKEN; return CONTINUE; } YY_BREAK case 10: YY_RULE_SETUP -#line 36 "tokens.l" +#line 36 "./tokens.l" { STRING_TOKEN; return RETURN; } YY_BREAK case 11: YY_RULE_SETUP -#line 38 "tokens.l" +#line 38 "./tokens.l" { KEYWORD_TOKEN(EQ); return EQ; } YY_BREAK case 12: YY_RULE_SETUP -#line 40 "tokens.l" +#line 40 "./tokens.l" { KEYWORD_TOKEN(NE); return NE; } YY_BREAK case 13: YY_RULE_SETUP -#line 42 "tokens.l" +#line 42 "./tokens.l" { KEYWORD_TOKEN(LT); return LT; } YY_BREAK case 14: YY_RULE_SETUP -#line 44 "tokens.l" +#line 44 "./tokens.l" { KEYWORD_TOKEN(GT); return GT; } YY_BREAK case 15: YY_RULE_SETUP -#line 46 "tokens.l" +#line 46 "./tokens.l" { KEYWORD_TOKEN(GE); return GE; } YY_BREAK case 16: YY_RULE_SETUP -#line 48 "tokens.l" +#line 48 "./tokens.l" { KEYWORD_TOKEN(LE); return LE; } YY_BREAK case 17: YY_RULE_SETUP -#line 50 "tokens.l" +#line 50 "./tokens.l" { KEYWORD_TOKEN(NOT); return NOT; } YY_BREAK case 18: YY_RULE_SETUP -#line 52 "tokens.l" +#line 52 "./tokens.l" { KEYWORD_TOKEN(AND); return AND; } YY_BREAK case 19: YY_RULE_SETUP -#line 54 "tokens.l" +#line 54 "./tokens.l" { KEYWORD_TOKEN(OR); return OR; } YY_BREAK case 20: YY_RULE_SETUP -#line 56 "tokens.l" +#line 56 "./tokens.l" { KEYWORD_TOKEN(ADD); return ADD; } YY_BREAK case 21: YY_RULE_SETUP -#line 58 "tokens.l" +#line 58 "./tokens.l" { KEYWORD_TOKEN(SUB); return SUB; } YY_BREAK case 22: YY_RULE_SETUP -#line 60 "tokens.l" +#line 60 "./tokens.l" { KEYWORD_TOKEN(MUL); return MUL; } YY_BREAK case 23: YY_RULE_SETUP -#line 62 "tokens.l" +#line 62 "./tokens.l" { KEYWORD_TOKEN(DIV); return DIV; } YY_BREAK case 24: YY_RULE_SETUP -#line 64 "tokens.l" +#line 64 "./tokens.l" { KEYWORD_TOKEN(MOD); return MOD; } YY_BREAK case 25: YY_RULE_SETUP -#line 66 "tokens.l" -{ +#line 66 "./tokens.l" +{ STRING_TOKEN; - return Ident; + return Ident; } YY_BREAK case 26: YY_RULE_SETUP -#line 71 "tokens.l" +#line 71 "./tokens.l" { - // be careful for 'o - //std::cout << "IntConst: " << yytext << std::endl; - STRING_INT; - return IntConst; } -YY_BREAK + // be careful for 'o + //std::cout << "IntConst: " << yytext << std::endl; + STRING_INT; + return IntConst; } + YY_BREAK case 27: YY_RULE_SETUP -#line 77 "tokens.l" +#line 77 "./tokens.l" {} YY_BREAK case 28: +/* rule 28 can match eol */ YY_RULE_SETUP -#line 79 "tokens.l" -{} +#line 79 "./tokens.l" +{} YY_BREAK case 29: YY_RULE_SETUP -#line 81 "tokens.l" +#line 81 "./tokens.l" { //std::cout << "lex " << *yytext << " unknown at line:" << yylineno << std::std::endl; - return *yytext; } + return *yytext;} YY_BREAK case 30: YY_RULE_SETUP -#line 83 "tokens.l" +#line 83 "./tokens.l" ECHO; YY_BREAK -#line 860 "lex.yy.c" - case YY_STATE_EOF(INITIAL): - yyterminate(); +#line 984 "./tokens.cpp" +case YY_STATE_EOF(INITIAL): + 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; + 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_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET - if (yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW) + 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 + * 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->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + (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 @@ -897,13 +1017,13 @@ ECHO; * end-of-buffer state). Contrast this with the test * in input(). */ - if (yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars]) + 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_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -914,32 +1034,32 @@ ECHO; * will run more slowly). */ - yy_next_state = yy_try_NUL_trans(yy_current_state); + yy_next_state = yy_try_NUL_trans( yy_current_state ); - yy_bp = yytext_ptr + YY_MORE_ADJ; + yy_bp = (yytext_ptr) + YY_MORE_ADJ; - if (yy_next_state) + if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; + yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = yy_c_buf_p; + yy_cp = (yy_c_buf_p); goto yy_find_action; } } - else switch (yy_get_next_buffer()) + else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { - yy_did_buffer_switch_on_eof = 0; + (yy_did_buffer_switch_on_eof) = 0; - if (yywrap()) + if ( yywrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -950,7 +1070,7 @@ ECHO; * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -958,30 +1078,30 @@ ECHO; else { - if (!yy_did_buffer_switch_on_eof) + 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_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; + 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->yy_ch_buf[yy_n_chars]; + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - yy_current_state = yy_get_previous_state(); + yy_current_state = yy_get_previous_state( ); - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; @@ -989,12 +1109,12 @@ ECHO; default: YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found"); + "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of yylex */ - /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: @@ -1002,469 +1122,468 @@ ECHO; * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ - - static int yy_get_next_buffer() +static int yy_get_next_buffer (void) { - register char* dest = yy_current_buffer->yy_ch_buf; - register char* source = yytext_ptr; - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; int ret_val; - if (yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1]) + 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"); + "fatal flex scanner internal error--end of buffer missed" ); - if (yy_current_buffer->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) - { + 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; + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); - for (i = 0; i < number_to_move; ++i) + for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); - if (yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING) + 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->yy_n_chars = yy_n_chars = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; - - while (num_to_read <= 0) - { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( - "input buffer overflow, can't enlarge buffer because scanner uses REJECT"); -#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; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = - (int)(yy_c_buf_p - b->yy_ch_buf); + (int) ((yy_c_buf_p) - b->yy_ch_buf); - if (b->yy_is_our_buffer) - { + if ( b->yy_is_our_buffer ) + { int new_size = b->yy_buf_size * 2; - if (new_size <= 0) + if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; else b->yy_buf_size *= 2; - b->yy_ch_buf = (char*) + b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yy_flex_realloc((void*)b->yy_ch_buf, - b->yy_buf_size + 2); - } + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; - if (!b->yy_ch_buf) + if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow"); + "fatal error - scanner input buffer overflow" ); - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; -#endif - } + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; - if (num_to_read > YY_READ_BUF_SIZE) + } + + if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ - YY_INPUT((&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read); + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); - yy_current_buffer->yy_n_chars = yy_n_chars; - } + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } - if (yy_n_chars == 0) - { - if (number_to_move == YY_MORE_ADJ) + if ( (yy_n_chars) == 0 ) { + if ( number_to_move == YY_MORE_ADJ ) + { ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin); - } + yyrestart( yyin ); + } else - { + { ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = + 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->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + (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() + 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; - yy_state_ptr = yy_state_buf; - *yy_state_ptr++ = yy_current_state; + yy_state_type yy_current_state; + 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); - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { - yy_current_state = (int)yy_def[yy_current_state]; - if (yy_current_state >= 78) - yy_c = yy_meta[(unsigned int)yy_c]; + 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 >= 78 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int)yy_c]; - *yy_state_ptr++ = yy_current_state; - } 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 ); */ - -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state) -#else -static yy_state_type yy_try_NUL_trans(yy_current_state) -yy_state_type yy_current_state; -#endif + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - register int yy_is_jam; + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); - register YY_CHAR yy_c = 1; - 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 >= 78) - yy_c = yy_meta[(unsigned int)yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int)yy_c]; + 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 >= 78 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 77); - if (!yy_is_jam) - *yy_state_ptr++ = yy_current_state; - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } - #ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput(int c, register char* yy_bp) -#else -static void yyunput(c, yy_bp) -int c; -register char* yy_bp; -#endif + + static void yyunput (int c, char * yy_bp ) { - register char* yy_cp = yy_c_buf_p; + char *yy_cp; + + yy_cp = (yy_c_buf_p); /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; - - if (yy_cp < yy_current_buffer->yy_ch_buf + 2) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char* dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char* source = - &yy_current_buffer->yy_ch_buf[number_to_move]; - - while (source > yy_current_buffer->yy_ch_buf) + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) *--dest = *--source; - yy_cp += (int)(dest - source); - yy_bp += (int)(dest - source); - yy_current_buffer->yy_n_chars = - yy_n_chars = yy_current_buffer->yy_buf_size; + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - if (yy_cp < yy_current_buffer->yy_ch_buf + 2) - YY_FATAL_ERROR("flex scanner push-back overflow"); - } + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } - *--yy_cp = (char)c; + *--yy_cp = (char) c; - if (c == '\n') - --yylineno; + if ( c == '\n' ){ + --yylineno; + } - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; } -#endif /* ifndef YY_NO_UNPUT */ +#endif +#ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput() + static int yyinput (void) #else -static int input() + static int input (void) #endif + { int c; + + *(yy_c_buf_p) = (yy_hold_char); - *yy_c_buf_p = yy_hold_char; - - if (*yy_c_buf_p == YY_END_OF_BUFFER_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->yy_ch_buf[yy_n_chars]) + 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'; + *(yy_c_buf_p) = '\0'; else - { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; + { /* need more input */ + int offset = (int) ((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. - */ + 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); + /* Reset buffer status. */ + yyrestart( yyin ); - /* fall through */ + /*FALLTHROUGH*/ - case EOB_ACT_END_OF_FILE: - { - if (yywrap()) - return EOF; + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; - if (!yy_did_buffer_switch_on_eof) - YY_NEW_FILE; + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(); #else - return input(); + return input(); #endif - } + } - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; - break; + 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; + 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); - if (c == '\n') - ++yylineno; + if ( c == '\n' ) + + yylineno++; +; return c; } +#endif /* ifndef YY_NO_INPUT */ - -#ifdef YY_USE_PROTOS -void yyrestart(FILE* input_file) -#else -void yyrestart(input_file) -FILE* input_file; -#endif +/** 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) - yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE); + + 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(); + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); } - -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer) -#else -void yy_switch_to_buffer(new_buffer) -YY_BUFFER_STATE new_buffer; -#endif +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { - if (yy_current_buffer == 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) - { + if ( YY_CURRENT_BUFFER ) + { /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } + *(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 = new_buffer; - yy_load_buffer_state(); + 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; + (yy_did_buffer_switch_on_eof) = 1; } - -#ifdef YY_USE_PROTOS -void yy_load_buffer_state(void) -#else -void yy_load_buffer_state() -#endif +static void yy_load_buffer_state (void) { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; + (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); } - -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer(FILE* file, int size) -#else -YY_BUFFER_STATE yy_create_buffer(file, size) -FILE* file; -int size; -#endif +/** 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)yy_flex_alloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); + + 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*)yy_flex_alloc(b->yy_buf_size + 2); - if (!b->yy_ch_buf) - YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (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); + yy_init_buffer( b, file ); return b; } - -#ifdef YY_USE_PROTOS -void yy_delete_buffer(YY_BUFFER_STATE b) -#else -void yy_delete_buffer(b) -YY_BUFFER_STATE b; -#endif +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) { - if (!b) + + if ( ! b ) return; - if (b == yy_current_buffer) - yy_current_buffer = (YY_BUFFER_STATE)0; + 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) - yy_flex_free((void*)b->yy_ch_buf); + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); - yy_flex_free((void*)b); + yyfree( (void *) b ); } - -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO((int)); -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer(YY_BUFFER_STATE b, FILE* file) -#else -void yy_init_buffer(b, file) -YY_BUFFER_STATE b; -FILE* file; -#endif - +/* 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 ) { - yy_flush_buffer(b); + int oerrno = errno; + + yy_flush_buffer( b ); b->yy_input_file = file; b->yy_fill_buffer = 1; -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0; -#endif -#endif + /* 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 = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; } - -#ifdef YY_USE_PROTOS -void yy_flush_buffer(YY_BUFFER_STATE b) -#else -void yy_flush_buffer(b) -YY_BUFFER_STATE b; -#endif - +/** 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) + if ( ! b ) return; b->yy_n_chars = 0; @@ -1481,94 +1600,185 @@ YY_BUFFER_STATE b; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; - if (b == yy_current_buffer) - yy_load_buffer_state(); + 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; -#ifndef YY_NO_SCAN_BUFFER -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer(char* base, yy_size_t size) -#else -YY_BUFFER_STATE yy_scan_buffer(base, size) -char* base; -yy_size_t size; -#endif + 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) { - YY_BUFFER_STATE b; + 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 (size < 2 || - base[size - 2] != YY_END_OF_BUFFER_CHAR || - base[size - 1] != YY_END_OF_BUFFER_CHAR) + 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) +{ + yy_size_t 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; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + 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. */ + yy_size_t 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*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* 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; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ - return 0; + return NULL; - b = (YY_BUFFER_STATE)yy_flex_alloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer(b); + yy_switch_to_buffer( b ); return b; } -#endif - -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string(yyconst char* yy_str) -#else -YY_BUFFER_STATE yy_scan_string(yy_str) -yyconst char* yy_str; -#endif +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (const char * yystr ) { - int len; - for (len = 0; yy_str[len]; ++len) - ; - - return yy_scan_bytes(yy_str, len); + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); } -#endif - -#ifndef YY_NO_SCAN_BYTES -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes(yyconst char* bytes, int len) -#else -YY_BUFFER_STATE yy_scan_bytes(bytes, len) -yyconst char* bytes; -int len; -#endif +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; - char* buf; + char *buf; yy_size_t n; int i; - + /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char*)yy_flex_alloc(n); - if (!buf) - YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()"); + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - for (i = 0; i < len; ++i) - buf[i] = bytes[i]; + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; - buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR; + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer(buf, n); - if (!b) - YY_FATAL_ERROR("bad buffer in yy_scan_bytes()"); + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. @@ -1577,147 +1787,200 @@ int len; return b; } -#endif - -#ifndef YY_NO_PUSH_STATE -#ifdef YY_USE_PROTOS -static void yy_push_state(int new_state) -#else -static void yy_push_state(new_state) -int new_state; +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 #endif + +static void yynoreturn yy_fatal_error (const char* msg ) { - if (yy_start_stack_ptr >= yy_start_stack_depth) - { - yy_size_t new_size; + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof(int); +/* Redefine yyless() so it works in section 3 code. */ - if (!yy_start_stack) - yy_start_stack = (int*)yy_flex_alloc(new_size); +#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 ) - else - yy_start_stack = (int*)yy_flex_realloc( - (void*)yy_start_stack, new_size); +/* Accessor methods (get/set functions) to struct members. */ - if (!yy_start_stack) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack"); - } +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} - yy_start_stack[yy_start_stack_ptr++] = YY_START; +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} - BEGIN(new_state); +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; } -#endif +/** Get the current token. + * + */ -#ifndef YY_NO_POP_STATE -static void yy_pop_state() +char *yyget_text (void) { - if (--yy_start_stack_ptr < 0) - YY_FATAL_ERROR("start-condition stack underflow"); + return yytext; +} - BEGIN(yy_start_stack[yy_start_stack_ptr]); +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; } -#endif +/** 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 ; +} -#ifndef YY_NO_TOP_STATE -static int yy_top_state() +void yyset_out (FILE * _out_str ) { - return yy_start_stack[yy_start_stack_ptr - 1]; + yyout = _out_str ; } -#endif -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif +int yyget_debug (void) +{ + return yy_flex_debug; +} -#ifdef YY_USE_PROTOS -static void yy_fatal_error(yyconst char msg[]) -#else -static void yy_fatal_error(msg) -char msg[]; -#endif +void yyset_debug (int _bdebug ) { - (void)fprintf(stderr, "%s\n", msg); - exit(YY_EXIT_FAILURE); + 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. + */ + + /* We do not touch yylineno unless the option is enabled. */ + yylineno = 1; + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} -/* Redefine yyless() so it works in section 3 code. */ +/* 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(); + } -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) + /* 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. */ +/* + * Internal utility routines. + */ #ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy(char* s1, yyconst char* s2, int n) -#else -static void yy_flex_strncpy(s1, s2, n) -char* s1; -yyconst char* s2; -int n; -#endif +static void yy_flex_strncpy (char* s1, const char * s2, int n ) { - register int i; - for (i = 0; i < n; ++i) + + int i; + for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen(yyconst char* s) -#else -static int yy_flex_strlen(s) -yyconst char* s; -#endif +static int yy_flex_strlen (const char * s ) { - register int n; - for (n = 0; s[n]; ++n) + int n; + for ( n = 0; s[n]; ++n ) ; return n; } #endif - -#ifdef YY_USE_PROTOS -static void* yy_flex_alloc(yy_size_t size) -#else -static void* yy_flex_alloc(size) -yy_size_t size; -#endif +void *yyalloc (yy_size_t size ) { - return (void*)malloc(size); + return malloc(size); } -#ifdef YY_USE_PROTOS -static void* yy_flex_realloc(void* ptr, yy_size_t size) -#else -static void* yy_flex_realloc(ptr, size) -void* ptr; -yy_size_t size; -#endif +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 @@ -1725,24 +1988,15 @@ yy_size_t size; * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void*)realloc((char*)ptr, size); + return realloc(ptr, size); } -#ifdef YY_USE_PROTOS -static void yy_flex_free(void* ptr) -#else -static void yy_flex_free(ptr) -void* ptr; -#endif +void yyfree (void * ptr ) { - free(ptr); + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } -#if YY_MAIN -int main() -{ - yylex(); - return 0; -} -#endif -#line 83 "tokens.l" +#define YYTABLES_NAME "yytables" + +#line 83 "./tokens.l" + diff --git a/test/02_mv1.sy b/test/02_mv1.sy new file mode 100644 index 0000000..d716acb --- /dev/null +++ b/test/02_mv1.sy @@ -0,0 +1,71 @@ +int x; + +const int N = 2010; + +void mv(int n, int A[][N], int b[], int res[]){ + int x, y; + y = 0; + x = 11; + int i, j; + + i = 0; + while(i < n){ + res[i] = 0; + i = i + 1; + } + + i = 0; + j = 0; + while (i < n){ + j = 0; + while (j < n){ + if (A[i][j] == 0){ + x = x * b[i] + b[j]; + y = y - x; + }else{ + res[i] = res[i] + A[i][j] * b[j]; + } + j = j + 1; + } + i = i + 1; + } +} + +int A[N][N]; +int B[N]; +int C[N]; + +int main(){ + int n = getint(); + int i, j; + + i = 0; + + while (i < n){ + j = 0; + while (j < n){ + A[i][j] = getint(); + j = j + 1; + } + i = i + 1; + } + + i = 0; + while (i < n){ + B[i] = getint(); + i = i + 1; + } + + starttime(); + + i = 0; + while (i < 50){ + mv(n, A, B, C); + mv(n, A, C, B); + i = i + 1; + } + stoptime(); + + putarray(n, C); + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/000_main.out b/test/function_test2021/000_main.out new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/test/function_test2021/000_main.out @@ -0,0 +1 @@ +3 diff --git a/test/function_test2021/000_main.sy b/test/function_test2021/000_main.sy new file mode 100644 index 0000000..0efccbf --- /dev/null +++ b/test/function_test2021/000_main.sy @@ -0,0 +1,3 @@ +int main(){ + return 3; +} \ No newline at end of file diff --git a/test/function_test2021/001_var_defn.out b/test/function_test2021/001_var_defn.out new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/test/function_test2021/001_var_defn.out @@ -0,0 +1 @@ +8 diff --git a/test/function_test2021/001_var_defn.sy b/test/function_test2021/001_var_defn.sy new file mode 100644 index 0000000..3def749 --- /dev/null +++ b/test/function_test2021/001_var_defn.sy @@ -0,0 +1,7 @@ +//test global var define +int a = 3; +int b = 5; + +int main(){ + return a + b; +} \ No newline at end of file diff --git a/test/function_test2021/002_var_defn2.out b/test/function_test2021/002_var_defn2.out new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/test/function_test2021/002_var_defn2.out @@ -0,0 +1 @@ +10 diff --git a/test/function_test2021/002_var_defn2.sy b/test/function_test2021/002_var_defn2.sy new file mode 100644 index 0000000..8fdccfa --- /dev/null +++ b/test/function_test2021/002_var_defn2.sy @@ -0,0 +1,8 @@ +//test domain of global var define and local define +int a = 3; +int b = 5; + +int main(){ + int a = 5; + return a + b; +} \ No newline at end of file diff --git a/test/function_test2021/003_var_defn3.out b/test/function_test2021/003_var_defn3.out new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/test/function_test2021/003_var_defn3.out @@ -0,0 +1 @@ +5 diff --git a/test/function_test2021/003_var_defn3.sy b/test/function_test2021/003_var_defn3.sy new file mode 100644 index 0000000..192d060 --- /dev/null +++ b/test/function_test2021/003_var_defn3.sy @@ -0,0 +1,8 @@ +//test local var define +int main(){ + int a, b0, _c; + a = 1; + b0 = 2; + _c = 3; + return b0 + _c; +} \ No newline at end of file diff --git a/test/function_test2021/004_arr_defn.out b/test/function_test2021/004_arr_defn.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/function_test2021/004_arr_defn.out @@ -0,0 +1 @@ +0 diff --git a/test/function_test2021/004_arr_defn.sy b/test/function_test2021/004_arr_defn.sy new file mode 100644 index 0000000..0fa1ceb --- /dev/null +++ b/test/function_test2021/004_arr_defn.sy @@ -0,0 +1,4 @@ +int a[10]; +int main(){ + return 0; +} diff --git a/test/function_test2021/005_arr_defn2.out b/test/function_test2021/005_arr_defn2.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/function_test2021/005_arr_defn2.out @@ -0,0 +1 @@ +0 diff --git a/test/function_test2021/005_arr_defn2.sy b/test/function_test2021/005_arr_defn2.sy new file mode 100644 index 0000000..fa1accd --- /dev/null +++ b/test/function_test2021/005_arr_defn2.sy @@ -0,0 +1,4 @@ +int a[10][10]; +int main(){ + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/006_arr_defn3.out b/test/function_test2021/006_arr_defn3.out new file mode 100644 index 0000000..8351c19 --- /dev/null +++ b/test/function_test2021/006_arr_defn3.out @@ -0,0 +1 @@ +14 diff --git a/test/function_test2021/006_arr_defn3.sy b/test/function_test2021/006_arr_defn3.sy new file mode 100644 index 0000000..d268998 --- /dev/null +++ b/test/function_test2021/006_arr_defn3.sy @@ -0,0 +1,9 @@ +//test array define +int main(){ + int a[4][2] = {}; + int b[4][2] = {1, 2, 3, 4, 5, 6, 7, 8}; + int c[4][2] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; + int d[4][2] = {1, 2, {3}, {5}, 7 , 8}; + int e[4][2] = {{d[2][1], c[2][1]}, {3, 4}, {5, 6}, {7, 8}}; + return e[3][1] + e[0][0] + e[0][1] + a[2][0]; +} \ No newline at end of file diff --git a/test/function_test2021/007_arr_defn4.out b/test/function_test2021/007_arr_defn4.out new file mode 100644 index 0000000..aabe6ec --- /dev/null +++ b/test/function_test2021/007_arr_defn4.out @@ -0,0 +1 @@ +21 diff --git a/test/function_test2021/007_arr_defn4.sy b/test/function_test2021/007_arr_defn4.sy new file mode 100644 index 0000000..51a0e2c --- /dev/null +++ b/test/function_test2021/007_arr_defn4.sy @@ -0,0 +1,9 @@ +int main(){ + const int a[4][2] = {{1, 2}, {3, 4}, {}, 7}; + const int N = 3; + int b[4][2] = {}; + int c[4][2] = {1, 2, 3, 4, 5, 6, 7, 8}; + int d[N + 1][2] = {1, 2, {3}, {5}, a[3][0], 8}; + int e[4][2][1] = {{d[2][1], {c[2][1]}}, {3, 4}, {5, 6}, {7, 8}}; + return e[3][1][0] + e[0][0][0] + e[0][1][0] + d[3][0]; +} diff --git a/test/function_test2021/008_const_var_defn.out b/test/function_test2021/008_const_var_defn.out new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/test/function_test2021/008_const_var_defn.out @@ -0,0 +1 @@ +10 diff --git a/test/function_test2021/008_const_var_defn.sy b/test/function_test2021/008_const_var_defn.sy new file mode 100644 index 0000000..bfc9cf4 --- /dev/null +++ b/test/function_test2021/008_const_var_defn.sy @@ -0,0 +1,6 @@ +//test global var define +const int a = 10; + +int main(){ + return a; +} \ No newline at end of file diff --git a/test/function_test2021/009_const_var_defn2.out b/test/function_test2021/009_const_var_defn2.out new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/test/function_test2021/009_const_var_defn2.out @@ -0,0 +1 @@ +5 diff --git a/test/function_test2021/009_const_var_defn2.sy b/test/function_test2021/009_const_var_defn2.sy new file mode 100644 index 0000000..333801c --- /dev/null +++ b/test/function_test2021/009_const_var_defn2.sy @@ -0,0 +1,6 @@ +//test const gloal var define +const int a = 10, b = 5; + +int main(){ + return b; +} \ No newline at end of file diff --git a/test/function_test2021/010_const_var_defn3.out b/test/function_test2021/010_const_var_defn3.out new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/test/function_test2021/010_const_var_defn3.out @@ -0,0 +1 @@ +5 diff --git a/test/function_test2021/010_const_var_defn3.sy b/test/function_test2021/010_const_var_defn3.sy new file mode 100644 index 0000000..4dfd2e9 --- /dev/null +++ b/test/function_test2021/010_const_var_defn3.sy @@ -0,0 +1,5 @@ +//test const local var define +int main(){ + const int a = 10, b = 5; + return b; +} \ No newline at end of file diff --git a/test/function_test2021/011_const_array_defn.out b/test/function_test2021/011_const_array_defn.out new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/test/function_test2021/011_const_array_defn.out @@ -0,0 +1 @@ +4 diff --git a/test/function_test2021/011_const_array_defn.sy b/test/function_test2021/011_const_array_defn.sy new file mode 100644 index 0000000..4238a31 --- /dev/null +++ b/test/function_test2021/011_const_array_defn.sy @@ -0,0 +1,5 @@ +const int a[5]={0,1,2,3,4}; + +int main(){ + return a[4]; +} \ No newline at end of file diff --git a/test/function_test2021/012_func_defn.out b/test/function_test2021/012_func_defn.out new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/test/function_test2021/012_func_defn.out @@ -0,0 +1 @@ +9 diff --git a/test/function_test2021/012_func_defn.sy b/test/function_test2021/012_func_defn.sy new file mode 100644 index 0000000..8b5acb2 --- /dev/null +++ b/test/function_test2021/012_func_defn.sy @@ -0,0 +1,11 @@ +int a; +int func(int p){ + p = p - 1; + return p; +} +int main(){ + int b; + a = 10; + b = func(a); + return b; +} diff --git a/test/function_test2021/013_var_defn_func.out b/test/function_test2021/013_var_defn_func.out new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/test/function_test2021/013_var_defn_func.out @@ -0,0 +1 @@ +4 diff --git a/test/function_test2021/013_var_defn_func.sy b/test/function_test2021/013_var_defn_func.sy new file mode 100644 index 0000000..03ab608 --- /dev/null +++ b/test/function_test2021/013_var_defn_func.sy @@ -0,0 +1,8 @@ +int defn(){ + return 4; +} + +int main(){ + int a=defn(); + return a; +} \ No newline at end of file diff --git a/test/function_test2021/014_add.out b/test/function_test2021/014_add.out new file mode 100644 index 0000000..48082f7 --- /dev/null +++ b/test/function_test2021/014_add.out @@ -0,0 +1 @@ +12 diff --git a/test/function_test2021/014_add.sy b/test/function_test2021/014_add.sy new file mode 100644 index 0000000..aebe726 --- /dev/null +++ b/test/function_test2021/014_add.sy @@ -0,0 +1,7 @@ +//test add +int main(){ + int a, b; + a = 10; + b = 2; + return a + b; +} \ No newline at end of file diff --git a/test/function_test2021/015_add2.out b/test/function_test2021/015_add2.out new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/test/function_test2021/015_add2.out @@ -0,0 +1 @@ +9 diff --git a/test/function_test2021/015_add2.sy b/test/function_test2021/015_add2.sy new file mode 100644 index 0000000..229ae98 --- /dev/null +++ b/test/function_test2021/015_add2.sy @@ -0,0 +1,7 @@ +//test add +int main(){ + int a, b; + a = 10; + b = -1; + return a + b; +} \ No newline at end of file diff --git a/test/function_test2021/016_addc.out b/test/function_test2021/016_addc.out new file mode 100644 index 0000000..60d3b2f --- /dev/null +++ b/test/function_test2021/016_addc.out @@ -0,0 +1 @@ +15 diff --git a/test/function_test2021/016_addc.sy b/test/function_test2021/016_addc.sy new file mode 100644 index 0000000..550ed2a --- /dev/null +++ b/test/function_test2021/016_addc.sy @@ -0,0 +1,5 @@ +//test addc +const int a = 10; +int main(){ + return a + 5; +} \ No newline at end of file diff --git a/test/function_test2021/017_sub.out b/test/function_test2021/017_sub.out new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/test/function_test2021/017_sub.out @@ -0,0 +1 @@ +8 diff --git a/test/function_test2021/017_sub.sy b/test/function_test2021/017_sub.sy new file mode 100644 index 0000000..eb4ecd7 --- /dev/null +++ b/test/function_test2021/017_sub.sy @@ -0,0 +1,7 @@ +//test sub +int main(){ + int a, b; + a = 10; + b = 2; + return a - b; +} \ No newline at end of file diff --git a/test/function_test2021/018_sub2.out b/test/function_test2021/018_sub2.out new file mode 100644 index 0000000..5d0b6c4 --- /dev/null +++ b/test/function_test2021/018_sub2.out @@ -0,0 +1 @@ +248 diff --git a/test/function_test2021/018_sub2.sy b/test/function_test2021/018_sub2.sy new file mode 100644 index 0000000..54b8d5b --- /dev/null +++ b/test/function_test2021/018_sub2.sy @@ -0,0 +1,7 @@ +//test sub +const int a = 10; +int main(){ + int b; + b = 2; + return b - a; +} \ No newline at end of file diff --git a/test/function_test2021/019_subc.out b/test/function_test2021/019_subc.out new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/test/function_test2021/019_subc.out @@ -0,0 +1 @@ +8 diff --git a/test/function_test2021/019_subc.sy b/test/function_test2021/019_subc.sy new file mode 100644 index 0000000..d23843b --- /dev/null +++ b/test/function_test2021/019_subc.sy @@ -0,0 +1,6 @@ +//test subc +int main(){ + int a; + a = 10; + return a - 2; +} \ No newline at end of file diff --git a/test/function_test2021/020_mul.out b/test/function_test2021/020_mul.out new file mode 100644 index 0000000..e373ee6 --- /dev/null +++ b/test/function_test2021/020_mul.out @@ -0,0 +1 @@ +50 diff --git a/test/function_test2021/020_mul.sy b/test/function_test2021/020_mul.sy new file mode 100644 index 0000000..4d3453d --- /dev/null +++ b/test/function_test2021/020_mul.sy @@ -0,0 +1,7 @@ +//test mul +int main(){ + int a, b; + a = 10; + b = 5; + return a * b; +} \ No newline at end of file diff --git a/test/function_test2021/021_mulc.out b/test/function_test2021/021_mulc.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/021_mulc.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/021_mulc.sy b/test/function_test2021/021_mulc.sy new file mode 100644 index 0000000..b975a62 --- /dev/null +++ b/test/function_test2021/021_mulc.sy @@ -0,0 +1,5 @@ +//test mulc +const int a = 5; +int main(){ + return a * 5; +} \ No newline at end of file diff --git a/test/function_test2021/022_div.out b/test/function_test2021/022_div.out new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test/function_test2021/022_div.out @@ -0,0 +1 @@ +2 diff --git a/test/function_test2021/022_div.sy b/test/function_test2021/022_div.sy new file mode 100644 index 0000000..49506f3 --- /dev/null +++ b/test/function_test2021/022_div.sy @@ -0,0 +1,7 @@ +//test div +int main(){ + int a, b; + a = 10; + b = 5; + return a / b; +} \ No newline at end of file diff --git a/test/function_test2021/023_divc.out b/test/function_test2021/023_divc.out new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test/function_test2021/023_divc.out @@ -0,0 +1 @@ +2 diff --git a/test/function_test2021/023_divc.sy b/test/function_test2021/023_divc.sy new file mode 100644 index 0000000..07505ab --- /dev/null +++ b/test/function_test2021/023_divc.sy @@ -0,0 +1,5 @@ +//test divc +const int a = 10; +int main(){ + return a / 5; +} \ No newline at end of file diff --git a/test/function_test2021/024_mod.out b/test/function_test2021/024_mod.out new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/test/function_test2021/024_mod.out @@ -0,0 +1 @@ +3 diff --git a/test/function_test2021/024_mod.sy b/test/function_test2021/024_mod.sy new file mode 100644 index 0000000..b186545 --- /dev/null +++ b/test/function_test2021/024_mod.sy @@ -0,0 +1,6 @@ +//test mod +int main(){ + int a; + a = 10; + return a / 3; +} \ No newline at end of file diff --git a/test/function_test2021/025_rem.out b/test/function_test2021/025_rem.out new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/function_test2021/025_rem.out @@ -0,0 +1 @@ +1 diff --git a/test/function_test2021/025_rem.sy b/test/function_test2021/025_rem.sy new file mode 100644 index 0000000..6aa8143 --- /dev/null +++ b/test/function_test2021/025_rem.sy @@ -0,0 +1,6 @@ +//test rem +int main(){ + int a; + a = 10; + return a % 3; +} \ No newline at end of file diff --git a/test/function_test2021/026_if.out b/test/function_test2021/026_if.out new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/function_test2021/026_if.out @@ -0,0 +1 @@ +1 diff --git a/test/function_test2021/026_if.sy b/test/function_test2021/026_if.sy new file mode 100644 index 0000000..a908d63 --- /dev/null +++ b/test/function_test2021/026_if.sy @@ -0,0 +1,9 @@ +int a; + +int main(){ + a = 10; + if( a>0 ){ + return 1; + } + return 0; +} diff --git a/test/function_test2021/027_if2.out b/test/function_test2021/027_if2.out new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/function_test2021/027_if2.out @@ -0,0 +1 @@ +1 diff --git a/test/function_test2021/027_if2.sy b/test/function_test2021/027_if2.sy new file mode 100644 index 0000000..a4f5062 --- /dev/null +++ b/test/function_test2021/027_if2.sy @@ -0,0 +1,10 @@ +int a; +int main(){ + a = 10; + if( a>0 ){ + return 1; + } + else{ + return 0; + } +} diff --git a/test/function_test2021/028_if_test1.out b/test/function_test2021/028_if_test1.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/028_if_test1.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/028_if_test1.sy b/test/function_test2021/028_if_test1.sy new file mode 100644 index 0000000..1811e94 --- /dev/null +++ b/test/function_test2021/028_if_test1.sy @@ -0,0 +1,16 @@ +// test if-else +int ifElse() { + int a; + a = 5; + if (a == 5) { + a = 25; + } else { + a = a * 2; + } + return (a); +} + + +int main() { + return (ifElse()); +} diff --git a/test/function_test2021/029_if_test2.out b/test/function_test2021/029_if_test2.out new file mode 100644 index 0000000..330e18d --- /dev/null +++ b/test/function_test2021/029_if_test2.out @@ -0,0 +1,2 @@ +-5 +0 diff --git a/test/function_test2021/029_if_test2.sy b/test/function_test2021/029_if_test2.sy new file mode 100644 index 0000000..bf7b8fa --- /dev/null +++ b/test/function_test2021/029_if_test2.sy @@ -0,0 +1,25 @@ +// test if-else-if +int ifElseIf() { + int a; + a = 5; + int b; + b = 10; + if(a == 6 || b == 0xb) { + return a; + } + else { + if (b == 10 && a == 1) + a = 25; + else if (b == 10 && a == -5) + a = a + 15; + else + a = -+a; + } + + return a; +} + +int main(){ + putint(ifElseIf()); + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/030_if_test3.out b/test/function_test2021/030_if_test3.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/030_if_test3.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/030_if_test3.sy b/test/function_test2021/030_if_test3.sy new file mode 100644 index 0000000..7f48df1 --- /dev/null +++ b/test/function_test2021/030_if_test3.sy @@ -0,0 +1,18 @@ +// test if-if-else +int ififElse() { + int a; + a = 5; + int b; + b = 10; + if(a == 5) + if (b == 10) + a = 25; + else + a = a + 15; + + return (a); +} + +int main(){ + return (ififElse()); +} diff --git a/test/function_test2021/031_if_test4.out b/test/function_test2021/031_if_test4.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/031_if_test4.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/031_if_test4.sy b/test/function_test2021/031_if_test4.sy new file mode 100644 index 0000000..fb01502 --- /dev/null +++ b/test/function_test2021/031_if_test4.sy @@ -0,0 +1,18 @@ +// test if-{if-else} +int if_ifElse_() { + int a; + a = 5; + int b; + b = 10; + if(a == 5){ + if (b == 10) + a = 25; + else + a = a + 15; + } + return (a); +} + +int main(){ + return (if_ifElse_()); +} diff --git a/test/function_test2021/032_if_test5.out b/test/function_test2021/032_if_test5.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/032_if_test5.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/032_if_test5.sy b/test/function_test2021/032_if_test5.sy new file mode 100644 index 0000000..39cf890 --- /dev/null +++ b/test/function_test2021/032_if_test5.sy @@ -0,0 +1,18 @@ +// test if-{if}-else +int if_if_Else() { + int a; + a = 5; + int b; + b = 10; + if(a == 5){ + if (b == 10) + a = 25; + } + else + a = a + 15; + return (a); +} + +int main(){ + return (if_if_Else()); +} diff --git a/test/function_test2021/033_while_if.out b/test/function_test2021/033_while_if.out new file mode 100644 index 0000000..abe17ac --- /dev/null +++ b/test/function_test2021/033_while_if.out @@ -0,0 +1,2 @@ +88 +0 diff --git a/test/function_test2021/033_while_if.sy b/test/function_test2021/033_while_if.sy new file mode 100644 index 0000000..47b8b79 --- /dev/null +++ b/test/function_test2021/033_while_if.sy @@ -0,0 +1,31 @@ +int get_one(int a) { + return 1; +} + +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (get_one(0) == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + p = deepWhileBr(p, p); + putint(p); + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/034_while_test1.out b/test/function_test2021/034_while_test1.out new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/test/function_test2021/034_while_test1.out @@ -0,0 +1 @@ +3 diff --git a/test/function_test2021/034_while_test1.sy b/test/function_test2021/034_while_test1.sy new file mode 100644 index 0000000..d184d5b --- /dev/null +++ b/test/function_test2021/034_while_test1.sy @@ -0,0 +1,18 @@ +int doubleWhile() { + int i; + i = 5; + int j; + j = 7; + while (i < 100) { + i = i + 30; + while(j < 100){ + j = j + 6; + } + j = j - 100; + } + return (j); +} + +int main() { + return doubleWhile(); +} diff --git a/test/function_test2021/035_while_test2.out b/test/function_test2021/035_while_test2.out new file mode 100644 index 0000000..fb1e7bc --- /dev/null +++ b/test/function_test2021/035_while_test2.out @@ -0,0 +1 @@ +54 diff --git a/test/function_test2021/035_while_test2.sy b/test/function_test2021/035_while_test2.sy new file mode 100644 index 0000000..d1fad82 --- /dev/null +++ b/test/function_test2021/035_while_test2.sy @@ -0,0 +1,31 @@ +int FourWhile() { + int a; + a = 5; + int b; + int c; + b = 6; + c = 7; + int d; + d = 10; + while (a < 20) { + a = a + 3; + while(b < 10){ + b = b + 1; + while(c == 7){ + c = c - 1; + while(d < 20){ + d = d + 3; + } + d = d - 1; + } + c = c + 1; + } + b = b - 2; + } + + return (a + (b + d) + c); +} + +int main() { + return FourWhile(); +} diff --git a/test/function_test2021/036_while_test3.out b/test/function_test2021/036_while_test3.out new file mode 100644 index 0000000..4099407 --- /dev/null +++ b/test/function_test2021/036_while_test3.out @@ -0,0 +1 @@ +23 diff --git a/test/function_test2021/036_while_test3.sy b/test/function_test2021/036_while_test3.sy new file mode 100644 index 0000000..47ffb5f --- /dev/null +++ b/test/function_test2021/036_while_test3.sy @@ -0,0 +1,55 @@ +int g; +int h; +int f; +int e; +int EightWhile() { + int a; + a = 5; + int b; + int c; + b = 6; + c = 7; + int d; + d = 10; + while (a < 20) { + a = a + 3; + while(b < 10){ + b = b + 1; + while(c == 7){ + c = c - 1; + while(d < 20){ + d = d + 3; + while(e > 1){ + e = e-1; + while(f > 2){ + f = f -2; + while(g < 3){ + g = g +10; + while(h < 10){ + h = h + 8; + } + h = h-1; + } + g = g- 8; + } + f = f + 1; + } + e = e + 1; + } + d = d - 1; + } + c = c + 1; + } + b = b - 2; + } + + return (a + (b + d) + c)-(e + d - g + h); +} + +int main() { + g = 1; + h = 2; + e = 4; + f = 6; + return EightWhile(); +} diff --git a/test/function_test2021/037_break.out b/test/function_test2021/037_break.out new file mode 100644 index 0000000..3bc92d4 --- /dev/null +++ b/test/function_test2021/037_break.out @@ -0,0 +1 @@ +201 diff --git a/test/function_test2021/037_break.sy b/test/function_test2021/037_break.sy new file mode 100644 index 0000000..2ab2a05 --- /dev/null +++ b/test/function_test2021/037_break.sy @@ -0,0 +1,15 @@ +//test break +int main(){ + int i; + i = 0; + int sum; + sum = 0; + while(i < 100){ + if(i == 50){ + break; + } + sum = sum + i; + i = i + 1; + } + return sum; +} \ No newline at end of file diff --git a/test/function_test2021/038_continue.out b/test/function_test2021/038_continue.out new file mode 100644 index 0000000..7facc89 --- /dev/null +++ b/test/function_test2021/038_continue.out @@ -0,0 +1 @@ +36 diff --git a/test/function_test2021/038_continue.sy b/test/function_test2021/038_continue.sy new file mode 100644 index 0000000..df09865 --- /dev/null +++ b/test/function_test2021/038_continue.sy @@ -0,0 +1,16 @@ +//test continue +int main(){ + int i; + i = 0; + int sum; + sum = 0; + while(i < 10){ + if(i == 5){ + i = i + 1; + continue; + } + sum = sum + i; + i = i + 1; + } + return sum; +} diff --git a/test/function_test2021/039_while_if_test1.out b/test/function_test2021/039_while_if_test1.out new file mode 100644 index 0000000..ca55a6c --- /dev/null +++ b/test/function_test2021/039_while_if_test1.out @@ -0,0 +1 @@ +198 diff --git a/test/function_test2021/039_while_if_test1.sy b/test/function_test2021/039_while_if_test1.sy new file mode 100644 index 0000000..2d2b9fb --- /dev/null +++ b/test/function_test2021/039_while_if_test1.sy @@ -0,0 +1,25 @@ +// test while-if +int whileIf() { + int a; + a = 0; + int b; + b = 0; + while (a < 100) { + if (a == 5) { + b = 25; + } + else if (a == 10) { + b = 42; + } + else { + b = a * 2; + } + a = a + 1; + } + return (b); +} + + +int main(){ + return (whileIf()); +} diff --git a/test/function_test2021/040_while_if_test2.out b/test/function_test2021/040_while_if_test2.out new file mode 100644 index 0000000..f906e18 --- /dev/null +++ b/test/function_test2021/040_while_if_test2.out @@ -0,0 +1 @@ +96 diff --git a/test/function_test2021/040_while_if_test2.sy b/test/function_test2021/040_while_if_test2.sy new file mode 100644 index 0000000..34c92da --- /dev/null +++ b/test/function_test2021/040_while_if_test2.sy @@ -0,0 +1,23 @@ +int ifWhile() { + int a; + a = 0; + int b; + b = 3; + if (a == 5) { + while(b == 2){ + b = b + 2; + } + b = b + 25; + } + else + while (a < 5) { + b = b * 2; + a = a + 1; + } + return (b); +} + + +int main(){ + return (ifWhile()); +} diff --git a/test/function_test2021/041_while_if_test3.out b/test/function_test2021/041_while_if_test3.out new file mode 100644 index 0000000..d22307c --- /dev/null +++ b/test/function_test2021/041_while_if_test3.out @@ -0,0 +1 @@ +88 diff --git a/test/function_test2021/041_while_if_test3.sy b/test/function_test2021/041_while_if_test3.sy new file mode 100644 index 0000000..ef16dfa --- /dev/null +++ b/test/function_test2021/041_while_if_test3.sy @@ -0,0 +1,25 @@ +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (1 == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + return deepWhileBr(p, p); +} diff --git a/test/function_test2021/042_arr_expr_len.out b/test/function_test2021/042_arr_expr_len.out new file mode 100644 index 0000000..82cced2 --- /dev/null +++ b/test/function_test2021/042_arr_expr_len.out @@ -0,0 +1 @@ +51 diff --git a/test/function_test2021/042_arr_expr_len.sy b/test/function_test2021/042_arr_expr_len.sy new file mode 100644 index 0000000..391776e --- /dev/null +++ b/test/function_test2021/042_arr_expr_len.sy @@ -0,0 +1,11 @@ +const int N = -1; +int arr[N + 2 * 4 - 99 / 99] = {1, 2, 33, 4, 5, 6}; + +int main() { + int i = 0, sum = 0; + while (i < 6) { + sum = sum + arr[i]; + i = i + 1; + } + return sum; +} diff --git a/test/function_test2021/043_op_priority1.out b/test/function_test2021/043_op_priority1.out new file mode 100644 index 0000000..425151f --- /dev/null +++ b/test/function_test2021/043_op_priority1.out @@ -0,0 +1 @@ +40 diff --git a/test/function_test2021/043_op_priority1.sy b/test/function_test2021/043_op_priority1.sy new file mode 100644 index 0000000..2d745b2 --- /dev/null +++ b/test/function_test2021/043_op_priority1.sy @@ -0,0 +1,9 @@ +//test the priority of add and mul +int main(){ + int a, b, c, d; + a = 10; + b = 4; + c = 2; + d = 2; + return c + a * b - d; +} \ No newline at end of file diff --git a/test/function_test2021/044_op_priority2.out b/test/function_test2021/044_op_priority2.out new file mode 100644 index 0000000..a45fd52 --- /dev/null +++ b/test/function_test2021/044_op_priority2.out @@ -0,0 +1 @@ +24 diff --git a/test/function_test2021/044_op_priority2.sy b/test/function_test2021/044_op_priority2.sy new file mode 100644 index 0000000..ac9c015 --- /dev/null +++ b/test/function_test2021/044_op_priority2.sy @@ -0,0 +1,9 @@ +//test the priority of add and mul +int main(){ + int a, b, c, d; + a = 10; + b = 4; + c = 2; + d = 2; + return (c + a) * (b - d); +} \ No newline at end of file diff --git a/test/function_test2021/045_op_priority3.out b/test/function_test2021/045_op_priority3.out new file mode 100644 index 0000000..425151f --- /dev/null +++ b/test/function_test2021/045_op_priority3.out @@ -0,0 +1 @@ +40 diff --git a/test/function_test2021/045_op_priority3.sy b/test/function_test2021/045_op_priority3.sy new file mode 100644 index 0000000..e04c930 --- /dev/null +++ b/test/function_test2021/045_op_priority3.sy @@ -0,0 +1,7 @@ +//test the priority of unary operator and binary operator +int main(){ + int a, b; + a = 10; + b = 30; + return a - -5 + b + -5; +} \ No newline at end of file diff --git a/test/function_test2021/046_op_priority4.in b/test/function_test2021/046_op_priority4.in new file mode 100644 index 0000000..ecfbc7c --- /dev/null +++ b/test/function_test2021/046_op_priority4.in @@ -0,0 +1 @@ +0 1 1 1 1 diff --git a/test/function_test2021/046_op_priority4.out b/test/function_test2021/046_op_priority4.out new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/function_test2021/046_op_priority4.out @@ -0,0 +1 @@ +1 diff --git a/test/function_test2021/046_op_priority4.sy b/test/function_test2021/046_op_priority4.sy new file mode 100644 index 0000000..6246557 --- /dev/null +++ b/test/function_test2021/046_op_priority4.sy @@ -0,0 +1,19 @@ +int a; +int b; +int c; +int d; +int e; +int main() +{ + a=getint(); + b=getint(); + c=getint(); + d=getint(); + e=getint(); + int flag=0; + if(a-b*c!=d-a/c||a*b/c==e+d||a+b+c==d+e) + { + flag=1; + } + return flag; +} diff --git a/test/function_test2021/047_op_priority5.out b/test/function_test2021/047_op_priority5.out new file mode 100644 index 0000000..6ed281c --- /dev/null +++ b/test/function_test2021/047_op_priority5.out @@ -0,0 +1,2 @@ +1 +1 diff --git a/test/function_test2021/047_op_priority5.sy b/test/function_test2021/047_op_priority5.sy new file mode 100644 index 0000000..ac787fc --- /dev/null +++ b/test/function_test2021/047_op_priority5.sy @@ -0,0 +1,15 @@ +int a = 1; +int b = 0; +int c = 1; +int d = 2; +int e = 4; +int main() +{ + int flag=0; + if(a * b / c == e + d && a * (a + b) + c <= d + e || a - (b * c) == d - a / c) + { + flag=1; + } + putint(flag); + return flag; +} \ No newline at end of file diff --git a/test/function_test2021/048_stmt_expr.out b/test/function_test2021/048_stmt_expr.out new file mode 100644 index 0000000..670473d --- /dev/null +++ b/test/function_test2021/048_stmt_expr.out @@ -0,0 +1,2 @@ +1024 +0 diff --git a/test/function_test2021/048_stmt_expr.sy b/test/function_test2021/048_stmt_expr.sy new file mode 100644 index 0000000..a5f5bb5 --- /dev/null +++ b/test/function_test2021/048_stmt_expr.sy @@ -0,0 +1,13 @@ +int k; +const int n = 10; +int main () { + int i = 0; + k = 1; + while (i <= n - 1) { + i = i + 1; + k + 1; + k = k + k; + } + putint(k); + return k; +} diff --git a/test/function_test2021/049_unary_op.out b/test/function_test2021/049_unary_op.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/function_test2021/049_unary_op.out @@ -0,0 +1 @@ +0 diff --git a/test/function_test2021/049_unary_op.sy b/test/function_test2021/049_unary_op.sy new file mode 100644 index 0000000..eb5e28c --- /dev/null +++ b/test/function_test2021/049_unary_op.sy @@ -0,0 +1,11 @@ +int main() { + int a; + a = 10; + if (+-!!!a) { + a = - - -1; + } + else { + a = 0; + } + return a; +} \ No newline at end of file diff --git a/test/function_test2021/050_unary_op2.out b/test/function_test2021/050_unary_op2.out new file mode 100644 index 0000000..661d826 --- /dev/null +++ b/test/function_test2021/050_unary_op2.out @@ -0,0 +1,2 @@ +4 +0 diff --git a/test/function_test2021/050_unary_op2.sy b/test/function_test2021/050_unary_op2.sy new file mode 100644 index 0000000..a824266 --- /dev/null +++ b/test/function_test2021/050_unary_op2.sy @@ -0,0 +1,14 @@ +int main() { + int a, b; + a = 070; + b = 0x4; + a = a - - 4 + + b; + if (+-!!!a) { + a = - - -1; + } + else { + a = 0 + + b; + } + putint(a); + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/051_logi_assign.in b/test/function_test2021/051_logi_assign.in new file mode 100644 index 0000000..8835c07 --- /dev/null +++ b/test/function_test2021/051_logi_assign.in @@ -0,0 +1 @@ +4 4 diff --git a/test/function_test2021/051_logi_assign.out b/test/function_test2021/051_logi_assign.out new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/function_test2021/051_logi_assign.out @@ -0,0 +1 @@ +1 diff --git a/test/function_test2021/051_logi_assign.sy b/test/function_test2021/051_logi_assign.sy new file mode 100644 index 0000000..dd96553 --- /dev/null +++ b/test/function_test2021/051_logi_assign.sy @@ -0,0 +1,15 @@ +int a; +int b; +int main() +{ + a=getint(); + b=getint(); + int c; + if (a==b&&a!=3) { + c = 1; + } + else { + c = 0; + } + return c; +} diff --git a/test/function_test2021/052_comment1.out b/test/function_test2021/052_comment1.out new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/test/function_test2021/052_comment1.out @@ -0,0 +1 @@ +5 diff --git a/test/function_test2021/052_comment1.sy b/test/function_test2021/052_comment1.sy new file mode 100644 index 0000000..d14c157 --- /dev/null +++ b/test/function_test2021/052_comment1.sy @@ -0,0 +1,8 @@ +//test comment +int main(){ + int a; + a = 5; + //int b = 4; + //a = b + a; + return a; +} \ No newline at end of file diff --git a/test/function_test2021/053_comment2.out b/test/function_test2021/053_comment2.out new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test/function_test2021/053_comment2.out @@ -0,0 +1 @@ +2 diff --git a/test/function_test2021/053_comment2.sy b/test/function_test2021/053_comment2.sy new file mode 100644 index 0000000..fa2438a --- /dev/null +++ b/test/function_test2021/053_comment2.sy @@ -0,0 +1,11 @@ +//test comment +int main(){ + int a, b; + a = 10; + b = 2; + /*/* + b = 1; + // b = 2 + */ + return b; +} \ No newline at end of file diff --git a/test/function_test2021/054_hex_defn.out b/test/function_test2021/054_hex_defn.out new file mode 100644 index 0000000..60d3b2f --- /dev/null +++ b/test/function_test2021/054_hex_defn.out @@ -0,0 +1 @@ +15 diff --git a/test/function_test2021/054_hex_defn.sy b/test/function_test2021/054_hex_defn.sy new file mode 100644 index 0000000..3f20fdf --- /dev/null +++ b/test/function_test2021/054_hex_defn.sy @@ -0,0 +1,6 @@ +// test hexadecimal define +int main(){ + int a; + a = 0xf; + return a; +} \ No newline at end of file diff --git a/test/function_test2021/055_hex_oct_add.out b/test/function_test2021/055_hex_oct_add.out new file mode 100644 index 0000000..d22307c --- /dev/null +++ b/test/function_test2021/055_hex_oct_add.out @@ -0,0 +1 @@ +88 diff --git a/test/function_test2021/055_hex_oct_add.sy b/test/function_test2021/055_hex_oct_add.sy new file mode 100644 index 0000000..545a8cd --- /dev/null +++ b/test/function_test2021/055_hex_oct_add.sy @@ -0,0 +1,7 @@ +//test add of hex and oct +int main(){ + int a, b; + a = 0xf; + b = 0xc; + return a + b + 075; +} \ No newline at end of file diff --git a/test/function_test2021/056_assign_complex_expr.out b/test/function_test2021/056_assign_complex_expr.out new file mode 100644 index 0000000..d0890d1 --- /dev/null +++ b/test/function_test2021/056_assign_complex_expr.out @@ -0,0 +1,2 @@ +-171 +0 diff --git a/test/function_test2021/056_assign_complex_expr.sy b/test/function_test2021/056_assign_complex_expr.sy new file mode 100644 index 0000000..c6471a7 --- /dev/null +++ b/test/function_test2021/056_assign_complex_expr.sy @@ -0,0 +1,18 @@ +// Use complex expression in assign structure +int main () { + int a; + int b; + int c; + int d; + int result; + a = 5; + b = 5; + c = 1; + d = -2; + result = (d * 1 / 2) + (a - b) - -(c + 3) % 2; + putint(result); + result = ((d % 2 + 67) + -(a - b) - -((c + 2) % 2)); + result = result + 3; + putint(result); + return 0; +} diff --git a/test/function_test2021/057_if_complex_expr.out b/test/function_test2021/057_if_complex_expr.out new file mode 100644 index 0000000..389e262 --- /dev/null +++ b/test/function_test2021/057_if_complex_expr.out @@ -0,0 +1,2 @@ +2 +0 diff --git a/test/function_test2021/057_if_complex_expr.sy b/test/function_test2021/057_if_complex_expr.sy new file mode 100644 index 0000000..32c897c --- /dev/null +++ b/test/function_test2021/057_if_complex_expr.sy @@ -0,0 +1,21 @@ +// Use complex expression in if structure +int main () { + int a; + int b; + int c; + int d; + int result; + a = 5; + b = 5; + c = 1; + d = -2; + result = 2; + if ((d * 1 / 2) < 0 || (a - b) != 0 && (c + 3) % 2 != 0) { + putint(result); + } + if ((d % 2 + 67) < 0 || (a - b) != 0 && (c + 2) % 2 != 0) { + result = 4; + putint(result); + } + return 0; +} diff --git a/test/function_test2021/058_short_circuit.in b/test/function_test2021/058_short_circuit.in new file mode 100644 index 0000000..71f0f6a --- /dev/null +++ b/test/function_test2021/058_short_circuit.in @@ -0,0 +1,4 @@ +11 +10 +100 +99 \ No newline at end of file diff --git a/test/function_test2021/058_short_circuit.out b/test/function_test2021/058_short_circuit.out new file mode 100644 index 0000000..882e4db --- /dev/null +++ b/test/function_test2021/058_short_circuit.out @@ -0,0 +1,2 @@ +11111210 +0 diff --git a/test/function_test2021/058_short_circuit.sy b/test/function_test2021/058_short_circuit.sy new file mode 100644 index 0000000..322855d --- /dev/null +++ b/test/function_test2021/058_short_circuit.sy @@ -0,0 +1,21 @@ +int g = 0; + +int func(int n) { + g = g + n; + putint(g); + return g; +} + +int main() { + int i; + i = getint(); + if (i > 10 && func(i)) i = 1; else i = 0; + i = getint(); + if (i > 11 && func(i)) i = 1; else i = 0; + i = getint(); + if (i <= 99 || func(i)) i = 1; else i = 0; + i = getint(); + if (i <= 100 || func(i)) i = 1; else i = 0; + if (!func(99) && func(100)) i = 1; else i = 0; + return 0; +} diff --git a/test/function_test2021/059_short_circuit2.out b/test/function_test2021/059_short_circuit2.out new file mode 100644 index 0000000..911faf0 --- /dev/null +++ b/test/function_test2021/059_short_circuit2.out @@ -0,0 +1,2 @@ +05040 +0 diff --git a/test/function_test2021/059_short_circuit2.sy b/test/function_test2021/059_short_circuit2.sy new file mode 100644 index 0000000..7dbfca0 --- /dev/null +++ b/test/function_test2021/059_short_circuit2.sy @@ -0,0 +1,26 @@ +int func(int n) { + if (n <= 50) { + putint(n); + return 1; + } + else { + putint(n); + return 0; + } +} + +int main() { + int i; + + if (func(0) == 1 || func(50) == 1 && func(100) == 0) + i = 0; + else + i = 1; + + if (func(50) == 1 && func(40) == 1 || func(1) == 1 ) + i = 0; + else + i = 1; + + return 0; +} diff --git a/test/function_test2021/060_scope.out b/test/function_test2021/060_scope.out new file mode 100644 index 0000000..b261da1 --- /dev/null +++ b/test/function_test2021/060_scope.out @@ -0,0 +1,2 @@ +1 +0 diff --git a/test/function_test2021/060_scope.sy b/test/function_test2021/060_scope.sy new file mode 100644 index 0000000..7be1453 --- /dev/null +++ b/test/function_test2021/060_scope.sy @@ -0,0 +1,27 @@ +int a = 7; + +int func() { + int b = a; + int a = 1; + if (a == b) { + a = a + 1; + return 1; + } + else + return 0; +} + +int main() { + int result = 0; + int i = 0; + while (i < 100) { + if (func() == 1) + result = result + 1; + i = i + 1; + } + if (result < 100) + putint(1); + else + putint(0); + return 0; +} diff --git a/test/function_test2021/061_sort_test1.out b/test/function_test2021/061_sort_test1.out new file mode 100644 index 0000000..c9f2be1 --- /dev/null +++ b/test/function_test2021/061_sort_test1.out @@ -0,0 +1,11 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 diff --git a/test/function_test2021/061_sort_test1.sy b/test/function_test2021/061_sort_test1.sy new file mode 100644 index 0000000..8491e90 --- /dev/null +++ b/test/function_test2021/061_sort_test1.sy @@ -0,0 +1,41 @@ +int n; +int bubblesort(int arr[]) +{ + int i; + int j; + i =0; + while(i < n-1){ + // Last i elements are already in place + j = 0; + while(j < n-i-1){ + if (arr[j] > arr[j+1]) { + // swap(&arr[j], &arr[j+1]); + int tmp; + tmp = arr[j+1]; + arr[j+1] = arr[j]; + arr[j] = tmp; + } + j = j + 1; + } + i = i + 1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = bubblesort(a); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} diff --git a/test/function_test2021/062_sort_test2.out b/test/function_test2021/062_sort_test2.out new file mode 100644 index 0000000..c9f2be1 --- /dev/null +++ b/test/function_test2021/062_sort_test2.out @@ -0,0 +1,11 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 diff --git a/test/function_test2021/062_sort_test2.sy b/test/function_test2021/062_sort_test2.sy new file mode 100644 index 0000000..8ec1764 --- /dev/null +++ b/test/function_test2021/062_sort_test2.sy @@ -0,0 +1,39 @@ +int n; +int insertsort(int a[]) +{ + int i; + i = 1; + while(i-1&&temp k - 1) + { + j = j - 1; + } + + if(i < j) + { + arr[i] = arr[j]; + i = i + 1; + } + + while(i < j && arr[i] < k) + { + i = i + 1; + } + + if(i < j) + { + arr[j] = arr[i]; + j = j - 1; + } + } + + arr[i] = k; + int tmp; + tmp = i - 1; + tmp = QuickSort(arr, low, tmp); + tmp = i + 1; + tmp = QuickSort(arr, tmp, high); + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + int tmp; + tmp = 9; + i = QuickSort(a, i, tmp); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} diff --git a/test/function_test2021/064_sort_test4.out b/test/function_test2021/064_sort_test4.out new file mode 100644 index 0000000..c9f2be1 --- /dev/null +++ b/test/function_test2021/064_sort_test4.out @@ -0,0 +1,11 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 diff --git a/test/function_test2021/064_sort_test4.sy b/test/function_test2021/064_sort_test4.sy new file mode 100644 index 0000000..9280cd1 --- /dev/null +++ b/test/function_test2021/064_sort_test4.sy @@ -0,0 +1,49 @@ +int n; +int select_sort(int A[],int n) +{ + int i; + int j; + int min; + i =0; + while(i < n-1) + { + min=i;// + j = i + 1; + while(j < n) + { + if(A[min]>A[j]) + { + min=j; + } + j=j+1; + } + if(min!=i) + { + int tmp; + tmp = A[min]; + A[min] = A[i]; + A[i] = tmp; + } + i = i + 1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + i = select_sort(a, n); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} diff --git a/test/function_test2021/065_sort_test5.out b/test/function_test2021/065_sort_test5.out new file mode 100644 index 0000000..c9f2be1 --- /dev/null +++ b/test/function_test2021/065_sort_test5.out @@ -0,0 +1,11 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 diff --git a/test/function_test2021/065_sort_test5.sy b/test/function_test2021/065_sort_test5.sy new file mode 100644 index 0000000..6c634e5 --- /dev/null +++ b/test/function_test2021/065_sort_test5.sy @@ -0,0 +1,65 @@ +int n; +int swap (int array[], int i, int j){ + int temp; + temp = array[i]; + array[i] = array[j]; + array[j] = temp; + return 0; +} +int heap_ajust(int arr[], int start, int end) { + int dad; + dad = start; + int son; + son = dad * 2 + 1; + while (son < end + 1) { // + if (son < end && arr[son] < arr[son + 1]) + son = son + 1; + if (arr[dad] > arr[son]) + return 0; + else { + dad = swap(arr,dad,son); + dad = son; + son = dad * 2 + 1; + } + } + return 0; +} +int heap_sort(int arr[], int len) { + int i; + int tmp; + i = len / 2 - 1; + while ( i > -1) { + tmp = len - 1; + tmp = heap_ajust(arr, i, tmp); + i = i - 1; + } + i = len - 1; + while ( i > 0) { + int tmp0; + tmp0 = 0; + tmp = swap(arr,tmp0,i); + tmp = i - 1; + tmp = heap_ajust(arr, tmp0, tmp); + i = i-1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + i = heap_sort(a, n); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} diff --git a/test/function_test2021/066_sort_test6.out b/test/function_test2021/066_sort_test6.out new file mode 100644 index 0000000..c9f2be1 --- /dev/null +++ b/test/function_test2021/066_sort_test6.out @@ -0,0 +1,11 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 diff --git a/test/function_test2021/066_sort_test6.sy b/test/function_test2021/066_sort_test6.sy new file mode 100644 index 0000000..24093c7 --- /dev/null +++ b/test/function_test2021/066_sort_test6.sy @@ -0,0 +1,53 @@ +int n; + +int counting_sort(int ini_arr[], int sorted_arr[], int n) { + int count_arr[10]; + int i; + int j; + int k; + k = 0; + i = 0; + j = 0; + while(k < 10){ + count_arr[k] = 0; + k = k + 1; + } + while(i < n) + { + count_arr[ini_arr[i]] = count_arr[ini_arr[i]] + 1; + i = i + 1; + } + k = 1; + while(k < 10){ + count_arr[k] = count_arr[k] + count_arr[k - 1]; + k = k + 1; + } + j = n; + while( j > 0){ + count_arr[ini_arr[j - 1]] = count_arr[ini_arr[j - 1]] - 1; + sorted_arr[count_arr[ini_arr[j - 1]]] = ini_arr[j - 1]; + j = j - 1; + } + return 0; +} + + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + int b[10]; + i = counting_sort(a, b, n); + while (i < n) { + int tmp; + tmp = b[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} diff --git a/test/function_test2021/067_sort_test7.in b/test/function_test2021/067_sort_test7.in new file mode 100644 index 0000000..623bd2a --- /dev/null +++ b/test/function_test2021/067_sort_test7.in @@ -0,0 +1,11 @@ +97 +-10525 -9882 48155 -22162 -38879 52218 -44913 14799 -52541 19859 + 23040 38767 -39850 -2221 -63865 51868 64903 -3812 -58581 -14684 +-29113 12117 -32032 -58451 -59283 -24783 -10753 -18185 28370 7266 + 760 30956 -35818 -52888 -37486 21562 14967 53534 46231 -46019 +-46994 -62145 24886 18009 63111 -14203 40779 51479 36163 14992 + 57399 -58381 5335 -38236 4245 -33049 33608 -63687 37320 -32676 + 6602 40444 1715 11292 2406 16023 1996 -60066 -52763 -16559 + 53676 22077 57606 46802 -2033 -64412 -58092 61266 59389 -38805 + 1155 59786 35700 52562 9161 -2723 -57451 46501 -2730 38395 + -2556 -38481 52802 -47314 -21799 -18640 60818 diff --git a/test/function_test2021/067_sort_test7.out b/test/function_test2021/067_sort_test7.out new file mode 100644 index 0000000..9edc34d --- /dev/null +++ b/test/function_test2021/067_sort_test7.out @@ -0,0 +1,2 @@ +97: -64412 -63865 -63687 -62145 -60066 -59283 -58581 -58451 -58381 -58092 -57451 -52888 -52763 -52541 -47314 -46994 -46019 -44913 -39850 -38879 -38805 -38481 -38236 -37486 -35818 -33049 -32676 -32032 -29113 -24783 -22162 -21799 -18640 -18185 -16559 -14684 -14203 -10753 -10525 -9882 -3812 -2730 -2723 -2556 -2221 -2033 760 1155 1715 1996 2406 4245 5335 6602 7266 9161 11292 12117 14799 14967 14992 16023 18009 19859 21562 22077 23040 24886 28370 30956 33608 35700 36163 37320 38395 38767 40444 40779 46231 46501 46802 48155 51479 51868 52218 52562 52802 53534 53676 57399 57606 59389 59786 60818 61266 63111 64903 +0 diff --git a/test/function_test2021/067_sort_test7.sy b/test/function_test2021/067_sort_test7.sy new file mode 100644 index 0000000..50561d3 --- /dev/null +++ b/test/function_test2021/067_sort_test7.sy @@ -0,0 +1,47 @@ +int buf[2][100]; + +// sort [l, r) +void merge_sort(int l, int r) +{ + if (l + 1 >= r) + return; + + int mid = (l + r) / 2; + merge_sort(l, mid); + merge_sort(mid, r); + + int i = l, j = mid, k = l; + while (i < mid && j < r) { + if (buf[0][i] < buf[0][j]) { + buf[1][k] = buf[0][i]; + i = i + 1; + } else { + buf[1][k] = buf[0][j]; + j = j + 1; + } + k = k + 1; + } + while (i < mid) { + buf[1][k] = buf[0][i]; + i = i + 1; + k = k + 1; + } + while (j < r) { + buf[1][k] = buf[0][j]; + j = j + 1; + k = k + 1; + } + + while (l < r) { + buf[0][l] = buf[1][l]; + l = l + 1; + } +} + +int main() +{ + int n = getarray(buf[0]); + merge_sort(0, n); + putarray(n, buf[0]); + return 0; +} diff --git a/test/function_test2021/068_genealogical_tree.in b/test/function_test2021/068_genealogical_tree.in new file mode 100644 index 0000000..0a80e02 --- /dev/null +++ b/test/function_test2021/068_genealogical_tree.in @@ -0,0 +1 @@ +0 4 5 1 0 1 0 5 3 0 3 0 diff --git a/test/function_test2021/068_genealogical_tree.out b/test/function_test2021/068_genealogical_tree.out new file mode 100644 index 0000000..a09d72d --- /dev/null +++ b/test/function_test2021/068_genealogical_tree.out @@ -0,0 +1,6 @@ +2 +4 +5 +3 +1 +0 diff --git a/test/function_test2021/068_genealogical_tree.sy b/test/function_test2021/068_genealogical_tree.sy new file mode 100644 index 0000000..cdb10f9 --- /dev/null +++ b/test/function_test2021/068_genealogical_tree.sy @@ -0,0 +1,68 @@ +int map[10][10]; +int indegree[10]; +int queue[10]; +void topo(int n) +{ + int m=0; + int t=0; + int i,j; + i=1; + j=1; + while(i<=n) + { + j=1; + while(j<=n) + { + if(indegree[j]==0) + { + + m=j; + break; + } + j=j+1; + } + queue[t]=m; + t=t+1; + indegree[m]=-1; + j=1; + while(j<=n) + + { + if(map[m][j]) + { + indegree[j]=indegree[j]-1; + } + j=j+1; + } + i=i+1; + } + i=0; + while(i 0){ + rem = m % n; + m = n; + n = rem; + } + return m; +} +int main(){ + int n,m; + int num; + m=getint(); + n=getint(); + num=fun(m,n); + putint(num); + + return 0; +} diff --git a/test/function_test2021/070_multiplication_puzzle.out b/test/function_test2021/070_multiplication_puzzle.out new file mode 100644 index 0000000..c92444c --- /dev/null +++ b/test/function_test2021/070_multiplication_puzzle.out @@ -0,0 +1,2 @@ +3650 +0 diff --git a/test/function_test2021/070_multiplication_puzzle.sy b/test/function_test2021/070_multiplication_puzzle.sy new file mode 100644 index 0000000..1ac205a --- /dev/null +++ b/test/function_test2021/070_multiplication_puzzle.sy @@ -0,0 +1,32 @@ +int a[6]={10,1,50,50,20,5}; +int dp[10][10]; +int main() +{ + int n; + n=6; + + int k,i,t,j,aa; + k=3; + while(k<=n) + { + i=0; + while(i 1 && array[loc - 1] != -1) { + mmerge(loc, loc - 1); + } + if (a < n && array[loc + n] != -1) { + mmerge(loc, loc + n); + } + if (a > 1 && array[loc - n] != -1) { + mmerge(loc, loc - n); + } + + if (array[0] != -1 && array[k] != -1 && findfa(0) == findfa(k)) { + flag = 1; + int tmp = i + 1; + putint(tmp); + putch(10); + } + } + + i = i + 1; + } + if (!flag) { + putint(-1); + putch(10); + } + } + return 0; +} diff --git a/test/function_test2021/073_backpack.out b/test/function_test2021/073_backpack.out new file mode 100644 index 0000000..227eae2 --- /dev/null +++ b/test/function_test2021/073_backpack.out @@ -0,0 +1,2 @@ +15 +0 diff --git a/test/function_test2021/073_backpack.sy b/test/function_test2021/073_backpack.sy new file mode 100644 index 0000000..c54d6ff --- /dev/null +++ b/test/function_test2021/073_backpack.sy @@ -0,0 +1,63 @@ +int V[200][200]={}; +int KnapSack(int n, int w[], int v[], int x[], int C) +{ + int i, j; + i=1; + while(i<=n) + { + j=0; + while(jtmp2) + { + V[i][j] = tmp1; + } + else + { + V[i][j] = tmp2; + } + + } + j=j+1; + } + i=i+1; + } + + j = C; + i=n; + while(i>=1) + { + if (V[i][j]>V[i - 1][j]) + { + x[i] = 1; + j = j - w[i]; + } + else + { + + x[i] = 0; + } + i=i-1; + } + return V[n][C]; +} + +int main() +{ + int s; + int w[6] = {0,2,2,6,5,4}; + int v[6] = {0,6,3,5,4,6}; + int x[6]; + int n = 5; + int C=10; + s = KnapSack(n, w, v, x, C); + putint(s); + return 0; + +} diff --git a/test/function_test2021/074_matrix_add.out b/test/function_test2021/074_matrix_add.out new file mode 100644 index 0000000..28b5f4b --- /dev/null +++ b/test/function_test2021/074_matrix_add.out @@ -0,0 +1,4 @@ +024 +024 +024 +0 diff --git a/test/function_test2021/074_matrix_add.sy b/test/function_test2021/074_matrix_add.sy new file mode 100644 index 0000000..4f9158e --- /dev/null +++ b/test/function_test2021/074_matrix_add.sy @@ -0,0 +1,70 @@ +int M; +int L; +int N; + + +int add(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[]) +{ + int i; + i=0; + while(i -1) { + t = c2[i]; + j = len1 - 1; + while (j > -1) { + temp = result[n] + t * c1[j]; + if(temp >= 10) { + result[n] = (temp); + result[n-1] = result[n-1] + temp / 10; + } + else + result[n] = temp; + j = j - 1; + n = n - 1; + } + n = n + len1 - 1; + i = i - 1; + } + + if(result[0] != 0) + putint(result[0]); + + i = 1; + while (i <= len1 + len2 - 1) { + putint(result[i]); + i = i + 1; + } + + return 0; +} \ No newline at end of file diff --git a/test/function_test2021/079_calculator.in b/test/function_test2021/079_calculator.in new file mode 100644 index 0000000..d488a8b --- /dev/null +++ b/test/function_test2021/079_calculator.in @@ -0,0 +1 @@ +(4 - (3 - 5) * 2 + 100) % (2^3 - 1) / 2 + 1 diff --git a/test/function_test2021/079_calculator.out b/test/function_test2021/079_calculator.out new file mode 100644 index 0000000..389e262 --- /dev/null +++ b/test/function_test2021/079_calculator.out @@ -0,0 +1,2 @@ +2 +0 diff --git a/test/function_test2021/079_calculator.sy b/test/function_test2021/079_calculator.sy new file mode 100644 index 0000000..f67a932 --- /dev/null +++ b/test/function_test2021/079_calculator.sy @@ -0,0 +1,184 @@ +int ints[10000]; +int intt; +int chas[10000]; +int chat; +int i=0, ii=1; +int c; +int get[10000]; +int get2[10000]; + +int isdigit(int x) { + if (x >= 48 && x <= 57) + return 1; + return 0; +} + +int power(int b, int a) { + int result = 1; + while (a != 0) { + result = result * b; + a = a - 1; + } + return result; +} + +int getstr(int get[]) { + int x = getch(); + int length = 0; + while (x != 13 && x != 10) { + get[length] = x; + length = length + 1; + x = getch(); + } + return length; +} + +void intpush(int x) +{ + intt = intt + 1; + ints[intt] = x; +} +void chapush(int x) +{ + chat = chat + 1; + chas[chat] = x; +} +int intpop() +{ + intt = intt - 1; + return ints[intt + 1]; +} +int chapop() +{ + chat = chat - 1; + return chas[chat + 1]; +} +void intadd(int x) +{ + ints[intt] = ints[intt] * 10; + ints[intt] = ints[intt] + x; +} + +int find() +{ + c = chapop(); + get2[ii] = 32; + get2[ii + 1] = c; + ii = ii + 2; + if (chat == 0) return 0; + return 1; +} + +int main() +{ + intt=0; + chat=0; + int lengets = getstr(get); + while (i < lengets) + { + if (isdigit(get[i]) == 1) + { + get2[ii] = get[i]; + ii = ii + 1; + } + else + { + if(get[i] == 40) chapush(40); + if(get[i] == 94) chapush(94); + if(get[i] == 41) + { + c = chapop(); + while (c != 40) + { + get2[ii] = 32; + get2[ii + 1]=c; + ii = ii + 2; + c = chapop(); + } + } + if (get[i] == 43) + { + while (chas[chat] == 43 || chas[chat] == 45 || chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(43); + } + if (get[i] == 45) + { + while (chas[chat] == 43 || chas[chat] == 45 ||chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if(find()==0)break; + } + chapush(45); + } + if(get[i] == 42) + { + while (chas[chat] == 42 || chas[chat] == 47 ||chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(42); + } + if (get[i] == 47) + { + while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(47); + } + if (get[i] == 37) + { + while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(37); + } + get2[ii] = 32; + ii = ii + 1; + } + i = i + 1; + } + while(chat > 0) + { + int c = chapop(); + get2[ii] = 32; + get2[ii + 1]=c; + ii = ii + 2; + } + get2[ii]= 64; + i = 1; + while (get2[i] != 64) + { + if (get2[i] == 43 || get2[i] == 45 || get2[i] == 42 || get2[i] == 47 || get2[i] == 37 || get2[i] == 94) + { + int a=intpop();int b=intpop();int c; + if (get2[i] == 43) c = a + b; + if (get2[i] == 45) c = b - a; + if (get2[i] == 42) c = a * b; + if (get2[i] == 47) c = b / a; + if (get2[i] == 37) c = b % a; + if (get2[i] == 94) c = power(b,a); + intpush(c); + } + else + { + if(get2[i] != 32) + { + intpush(get2[i] - 48); + ii=1; + while(get2[i+ii] != 32) + { + intadd(get2[i+ii] - 48); + ii = ii + 1; + } + i = i + ii-1; + } + } + i = i + 1; + } + putint(ints[1]); + return 0; +} diff --git a/test/function_test2021/080_color.in b/test/function_test2021/080_color.in new file mode 100644 index 0000000..36826c2 --- /dev/null +++ b/test/function_test2021/080_color.in @@ -0,0 +1,2 @@ +5 +2 2 2 2 2 \ No newline at end of file diff --git a/test/function_test2021/080_color.out b/test/function_test2021/080_color.out new file mode 100644 index 0000000..14f95f6 --- /dev/null +++ b/test/function_test2021/080_color.out @@ -0,0 +1,2 @@ +39480 +56 diff --git a/test/function_test2021/080_color.sy b/test/function_test2021/080_color.sy new file mode 100644 index 0000000..a18319e --- /dev/null +++ b/test/function_test2021/080_color.sy @@ -0,0 +1,69 @@ +const int maxn = 18; +const int mod = 1000000007; +int dp[maxn][maxn][maxn][maxn][maxn][7]; +int list[200]; + +int equal(int a, int b) { + if (a == b) + return 1; + return 0; +} + +int dfs(int a, int b, int c, int d, int e, int last){ + if(dp[a][b][c][d][e][last] != -1) + return dp[a][b][c][d][e][last]; + if(a + b + c + d + e == 0) + return 1; + int ans = 0; + if (a) ans = (ans + (a - equal(last, 2)) * dfs(a - 1, b, c, d, e, 1)) % mod; + if (b) ans = (ans + (b - equal(last, 3)) * dfs(a + 1, b - 1, c, d, e, 2)) % mod; + if (c) ans = (ans + (c - equal(last, 4)) * dfs(a, b + 1, c - 1, d, e, 3)) % mod; + if (d) ans = (ans + (d - equal(last, 5)) * dfs(a, b, c + 1, d - 1, e, 4)) % mod; + if (e) ans = (ans + e * dfs(a, b, c, d + 1, e - 1, 5)) % mod; + dp[a][b][c][d][e][last] = ans % mod; + return dp[a][b][c][d][e][last]; +} + +int cns[20]; + +int main(){ + int n = getint(); + int i = 0; + while (i < maxn) { + int j = 0; + while(j < maxn) { + int k = 0; + while(k < maxn) { + int l = 0; + while (l < maxn) { + int m = 0; + while (m < maxn) { + int h = 0; + while (h < 7) { + dp[i][j][k][l][m][h] = -1; + h = h + 1; + } + m = m + 1; + } + l = l + 1; + } + k = k + 1; + } + j = j + 1; + } + i = i + 1; + } + + i = 0; + while (i < n) { + list[i] = getint(); + cns[list[i]] = cns[list[i]] + 1; + i = i + 1; + } + + int ans = dfs(cns[1], cns[2], cns[3], cns[4], cns[5], 0); + + putint(ans); + + return ans; +} \ No newline at end of file diff --git a/test/function_test2021/100_array_concat.out b/test/function_test2021/100_array_concat.out new file mode 100644 index 0000000..64d98dc --- /dev/null +++ b/test/function_test2021/100_array_concat.out @@ -0,0 +1,2 @@ +012012 +0 diff --git a/test/function_test2021/100_array_concat.sy b/test/function_test2021/100_array_concat.sy new file mode 100644 index 0000000..7e69e38 --- /dev/null +++ b/test/function_test2021/100_array_concat.sy @@ -0,0 +1,52 @@ + +int concat(int a0[],int b0[],int c0[]) +{ + int i; + i=0; + while(i<3) + { + c0[i]=a0[i]; + + i=i+1; + } + int j; + j=0; + while(j<3) + { + c0[i]=b0[j]; + i=i+1; + j=j+1; + } + + return 0; + +} + +int main() +{ + int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3]; + int i; + i=0; + while(i<3) + { + a0[i]=i; + a1[i]=i; + a2[i]=i; + b0[i]=i; + b1[i]=i; + b2[i]=i; + i=i+1; + } + i=concat( a0,b0, c0); + int x; + while(i<6) + { + x = c0[i]; + putint(x); + i=i+1; + } + x = 10; + putch(x); + + return 0; +} diff --git a/test/function_test2021/101_insert_order.in b/test/function_test2021/101_insert_order.in new file mode 100644 index 0000000..c5b431b --- /dev/null +++ b/test/function_test2021/101_insert_order.in @@ -0,0 +1 @@ +50 \ No newline at end of file diff --git a/test/function_test2021/101_insert_order.out b/test/function_test2021/101_insert_order.out new file mode 100644 index 0000000..0da658a --- /dev/null +++ b/test/function_test2021/101_insert_order.out @@ -0,0 +1,11 @@ +1 +3 +4 +7 +8 +11 +13 +18 +50 +50 +0 diff --git a/test/function_test2021/101_insert_order.sy b/test/function_test2021/101_insert_order.sy new file mode 100644 index 0000000..9d1e7b8 --- /dev/null +++ b/test/function_test2021/101_insert_order.sy @@ -0,0 +1,55 @@ +//int n; +int N; +int insert(int a[],int x) +{ + int p; + int i; + p=0; + + while(x>a[p]&&pp) + { + a[i]=a[i-1]; + a[p]=x; + i=i-1; + + } + + return 0; +} + +int main() +{ + N=10; + int a[11]; + //a[0]=1; + a[0]=1; + a[1]=3; + a[2]=4; + a[3]=7; + a[4]=8; + a[5]=11; + a[6]=13; + a[7]=18; + a[8]=56; + a[9]=78; + int x; + int i; + i=0; + x=getint(); + x=insert(a,x); + //while() + while(i -1 && s[c] == 0){ + c = c - 1; + } + if(c == -1) + return 0; + int i; + i = c; + while(i > -1){ + if(s[i] == 0) + return n - i - 1 - (n - 1 - c); + i = i - 1; + } + return c - i; +} +int main(){ + int res; + int a[10]; + a[0]=-4;a[1]=3;a[2]=9;a[3]=-2;a[4]=0; + a[5]=1;a[6]=-6;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = lengthOfLastWord(a, res); + return res; +} \ No newline at end of file diff --git a/test/function_test2021/85_multi.out b/test/function_test2021/85_multi.out new file mode 100644 index 0000000..9aea9e0 --- /dev/null +++ b/test/function_test2021/85_multi.out @@ -0,0 +1,2 @@ +0 +0 \ No newline at end of file diff --git a/test/function_test2021/85_multi.sy b/test/function_test2021/85_multi.sy new file mode 100644 index 0000000..a73ac10 --- /dev/null +++ b/test/function_test2021/85_multi.sy @@ -0,0 +1,19 @@ +int main() +{ + //newline=10; + int i; + int sum; + sum=0; + //m = 1478; + //int t; + i=0; + while(i<21) + { + sum=sum*i; + i=i+1; + } + + putint(sum); + + return 0; +} diff --git a/test/function_test2021/86_max_subsequence_sum.out b/test/function_test2021/86_max_subsequence_sum.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/function_test2021/86_max_subsequence_sum.out @@ -0,0 +1 @@ +25 diff --git a/test/function_test2021/86_max_subsequence_sum.sy b/test/function_test2021/86_max_subsequence_sum.sy new file mode 100644 index 0000000..bbb4a84 --- /dev/null +++ b/test/function_test2021/86_max_subsequence_sum.sy @@ -0,0 +1,30 @@ +int maxSubArray(int nums[], int n) { + if(n == 0) + return 0; + if(n == 1) + return nums[0]; + int sum; + sum = nums[0]; + int max; + max = sum; + int i; + i = 1; + while(i < n){ + if(sum < 0) + sum = 0; + sum = sum + nums[i]; + if(max < sum) + max = sum; + i = i + 1; + } + return max; +} +int main(){ + int res; + int a[10]; + a[0]=-4;a[1]=3;a[2]=9;a[3]=-2;a[4]=0; + a[5]=1;a[6]=-6;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = maxSubArray(a, res); + return res; +} \ No newline at end of file diff --git a/test/function_test2021/87_enum.out b/test/function_test2021/87_enum.out new file mode 100644 index 0000000..f7ac686 --- /dev/null +++ b/test/function_test2021/87_enum.out @@ -0,0 +1,2 @@ +01000 +0 diff --git a/test/function_test2021/87_enum.sy b/test/function_test2021/87_enum.sy new file mode 100644 index 0000000..fc98413 --- /dev/null +++ b/test/function_test2021/87_enum.sy @@ -0,0 +1,27 @@ +int main() +{ + int i; + int j; + int k; + int t; + i=0;j=0;k=0; + while(i<21) + { + while(j<101-i) + { + k=100-i-j; + if(5*i+1*j+k/2==100) + { + putint(i); + putint(j); + putint(k); + t=10; + putch(t); + } + j=j+1; + } + i=i+1; + } + + return 0; +} diff --git a/test/function_test2021/88_exchange_value.in b/test/function_test2021/88_exchange_value.in new file mode 100644 index 0000000..4271cf2 --- /dev/null +++ b/test/function_test2021/88_exchange_value.in @@ -0,0 +1,2 @@ +4 +20 \ No newline at end of file diff --git a/test/function_test2021/88_exchange_value.out b/test/function_test2021/88_exchange_value.out new file mode 100644 index 0000000..f76b2c0 --- /dev/null +++ b/test/function_test2021/88_exchange_value.out @@ -0,0 +1,3 @@ +20 +4 +0 diff --git a/test/function_test2021/88_exchange_value.sy b/test/function_test2021/88_exchange_value.sy new file mode 100644 index 0000000..24f3536 --- /dev/null +++ b/test/function_test2021/88_exchange_value.sy @@ -0,0 +1,25 @@ +int n; + +int main() +{ + //newline=10; + int i; + int j; + //m = 1478; + //int t; + i=getint(); + j=getint(); + int temp; + temp=i; + i=j; + j=temp; + + putint(i); + temp = 10; + putch(temp); + putint(j); + temp = 10; + putch(temp); + + return 0; +} diff --git a/test/function_test2021/89_itera_sqrt.out b/test/function_test2021/89_itera_sqrt.out new file mode 100644 index 0000000..3ec8ae5 --- /dev/null +++ b/test/function_test2021/89_itera_sqrt.out @@ -0,0 +1,2 @@ +20 +0 diff --git a/test/function_test2021/89_itera_sqrt.sy b/test/function_test2021/89_itera_sqrt.sy new file mode 100644 index 0000000..1b970d1 --- /dev/null +++ b/test/function_test2021/89_itera_sqrt.sy @@ -0,0 +1,27 @@ +int fsqrt(int a) +{ + int x0=0; + int x1; + x1=a/2; + while(x0-x1!=0) + { + x0=x1; + x1=(x0+a/x0); + x1=x1/2; + } + + return x1; + +} + +int main() +{ + int a; + a=400; + int res; + res=fsqrt(a); + putint(res); + res = 10; + putch(res); + return 0; +} diff --git a/test/function_test2021/90_max_container.out b/test/function_test2021/90_max_container.out new file mode 100644 index 0000000..f6b91e0 --- /dev/null +++ b/test/function_test2021/90_max_container.out @@ -0,0 +1 @@ +56 diff --git a/test/function_test2021/90_max_container.sy b/test/function_test2021/90_max_container.sy new file mode 100644 index 0000000..df966d4 --- /dev/null +++ b/test/function_test2021/90_max_container.sy @@ -0,0 +1,33 @@ +int maxArea(int height[], int n) { + int i; + int j; + i = 0; + j = n - 1; + int max_val; + max_val = -1; + while(i < j){ + int area; + if(height[i] < height[j]) + area = (j - i) * height[i]; + else + area = (j - i) * height[j]; + if(area > max_val){ + max_val = area; + } + if(height[i] > height[j]) + j = j - 1; + else + i = i + 1; + } + return max_val; +} + +int main(){ + int res; + int a[10]; + a[0]=3;a[1]=3;a[2]=9;a[3]=0;a[4]=0; + a[5]=1;a[6]=1;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = maxArea(a, res); + return res; +} \ No newline at end of file diff --git a/test/function_test2021/91_int_factor_sum.out b/test/function_test2021/91_int_factor_sum.out new file mode 100644 index 0000000..730a054 --- /dev/null +++ b/test/function_test2021/91_int_factor_sum.out @@ -0,0 +1 @@ +172 diff --git a/test/function_test2021/91_int_factor_sum.sy b/test/function_test2021/91_int_factor_sum.sy new file mode 100644 index 0000000..2344c11 --- /dev/null +++ b/test/function_test2021/91_int_factor_sum.sy @@ -0,0 +1,33 @@ +int N; + +int newline; + +int factor(int n ) +{ + int i; + int sum; + sum=0; + i=1; + while(i -1){ + j=n-2; + while(j > -1){ + dp[i*3+j] = dp[(i+1)*3+j] + dp[i*3+j+1]; + j = j - 1; + } + i = i - 1; + } + return dp[0]; +} +int main(){ + int res; + int n; + n=3; + res = uniquePaths(n, n); + return res; +} \ No newline at end of file diff --git a/test/function_test2021/93_decbinoct.out b/test/function_test2021/93_decbinoct.out new file mode 100644 index 0000000..e4848b1 --- /dev/null +++ b/test/function_test2021/93_decbinoct.out @@ -0,0 +1,2 @@ +110010000 +0 diff --git a/test/function_test2021/93_decbinoct.sy b/test/function_test2021/93_decbinoct.sy new file mode 100644 index 0000000..8cc78ba --- /dev/null +++ b/test/function_test2021/93_decbinoct.sy @@ -0,0 +1,31 @@ +int dec2bin(int a) +{ + int res; + int k; + int i; + int temp; + res=0; + k=1; + temp=a; + while(temp!=0) + { + i=temp%2; + res=k*i+res; + k=k*10; + temp=temp/2; + } + return res; + +} + +int main() +{ + int a; + a=400; + int res; + res=dec2bin(a); + putint(res); + res = 10; + putch(res); + return 0; +} diff --git a/test/function_test2021/94_lcm.in b/test/function_test2021/94_lcm.in new file mode 100644 index 0000000..4271cf2 --- /dev/null +++ b/test/function_test2021/94_lcm.in @@ -0,0 +1,2 @@ +4 +20 \ No newline at end of file diff --git a/test/function_test2021/94_lcm.out b/test/function_test2021/94_lcm.out new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/test/function_test2021/94_lcm.out @@ -0,0 +1 @@ +20 diff --git a/test/function_test2021/94_lcm.sy b/test/function_test2021/94_lcm.sy new file mode 100644 index 0000000..4930995 --- /dev/null +++ b/test/function_test2021/94_lcm.sy @@ -0,0 +1,35 @@ +int n; + +int gcd(int m,int n) +{ + int a; + int b; + a=m; + b=n; + + int t; + int r; + + if(m n - 2) + return 1; + int dp[10]; + int i; + i = 0; + while(i -1){ + int j; + if(nums[i] < n - 1 - i){ + j = nums[i]; + } + else + j = n - 1 - i; + while(j > -1){ + if(dp[i+j] != 0){ + dp[i] = 1; + } + j = j - 1; + } + i = i - 1; + } + + return dp[0]; +} +int main(){ + int res; + int a[10]; + a[0]=3;a[1]=3;a[2]=9;a[3]=0;a[4]=0; + a[5]=1;a[6]=1;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = canJump(a, res); + return res; +} \ No newline at end of file diff --git a/test/function_test2021/96_int_split.out b/test/function_test2021/96_int_split.out new file mode 100644 index 0000000..d3c7935 --- /dev/null +++ b/test/function_test2021/96_int_split.out @@ -0,0 +1,5 @@ +1 +4 +7 +8 +0 \ No newline at end of file diff --git a/test/function_test2021/96_int_split.sy b/test/function_test2021/96_int_split.sy new file mode 100644 index 0000000..fb1e91e --- /dev/null +++ b/test/function_test2021/96_int_split.sy @@ -0,0 +1,40 @@ +int N; + +int newline; + +int split(int n ,int a[]) +{ + int i; + i=N-1; + while(i!=-1) + { + a[i]=n%10; + n=n/10; + i=i-1; + + } + + return 0; +} + +int main() +{ + N=4; + newline=10; + int i; + int m; + int b[4]; + m = 1478; + m = split(m,b); + int t; + i=0; + while(i<4) + { + t=b[i]; + putint(t); + putch(newline); + i=i+1; + + } + return 0; +} diff --git a/test/function_test2021/97_enc_dec.out b/test/function_test2021/97_enc_dec.out new file mode 100644 index 0000000..fda270a --- /dev/null +++ b/test/function_test2021/97_enc_dec.out @@ -0,0 +1,2 @@ +401 +0 diff --git a/test/function_test2021/97_enc_dec.sy b/test/function_test2021/97_enc_dec.sy new file mode 100644 index 0000000..5df25f9 --- /dev/null +++ b/test/function_test2021/97_enc_dec.sy @@ -0,0 +1,38 @@ +int enc(int a) +{ + if(a>25) + a=a+60; + else + { + a=a-15; + } + + return a; + +} + +int dec(int a) +{ + if (a>85) + a=a-59; + else + { + a=a+14; + } + + return a; + +} + +int main() +{ + int a; + a=400; + int res; + res=enc(a); + res=dec(res); + putint(res); + res = 10; + putch(res); + return 0; +} diff --git a/test/function_test2021/98_palindrome_number.out b/test/function_test2021/98_palindrome_number.out new file mode 100644 index 0000000..a79e55f --- /dev/null +++ b/test/function_test2021/98_palindrome_number.out @@ -0,0 +1,2 @@ +1221 +0 diff --git a/test/function_test2021/98_palindrome_number.sy b/test/function_test2021/98_palindrome_number.sy new file mode 100644 index 0000000..19aa459 --- /dev/null +++ b/test/function_test2021/98_palindrome_number.sy @@ -0,0 +1,42 @@ +int palindrome(int n) +{ + int a[4]; + int j; + int flag; + j=0; + while(j<4) + { + a[j]=n%10; + n=n/10; + j=j+1; + } + + if(a[0]==a[3] && a[1]==a[2]) + { + flag=1; + }else{ + flag=0; + } + return flag; +} + +int main() +{ + int test; + test=1221; + int flag; + flag=palindrome(test); + if(flag==1) + putint(test); + else + { + flag = 0; + putint(flag); + } + + flag = 10; + putch(flag); + + return 0; + +} diff --git a/test/function_test2021/99_bin_search.in b/test/function_test2021/99_bin_search.in new file mode 100644 index 0000000..62f9457 --- /dev/null +++ b/test/function_test2021/99_bin_search.in @@ -0,0 +1 @@ +6 \ No newline at end of file diff --git a/test/function_test2021/99_bin_search.out b/test/function_test2021/99_bin_search.out new file mode 100644 index 0000000..cdfade7 --- /dev/null +++ b/test/function_test2021/99_bin_search.out @@ -0,0 +1,2 @@ +6 +0 diff --git a/test/function_test2021/99_bin_search.sy b/test/function_test2021/99_bin_search.sy new file mode 100644 index 0000000..ce86475 --- /dev/null +++ b/test/function_test2021/99_bin_search.sy @@ -0,0 +1,51 @@ + +int main() +{ + //newline=10; + int i; + int sum; + int a[10]; + sum=0; + //m = 1478; + //int t; + i=0; + while(i<10) + { + a[i]=i+1; + i=i+1; + } + int x; + int high; + int low; + int mid; + int n; + n=10; + x=getint(); + high=n-1; + low=0; + mid=(high+low)/2; + while(a[mid]!=x && low < high) + { + mid=(high+low)/2; + if(x0 ){ + return 1; + } + return 0; +} + + +This is test AST: 026_if.sy + +NCompUnit + NVarDecl int a noinit + NFuncDecl int main + NAssignStmt a = 10 + NIfStmt NBinaryExp NIdentifierExp a > 0 + True: NBlockStmt + NReturnStmt 1 + NReturnStmt 0 + + +This is test IR: 026_if.sy + +a +int: a +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 2 + Store argNum:2 int:10 int: 0 + Br argNum:2 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 0 int:0 Block or something + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 1 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + + + +This is test: 027_if2.sy + +int a; +int main(){ + a = 10; + if( a>0 ){ + return 1; + } + else{ + return 0; + } +} + + +This is test AST: 027_if2.sy + +NCompUnit + NVarDecl int a noinit + NFuncDecl int main + NAssignStmt a = 10 + NIfStmt NBinaryExp NIdentifierExp a > 0 + True: NBlockStmt + NReturnStmt 1 + False: NBlockStmt + NReturnStmt 0 + + +This is test IR: 027_if2.sy + +a +int: a +Function: main entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 2 + Store argNum:2 int:10 int: 0 + Br argNum:3 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 0 int:0 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + BlockType 0 InstructionListLength = 0 + + + +This is test: 028_if_test1.sy + +// test if-else +int ifElse() { + int a; + a = 5; + if (a == 5) { + a = 25; + } else { + a = a * 2; + } + return (a); +} + + +int main() { + return (ifElse()); +} + + +This is test AST: 028_if_test1.sy + +NCompUnit + NFuncDecl int ifElse + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NBlockStmt + NAssignStmt a = 25 + False: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a * 2 + NReturnStmt NIdentifierExp a + NFuncDecl int main + NReturnStmt NCallExp ifElse + + +This is test IR: 028_if_test1.sy + +Function: ifElse entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Br argNum:3 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 0 int:5 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 0 int:2 int: 0 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 029_if_test2.sy + +// test if-else-if +int ifElseIf() { + int a; + a = 5; + int b; + b = 10; + if(a == 6 || b == 0xb) { + return a; + } + else { + if (b == 10 && a == 1) + a = 25; + else if (b == 10 && a == -5) + a = a + 15; + else + a = -+a; + } + + return a; +} + +int main(){ + putint(ifElseIf()); + return 0; +} + +This is test AST: 029_if_test2.sy + +NCompUnit + NFuncDecl int ifElseIf + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 10 + NIfStmt NBinaryExp NBinaryExp NIdentifierExp a == 6 | NBinaryExp NIdentifierExp b == 0 + True: NBlockStmt + NReturnStmt NIdentifierExp a + False: NBlockStmt + NIfStmt NBinaryExp NBinaryExp NIdentifierExp b == 10 & NBinaryExp NIdentifierExp a == 1 + True: NAssignStmt a = 25 + False: NIfStmt NBinaryExp NBinaryExp NIdentifierExp b == 10 & NBinaryExp NIdentifierExp a == NUnaryExp 277 5 + True: NAssignStmt a = NBinaryExp NIdentifierExp a + 15 + False: NAssignStmt a = NUnaryExp 277 NUnaryExp 276 NIdentifierExp a + NReturnStmt NIdentifierExp a + NFuncDecl int main + NExpStmt NCallExp putint NCallExp ifElseIf + NReturnStmt 0 + + +This is test IR: 029_if_test2.sy + +Segmentation fault + + +This is test: 030_if_test3.sy + +// test if-if-else +int ififElse() { + int a; + a = 5; + int b; + b = 10; + if(a == 5) + if (b == 10) + a = 25; + else + a = a + 15; + + return (a); +} + +int main(){ + return (ififElse()); +} + + +This is test AST: 030_if_test3.sy + +NCompUnit + NFuncDecl int ififElse + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 10 + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NIfStmt NBinaryExp NIdentifierExp b == 10 + True: NAssignStmt a = 25 + False: NAssignStmt a = NBinaryExp NIdentifierExp a + 15 + NReturnStmt NIdentifierExp a + NFuncDecl int main + NReturnStmt NCallExp ififElse + + +This is test IR: 030_if_test3.sy + +Function: ififElse entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 8 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:10 int: 1 + Store argNum:2 int:25 int: 0 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 1 int:10 Block or something + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:15 int: 0 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 0 int:5 Block or something + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 031_if_test4.sy + +// test if-{if-else} +int if_ifElse_() { + int a; + a = 5; + int b; + b = 10; + if(a == 5){ + if (b == 10) + a = 25; + else + a = a + 15; + } + return (a); +} + +int main(){ + return (if_ifElse_()); +} + + +This is test AST: 031_if_test4.sy + +NCompUnit + NFuncDecl int if_ifElse_ + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 10 + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp b == 10 + True: NAssignStmt a = 25 + False: NAssignStmt a = NBinaryExp NIdentifierExp a + 15 + NReturnStmt NIdentifierExp a + NFuncDecl int main + NReturnStmt NCallExp if_ifElse_ + + +This is test IR: 031_if_test4.sy + +Function: if_ifElse_ entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:10 int: 1 + BlockType 0 InstructionListLength = 3 + Store argNum:2 int:25 int: 0 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 1 int:10 Block or something + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 0 int:5 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:15 int: 0 + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 032_if_test5.sy + +// test if-{if}-else +int if_if_Else() { + int a; + a = 5; + int b; + b = 10; + if(a == 5){ + if (b == 10) + a = 25; + } + else + a = a + 15; + return (a); +} + +int main(){ + return (if_if_Else()); +} + + +This is test AST: 032_if_test5.sy + +NCompUnit + NFuncDecl int if_if_Else + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 10 + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp b == 10 + True: NAssignStmt a = 25 + False: NAssignStmt a = NBinaryExp NIdentifierExp a + 15 + NReturnStmt NIdentifierExp a + NFuncDecl int main + NReturnStmt NCallExp if_if_Else + + +This is test IR: 032_if_test5.sy + +Function: if_if_Else entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 8 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:10 int: 1 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 1 int:10 Block or something + Br argNum:3 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 0 int:5 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:15 int: 0 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 033_while_if.sy + +int get_one(int a) { + return 1; +} + +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (get_one(0) == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + p = deepWhileBr(p, p); + putint(p); + return 0; +} + +This is test AST: 033_while_if.sy + +NCompUnit + NFuncDecl int get_one + NVarDecl int a noinit + NReturnStmt 1 + NFuncDecl int deepWhileBr + NVarDecl int a noinit + NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NAssignStmt c = NBinaryExp NIdentifierExp a + NIdentifierExp b + NWhileStmt NBinaryExp NIdentifierExp c < 75 + While: NBlockStmt + NDeclStmt NVarDecl int d noinit + NAssignStmt d = 42 + NIfStmt NBinaryExp NIdentifierExp c < 100 + True: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp c + NIdentifierExp d + NIfStmt NBinaryExp NIdentifierExp c > 99 + True: NBlockStmt + NDeclStmt NVarDecl int e noinit + NAssignStmt e = NBinaryExp NIdentifierExp d * 2 + NIfStmt NBinaryExp NCallExp get_one 0 == 1 + True: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp e * 2 + NReturnStmt NIdentifierExp c + NFuncDecl int main + NDeclStmt NVarDecl int p noinit + NAssignStmt p = 2 + NAssignStmt p = NCallExp deepWhileBr NIdentifierExp p NIdentifierExp p + NExpStmt NCallExp putint NIdentifierExp p + NReturnStmt 0 + + +This is test IR: 033_while_if.sy + +Function: get_one entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 1 + +Function: deepWhileBr entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: -1773152720 +Instruction: Load argNum:1 int: -1773152720 int: 0 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:42 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 int: 0 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 1 int:2 int: 2 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:0 Block or something int:1 Block or something + Br argNum:2 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 0 int:99 Block or something + Br argNum:2 +Instruction: LT argNum:2 +Instruction: Load argNum:1 int: 0 int:100 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 2 int:2 int: 0 + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 5 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:2 int: 3 + Store argNum:2 +Instruction: Call argNum:3 +Instruction: Load argNum:1 int: 3 +Instruction: Load argNum:1 int: 3 Block or something int: 3 + constant argNum:1 int: 0 + + + +This is test: 034_while_test1.sy + +int doubleWhile() { + int i; + i = 5; + int j; + j = 7; + while (i < 100) { + i = i + 30; + while(j < 100){ + j = j + 6; + } + j = j - 100; + } + return (j); +} + +int main() { + return doubleWhile(); +} + + +This is test AST: 034_while_test1.sy + +NCompUnit + NFuncDecl int doubleWhile + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 5 + NDeclStmt NVarDecl int j noinit + NAssignStmt j = 7 + NWhileStmt NBinaryExp NIdentifierExp i < 100 + While: NBlockStmt + NAssignStmt i = NBinaryExp NIdentifierExp i + 30 + NWhileStmt NBinaryExp NIdentifierExp j < 100 + While: NBlockStmt + NAssignStmt j = NBinaryExp NIdentifierExp j + 6 + NAssignStmt j = NBinaryExp NIdentifierExp j - 100 + NReturnStmt NIdentifierExp j + NFuncDecl int main + NReturnStmt NCallExp doubleWhile + + +This is test IR: 034_while_test1.sy + +Function: doubleWhile entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:7 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:30 int: 0 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 1 int:6 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 1 int:100 int: 1 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 1 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 035_while_test2.sy + +int FourWhile() { + int a; + a = 5; + int b; + int c; + b = 6; + c = 7; + int d; + d = 10; + while (a < 20) { + a = a + 3; + while(b < 10){ + b = b + 1; + while(c == 7){ + c = c - 1; + while(d < 20){ + d = d + 3; + } + d = d - 1; + } + c = c + 1; + } + b = b - 2; + } + + return (a + (b + d) + c); +} + +int main() { + return FourWhile(); +} + + +This is test AST: 035_while_test2.sy + +NCompUnit + NFuncDecl int FourWhile + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NAssignStmt b = 6 + NAssignStmt c = 7 + NDeclStmt NVarDecl int d noinit + NAssignStmt d = 10 + NWhileStmt NBinaryExp NIdentifierExp a < 20 + While: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a + 3 + NWhileStmt NBinaryExp NIdentifierExp b < 10 + While: NBlockStmt + NAssignStmt b = NBinaryExp NIdentifierExp b + 1 + NWhileStmt NBinaryExp NIdentifierExp c == 7 + While: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp c - 1 + NWhileStmt NBinaryExp NIdentifierExp d < 20 + While: NBlockStmt + NAssignStmt d = NBinaryExp NIdentifierExp d + 3 + NAssignStmt d = NBinaryExp NIdentifierExp d - 1 + NAssignStmt c = NBinaryExp NIdentifierExp c + 1 + NAssignStmt b = NBinaryExp NIdentifierExp b - 2 + NReturnStmt NBinaryExp NBinaryExp NIdentifierExp a + NBinaryExp NIdentifierExp b + NIdentifierExp d + NIdentifierExp c + NFuncDecl int main + NReturnStmt NCallExp FourWhile + + +This is test IR: 035_while_test2.sy + +Function: FourWhile entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 12 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Store argNum:2 int:6 int: 1 + Store argNum:2 int:7 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:10 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:3 int: 0 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 1 int:1 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 2 int:1 int: 2 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 3 int:3 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 3 int:1 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2 int:1 int: 2 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 1 int:2 int: 1 + BlockType 0 InstructionListLength = 1 + Add argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 3 +Instruction: Load argNum:1 int: 2 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 1 + Call argNum:1 Block or something + + + +This is test: 036_while_test3.sy + +int g; +int h; +int f; +int e; +int EightWhile() { + int a; + a = 5; + int b; + int c; + b = 6; + c = 7; + int d; + d = 10; + while (a < 20) { + a = a + 3; + while(b < 10){ + b = b + 1; + while(c == 7){ + c = c - 1; + while(d < 20){ + d = d + 3; + while(e > 1){ + e = e-1; + while(f > 2){ + f = f -2; + while(g < 3){ + g = g +10; + while(h < 10){ + h = h + 8; + } + h = h-1; + } + g = g- 8; + } + f = f + 1; + } + e = e + 1; + } + d = d - 1; + } + c = c + 1; + } + b = b - 2; + } + + return (a + (b + d) + c)-(e + d - g + h); +} + +int main() { + g = 1; + h = 2; + e = 4; + f = 6; + return EightWhile(); +} + + +This is test AST: 036_while_test3.sy + +NCompUnit + NVarDecl int g noinit + NVarDecl int h noinit + NVarDecl int f noinit + NVarDecl int e noinit + NFuncDecl int EightWhile + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NDeclStmt NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NAssignStmt b = 6 + NAssignStmt c = 7 + NDeclStmt NVarDecl int d noinit + NAssignStmt d = 10 + NWhileStmt NBinaryExp NIdentifierExp a < 20 + While: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a + 3 + NWhileStmt NBinaryExp NIdentifierExp b < 10 + While: NBlockStmt + NAssignStmt b = NBinaryExp NIdentifierExp b + 1 + NWhileStmt NBinaryExp NIdentifierExp c == 7 + While: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp c - 1 + NWhileStmt NBinaryExp NIdentifierExp d < 20 + While: NBlockStmt + NAssignStmt d = NBinaryExp NIdentifierExp d + 3 + NWhileStmt NBinaryExp NIdentifierExp e > 1 + While: NBlockStmt + NAssignStmt e = NBinaryExp NIdentifierExp e - 1 + NWhileStmt NBinaryExp NIdentifierExp f > 2 + While: NBlockStmt + NAssignStmt f = NBinaryExp NIdentifierExp f - 2 + NWhileStmt NBinaryExp NIdentifierExp g < 3 + While: NBlockStmt + NAssignStmt g = NBinaryExp NIdentifierExp g + 10 + NWhileStmt NBinaryExp NIdentifierExp h < 10 + While: NBlockStmt + NAssignStmt h = NBinaryExp NIdentifierExp h + 8 + NAssignStmt h = NBinaryExp NIdentifierExp h - 1 + NAssignStmt g = NBinaryExp NIdentifierExp g - 8 + NAssignStmt f = NBinaryExp NIdentifierExp f + 1 + NAssignStmt e = NBinaryExp NIdentifierExp e + 1 + NAssignStmt d = NBinaryExp NIdentifierExp d - 1 + NAssignStmt c = NBinaryExp NIdentifierExp c + 1 + NAssignStmt b = NBinaryExp NIdentifierExp b - 2 + NReturnStmt NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a + NBinaryExp NIdentifierExp b + NIdentifierExp d + NIdentifierExp c - NBinaryExp NBinaryExp NBinaryExp NIdentifierExp e + NIdentifierExp d - NIdentifierExp g + NIdentifierExp h + NFuncDecl int main + NAssignStmt g = 1 + NAssignStmt h = 2 + NAssignStmt e = 4 + NAssignStmt f = 6 + NReturnStmt NCallExp EightWhile + + +This is test IR: 036_while_test3.sy + +e +int: e +f +int: f +g +int: g +h +int: h +Function: EightWhile entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 12 + Alloca argNum:0 + Store argNum:2 int: 0 int: 4 + Store argNum:2 int:5 int: 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 5 + Alloca argNum:0 + Store argNum:2 int: 0 int: 6 + Store argNum:2 int:6 int: 5 + Store argNum:2 int:7 int: 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 7 + Store argNum:2 int:10 int: 7 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 4 int:3 int: 4 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 5 int:1 int: 5 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 6 int:1 int: 6 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 7 int:3 int: 7 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 3 int:1 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 2 int:2 int: 2 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:10 int: 0 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 1 int:8 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 1 int:1 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 0 int:8 int: 0 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2 int:1 int: 2 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 3 int:1 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 7 int:1 int: 7 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 6 int:1 int: 6 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 5 int:2 int: 5 + BlockType 0 InstructionListLength = 1 + Sub argNum:2 +Instruction: Add argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 4 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 5 +Instruction: Load argNum:1 int: 7 +Instruction: Load argNum:1 int: 6 +Instruction: Add argNum:2 +Instruction: Sub argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 3 +Instruction: Load argNum:1 int: 7 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 5 + Store argNum:2 int:1 int: 0 + Store argNum:2 int:2 int: 1 + Store argNum:2 int:4 int: 3 + Store argNum:2 int:6 int: 2 + Call argNum:1 Block or something + + + +This is test: 037_break.sy + +//test break +int main(){ + int i; + i = 0; + int sum; + sum = 0; + while(i < 100){ + if(i == 50){ + break; + } + sum = sum + i; + i = i + 1; + } + return sum; +} + +This is test AST: 037_break.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NDeclStmt NVarDecl int sum noinit + NAssignStmt sum = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 100 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp i == 50 + True: NBlockStmt + NBreakStmt + NAssignStmt sum = NBinaryExp NIdentifierExp sum + NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt NIdentifierExp sum + + +This is test IR: 037_break.sy + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:0 int: 1 + BlockType 0 InstructionListLength = 1 + Jmp argNum:1 Block or something + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 1 + + + +This is test: 039_while_if_test1.sy + +// test while-if +int whileIf() { + int a; + a = 0; + int b; + b = 0; + while (a < 100) { + if (a == 5) { + b = 25; + } + else if (a == 10) { + b = 42; + } + else { + b = a * 2; + } + a = a + 1; + } + return (b); +} + + +int main(){ + return (whileIf()); +} + + +This is test AST: 039_while_if_test1.sy + +NCompUnit + NFuncDecl int whileIf + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 0 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 0 + NWhileStmt NBinaryExp NIdentifierExp a < 100 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NBlockStmt + NAssignStmt b = 25 + False: NIfStmt NBinaryExp NIdentifierExp a == 10 + True: NBlockStmt + NAssignStmt b = 42 + False: NBlockStmt + NAssignStmt b = NBinaryExp NIdentifierExp a * 2 + NAssignStmt a = NBinaryExp NIdentifierExp a + 1 + NReturnStmt NIdentifierExp b + NFuncDecl int main + NReturnStmt NCallExp whileIf + + +This is test IR: 039_while_if_test1.sy + +Segmentation fault + + +This is test: 040_while_if_test2.sy + +int ifWhile() { + int a; + a = 0; + int b; + b = 3; + if (a == 5) { + while(b == 2){ + b = b + 2; + } + b = b + 25; + } + else + while (a < 5) { + b = b * 2; + a = a + 1; + } + return (b); +} + + +int main(){ + return (ifWhile()); +} + + +This is test AST: 040_while_if_test2.sy + +NCompUnit + NFuncDecl int ifWhile + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 0 + NDeclStmt NVarDecl int b noinit + NAssignStmt b = 3 + NIfStmt NBinaryExp NIdentifierExp a == 5 + True: NBlockStmt + NWhileStmt NBinaryExp NIdentifierExp b == 2 + While: NBlockStmt + NAssignStmt b = NBinaryExp NIdentifierExp b + 2 + NAssignStmt b = NBinaryExp NIdentifierExp b + 25 + False: NWhileStmt NBinaryExp NIdentifierExp a < 5 + While: NBlockStmt + NAssignStmt b = NBinaryExp NIdentifierExp b * 2 + NAssignStmt a = NBinaryExp NIdentifierExp a + 1 + NReturnStmt NIdentifierExp b + NFuncDecl int main + NReturnStmt NCallExp ifWhile + + +This is test IR: 040_while_if_test2.sy + +Segmentation fault + + +This is test: 041_while_if_test3.sy + +int deepWhileBr(int a, int b) { + int c; + c = a + b; + while (c < 75) { + int d; + d = 42; + if (c < 100) { + c = c + d; + if (c > 99) { + int e; + e = d * 2; + if (1 == 1) { + c = e * 2; + } + } + } + } + return (c); +} + +int main() { + int p; + p = 2; + return deepWhileBr(p, p); +} + + +This is test AST: 041_while_if_test3.sy + +NCompUnit + NFuncDecl int deepWhileBr + NVarDecl int a noinit + NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NAssignStmt c = NBinaryExp NIdentifierExp a + NIdentifierExp b + NWhileStmt NBinaryExp NIdentifierExp c < 75 + While: NBlockStmt + NDeclStmt NVarDecl int d noinit + NAssignStmt d = 42 + NIfStmt NBinaryExp NIdentifierExp c < 100 + True: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp c + NIdentifierExp d + NIfStmt NBinaryExp NIdentifierExp c > 99 + True: NBlockStmt + NDeclStmt NVarDecl int e noinit + NAssignStmt e = NBinaryExp NIdentifierExp d * 2 + NIfStmt NBinaryExp 1 == 1 + True: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp e * 2 + NReturnStmt NIdentifierExp c + NFuncDecl int main + NDeclStmt NVarDecl int p noinit + NAssignStmt p = 2 + NReturnStmt NCallExp deepWhileBr NIdentifierExp p NIdentifierExp p + + +This is test IR: 041_while_if_test3.sy + +Function: deepWhileBr entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: -1670224336 +Instruction: Load argNum:1 int: -1670224336 int: 0 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:42 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 int: 0 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 1 int:2 int: 2 + Br argNum:2 +Instruction: EQ argNum:2 int:1 int:1 Block or something + Br argNum:2 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 0 int:99 Block or something + Br argNum:2 +Instruction: LT argNum:2 +Instruction: Load argNum:1 int: 0 int:100 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 2 int:2 int: 0 + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:2 int: 3 + Call argNum:3 +Instruction: Load argNum:1 int: 3 +Instruction: Load argNum:1 int: 3 Block or something + + + +This is test: 042_arr_expr_len.sy + +const int N = -1; +int arr[N + 2 * 4 - 99 / 99] = {1, 2, 33, 4, 5, 6}; + +int main() { + int i = 0, sum = 0; + while (i < 6) { + sum = sum + arr[i]; + i = i + 1; + } + return sum; +} + + +This is test AST: 042_arr_expr_len.sy + +NCompUnit + NVarDecl const int N init [NUnaryExp 277 1] + NVarDecl int arr[NBinaryExp NBinaryExp NIdentifierExp N + NBinaryExp 2 * 4 - NBinaryExp 99 / 99] init [1][2][33][4][5][6] + NFuncDecl int main + NDeclStmt NVarDecl int i init [0] NVarDecl int sum init [0] + NWhileStmt NBinaryExp NIdentifierExp i < 6 + While: NBlockStmt + NAssignStmt sum = NBinaryExp NIdentifierExp sum + NIdentifierExp arr NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt NIdentifierExp sum + + +This is test IR: 042_arr_expr_len.sy + +N +int: N-1 +arr +array: arr1 2 33 4 5 6 +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int:0 int: 7 + Alloca argNum:0 + Store argNum:2 int:0 int: 8 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 8 +Instruction: VectorAdd argNum:1 +Instruction: Mul argNum:2 int: 1 +Instruction: Load argNum:1 int: 7 int: 8 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 7 int:1 int: 7 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 8 + + + +This is test: 043_op_priority1.sy + +//test the priority of add and mul +int main(){ + int a, b, c, d; + a = 10; + b = 4; + c = 2; + d = 2; + return c + a * b - d; +} + +This is test AST: 043_op_priority1.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit NVarDecl int c noinit NVarDecl int d noinit + NAssignStmt a = 10 + NAssignStmt b = 4 + NAssignStmt c = 2 + NAssignStmt d = 2 + NReturnStmt NBinaryExp NBinaryExp NIdentifierExp c + NBinaryExp NIdentifierExp a * NIdentifierExp b - NIdentifierExp d + + +This is test IR: 043_op_priority1.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 13 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:10 int: 0 + Store argNum:2 int:4 int: 1 + Store argNum:2 int:2 int: 2 + Store argNum:2 int:2 int: 3 + Sub argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 3 + + + +This is test: 044_op_priority2.sy + +//test the priority of add and mul +int main(){ + int a, b, c, d; + a = 10; + b = 4; + c = 2; + d = 2; + return (c + a) * (b - d); +} + +This is test AST: 044_op_priority2.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit NVarDecl int c noinit NVarDecl int d noinit + NAssignStmt a = 10 + NAssignStmt b = 4 + NAssignStmt c = 2 + NAssignStmt d = 2 + NReturnStmt NBinaryExp NBinaryExp NIdentifierExp c + NIdentifierExp a * NBinaryExp NIdentifierExp b - NIdentifierExp d + + +This is test IR: 044_op_priority2.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 13 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:10 int: 0 + Store argNum:2 int:4 int: 1 + Store argNum:2 int:2 int: 2 + Store argNum:2 int:2 int: 3 + Mul argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2 +Instruction: Load argNum:1 int: 0 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 3 + + + +This is test: 045_op_priority3.sy + +//test the priority of unary operator and binary operator +int main(){ + int a, b; + a = 10; + b = 30; + return a - -5 + b + -5; +} + +This is test AST: 045_op_priority3.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit + NAssignStmt a = 10 + NAssignStmt b = 30 + NReturnStmt NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a - NUnaryExp 277 5 + NIdentifierExp b + NUnaryExp 277 5 + + +This is test IR: 045_op_priority3.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 7 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:10 int: 0 + Store argNum:2 int:30 int: 1 + Add argNum:2 +Instruction: Add argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Sub argNum:1 int:5 +Instruction: Load argNum:1 int: 1 +Instruction: Sub argNum:1 int:5 + + + +This is test: 046_op_priority4.sy + +int a; +int b; +int c; +int d; +int e; +int main() +{ + a=getint(); + b=getint(); + c=getint(); + d=getint(); + e=getint(); + int flag=0; + if(a-b*c!=d-a/c||a*b/c==e+d||a+b+c==d+e) + { + flag=1; + } + return flag; +} + + +This is test AST: 046_op_priority4.sy + +NCompUnit + NVarDecl int a noinit + NVarDecl int b noinit + NVarDecl int c noinit + NVarDecl int d noinit + NVarDecl int e noinit + NFuncDecl int main + NAssignStmt a = NCallExp getint + NAssignStmt b = NCallExp getint + NAssignStmt c = NCallExp getint + NAssignStmt d = NCallExp getint + NAssignStmt e = NCallExp getint + NDeclStmt NVarDecl int flag init [0] + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a - NBinaryExp NIdentifierExp b * NIdentifierExp c != NBinaryExp NIdentifierExp d - NBinaryExp NIdentifierExp a / NIdentifierExp c | NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a * NIdentifierExp b / NIdentifierExp c == NBinaryExp NIdentifierExp e + NIdentifierExp d | NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a + NIdentifierExp b + NIdentifierExp c == NBinaryExp NIdentifierExp d + NIdentifierExp e + True: NBlockStmt + NAssignStmt flag = 1 + NReturnStmt NIdentifierExp flag + + +This is test IR: 046_op_priority4.sy + +a +int: a +b +int: b +c +int: c +d +int: d +e +int: e +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 8 + Store argNum:2 +Segmentation fault + + +This is test: 047_op_priority5.sy + +int a = 1; +int b = 0; +int c = 1; +int d = 2; +int e = 4; +int main() +{ + int flag=0; + if(a * b / c == e + d && a * (a + b) + c <= d + e || a - (b * c) == d - a / c) + { + flag=1; + } + putint(flag); + return flag; +} + +This is test AST: 047_op_priority5.sy + +NCompUnit + NVarDecl int a init [1] + NVarDecl int b init [0] + NVarDecl int c init [1] + NVarDecl int d init [2] + NVarDecl int e init [4] + NFuncDecl int main + NDeclStmt NVarDecl int flag init [0] + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a * NIdentifierExp b / NIdentifierExp c == NBinaryExp NIdentifierExp e + NIdentifierExp d & NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a * NBinaryExp NIdentifierExp a + NIdentifierExp b + NIdentifierExp c <= NBinaryExp NIdentifierExp d + NIdentifierExp e | NBinaryExp NBinaryExp NIdentifierExp a - NBinaryExp NIdentifierExp b * NIdentifierExp c == NBinaryExp NIdentifierExp d - NBinaryExp NIdentifierExp a / NIdentifierExp c + True: NBlockStmt + NAssignStmt flag = 1 + NExpStmt NCallExp putint NIdentifierExp flag + NReturnStmt NIdentifierExp flag + + +This is test IR: 047_op_priority5.sy + +a +int: a1 +b +int: b0 +c +int: c1 +d +int: d2 +e +int: e4 +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int:0 int: 5 + Br argNum:2 +Instruction: Or argNum:2 +Instruction: And argNum:2 +Instruction: EQ argNum:2 +Instruction: Div argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 4 +Instruction: Load argNum:1 int: 3 +Instruction: LE argNum:2 +Instruction: Add argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 3 +Instruction: Load argNum:1 int: 4 +Instruction: EQ argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 3 +Instruction: Div argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 2 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 int:1 int: 5 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 5 + + + +This is test: 048_stmt_expr.sy + +int k; +const int n = 10; +int main () { + int i = 0; + k = 1; + while (i <= n - 1) { + i = i + 1; + k + 1; + k = k + k; + } + putint(k); + return k; +} + + +This is test AST: 048_stmt_expr.sy + +NCompUnit + NVarDecl int k noinit + NVarDecl const int n init [10] + NFuncDecl int main + NDeclStmt NVarDecl int i init [0] + NAssignStmt k = 1 + NWhileStmt NBinaryExp NIdentifierExp i <= NBinaryExp NIdentifierExp n - 1 + While: NBlockStmt + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NExpStmt NBinaryExp NIdentifierExp k + 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + NIdentifierExp k + NExpStmt NCallExp putint NIdentifierExp k + NReturnStmt NIdentifierExp k + + +This is test IR: 048_stmt_expr.sy + +k +int: k +n +int: n10 +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 3 + Alloca argNum:0 + Store argNum:2 int:0 int: 2 + Store argNum:2 int:1 int: 0 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2 int:1 int: 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 0 int: 0 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 0 + + + +This is test: 049_unary_op.sy + +int main() { + int a; + a = 10; + if (+-!!!a) { + a = - - -1; + } + else { + a = 0; + } + return a; +} + +This is test AST: 049_unary_op.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 10 + NIfStmt NUnaryExp 276 NUnaryExp 277 NUnaryExp 273 NUnaryExp 273 NUnaryExp 273 NIdentifierExp a + True: NBlockStmt + NAssignStmt a = NUnaryExp 277 NUnaryExp 277 NUnaryExp 277 1 + False: NBlockStmt + NAssignStmt a = 0 + NReturnStmt NIdentifierExp a + + +This is test IR: 049_unary_op.sy + +Function: main entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:10 int: 0 + Br argNum:3 +Instruction: Add argNum:1 +Instruction: Sub argNum:1 +Instruction: Not argNum:1 +Instruction: Not argNum:1 +Instruction: Not argNum:1 +Instruction: Load argNum:1 int: 0 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 int:0 int: 0 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 0 + + + +This is test: 050_unary_op2.sy + +int main() { + int a, b; + a = 070; + b = 0x4; + a = a - - 4 + + b; + if (+-!!!a) { + a = - - -1; + } + else { + a = 0 + + b; + } + putint(a); + return 0; +} + +This is test AST: 050_unary_op2.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit + NAssignStmt a = 70 + NAssignStmt b = 0 + NAssignStmt a = NBinaryExp NBinaryExp NIdentifierExp a - NUnaryExp 277 4 + NUnaryExp 276 NIdentifierExp b + NIfStmt NUnaryExp 276 NUnaryExp 277 NUnaryExp 273 NUnaryExp 273 NUnaryExp 273 NIdentifierExp a + True: NBlockStmt + NAssignStmt a = NUnaryExp 277 NUnaryExp 277 NUnaryExp 277 1 + False: NBlockStmt + NAssignStmt a = NBinaryExp 0 + NUnaryExp 276 NIdentifierExp b + NExpStmt NCallExp putint NIdentifierExp a + NReturnStmt 0 + + +This is test IR: 050_unary_op2.sy + +Function: main entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 8 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:70 int: 0 + Store argNum:2 int:0 int: 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Sub argNum:1 int:4 +Instruction: Add argNum:1 +Instruction: Load argNum:1 int: 1 int: 0 + Br argNum:3 +Instruction: Add argNum:1 +Instruction: Sub argNum:1 +Instruction: Not argNum:1 +Instruction: Not argNum:1 +Instruction: Not argNum:1 +Instruction: Load argNum:1 int: 0 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 int:0 +Instruction: Add argNum:1 +Instruction: Load argNum:1 int: 1 int: 0 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + + + +This is test: 051_logi_assign.sy + +int a; +int b; +int main() +{ + a=getint(); + b=getint(); + int c; + if (a==b&&a!=3) { + c = 1; + } + else { + c = 0; + } + return c; +} + + +This is test AST: 051_logi_assign.sy + +NCompUnit + NVarDecl int a noinit + NVarDecl int b noinit + NFuncDecl int main + NAssignStmt a = NCallExp getint + NAssignStmt b = NCallExp getint + NDeclStmt NVarDecl int c noinit + NIfStmt NBinaryExp NBinaryExp NIdentifierExp a == NIdentifierExp b & NBinaryExp NIdentifierExp a != 3 + True: NBlockStmt + NAssignStmt c = 1 + False: NBlockStmt + NAssignStmt c = 0 + NReturnStmt NIdentifierExp c + + +This is test IR: 051_logi_assign.sy + +a +int: a +b +int: b +Function: main entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 5 + Store argNum:2 +Segmentation fault + + +This is test: 052_comment1.sy + +//test comment +int main(){ + int a; + a = 5; + //int b = 4; + //a = b + a; + return a; +} + +This is test AST: 052_comment1.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 5 + NReturnStmt NIdentifierExp a + + +This is test IR: 052_comment1.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:5 int: 0 + Load argNum:1 int: 0 + + + +This is test: 053_comment2.sy + +//test comment +int main(){ + int a, b; + a = 10; + b = 2; + /*/* + b = 1; + // b = 2 + */ + return b; +} + +This is test AST: 053_comment2.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit + NAssignStmt a = 10 + NAssignStmt b = 2 + NReturnStmt NIdentifierExp b + + +This is test IR: 053_comment2.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 7 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:10 int: 0 + Store argNum:2 int:2 int: 1 + Load argNum:1 int: 1 + + + +This is test: 054_hex_defn.sy + +// test hexadecimal define +int main(){ + int a; + a = 0xf; + return a; +} + +This is test AST: 054_hex_defn.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 0 + NReturnStmt NIdentifierExp a + + +This is test IR: 054_hex_defn.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:0 int: 0 + Load argNum:1 int: 0 + + + +This is test: 055_hex_oct_add.sy + +//test add of hex and oct +int main(){ + int a, b; + a = 0xf; + b = 0xc; + return a + b + 075; +} + +This is test AST: 055_hex_oct_add.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit + NAssignStmt a = 0 + NAssignStmt b = 0 + NReturnStmt NBinaryExp NBinaryExp NIdentifierExp a + NIdentifierExp b + 75 + + +This is test IR: 055_hex_oct_add.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 7 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:0 int: 0 + Store argNum:2 int:0 int: 1 + Add argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 int:75 + + + +This is test: 056_assign_complex_expr.sy + +// Use complex expression in assign structure +int main () { + int a; + int b; + int c; + int d; + int result; + a = 5; + b = 5; + c = 1; + d = -2; + result = (d * 1 / 2) + (a - b) - -(c + 3) % 2; + putint(result); + result = ((d % 2 + 67) + -(a - b) - -((c + 2) % 2)); + result = result + 3; + putint(result); + return 0; +} + + +This is test AST: 056_assign_complex_expr.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NDeclStmt NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NDeclStmt NVarDecl int d noinit + NDeclStmt NVarDecl int result noinit + NAssignStmt a = 5 + NAssignStmt b = 5 + NAssignStmt c = 1 + NAssignStmt d = NUnaryExp 277 2 + NAssignStmt result = NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp d * 1 / 2 + NBinaryExp NIdentifierExp a - NIdentifierExp b - NBinaryExp NUnaryExp 277 NBinaryExp NIdentifierExp c + 3 % 2 + NExpStmt NCallExp putint NIdentifierExp result + NAssignStmt result = NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp d % 2 + 67 + NUnaryExp 277 NBinaryExp NIdentifierExp a - NIdentifierExp b - NUnaryExp 277 NBinaryExp NBinaryExp NIdentifierExp c + 2 % 2 + NAssignStmt result = NBinaryExp NIdentifierExp result + 3 + NExpStmt NCallExp putint NIdentifierExp result + NReturnStmt 0 + + +This is test IR: 056_assign_complex_expr.sy + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 18 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Alloca argNum:0 + Store argNum:2 int: 0 int: 4 + Store argNum:2 int:5 int: 0 + Store argNum:2 int:5 int: 1 + Store argNum:2 int:1 int: 2 + Store argNum:2 +Instruction: Sub argNum:1 int:2 int: 3 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Add argNum:2 +Instruction: Div argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 3 int:1 int:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 +terminate called after throwing an instance of 'std::out_of_range' + what(): map::at +Aborted + + +This is test: 057_if_complex_expr.sy + +// Use complex expression in if structure +int main () { + int a; + int b; + int c; + int d; + int result; + a = 5; + b = 5; + c = 1; + d = -2; + result = 2; + if ((d * 1 / 2) < 0 || (a - b) != 0 && (c + 3) % 2 != 0) { + putint(result); + } + if ((d % 2 + 67) < 0 || (a - b) != 0 && (c + 2) % 2 != 0) { + result = 4; + putint(result); + } + return 0; +} + + +This is test AST: 057_if_complex_expr.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NDeclStmt NVarDecl int b noinit + NDeclStmt NVarDecl int c noinit + NDeclStmt NVarDecl int d noinit + NDeclStmt NVarDecl int result noinit + NAssignStmt a = 5 + NAssignStmt b = 5 + NAssignStmt c = 1 + NAssignStmt d = NUnaryExp 277 2 + NAssignStmt result = 2 + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp d * 1 / 2 < 0 | NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a - NIdentifierExp b != 0 & NBinaryExp NBinaryExp NBinaryExp NIdentifierExp c + 3 % 2 != 0 + True: NBlockStmt + NExpStmt NCallExp putint NIdentifierExp result + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp d % 2 + 67 < 0 | NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a - NIdentifierExp b != 0 & NBinaryExp NBinaryExp NBinaryExp NIdentifierExp c + 2 % 2 != 0 + True: NBlockStmt + NAssignStmt result = 4 + NExpStmt NCallExp putint NIdentifierExp result + NReturnStmt 0 + + +This is test IR: 057_if_complex_expr.sy + +Segmentation fault + + +This is test: 058_short_circuit.sy + +int g = 0; + +int func(int n) { + g = g + n; + putint(g); + return g; +} + +int main() { + int i; + i = getint(); + if (i > 10 && func(i)) i = 1; else i = 0; + i = getint(); + if (i > 11 && func(i)) i = 1; else i = 0; + i = getint(); + if (i <= 99 || func(i)) i = 1; else i = 0; + i = getint(); + if (i <= 100 || func(i)) i = 1; else i = 0; + if (!func(99) && func(100)) i = 1; else i = 0; + return 0; +} + + +This is test AST: 058_short_circuit.sy + +NCompUnit + NVarDecl int g init [0] + NFuncDecl int func + NVarDecl int n noinit + NAssignStmt g = NBinaryExp NIdentifierExp g + NIdentifierExp n + NExpStmt NCallExp putint NIdentifierExp g + NReturnStmt NIdentifierExp g + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NCallExp getint + NIfStmt NBinaryExp NBinaryExp NIdentifierExp i > 10 & NCallExp func NIdentifierExp i + True: NAssignStmt i = 1 + False: NAssignStmt i = 0 + NAssignStmt i = NCallExp getint + NIfStmt NBinaryExp NBinaryExp NIdentifierExp i > 11 & NCallExp func NIdentifierExp i + True: NAssignStmt i = 1 + False: NAssignStmt i = 0 + NAssignStmt i = NCallExp getint + NIfStmt NBinaryExp NBinaryExp NIdentifierExp i <= 99 | NCallExp func NIdentifierExp i + True: NAssignStmt i = 1 + False: NAssignStmt i = 0 + NAssignStmt i = NCallExp getint + NIfStmt NBinaryExp NBinaryExp NIdentifierExp i <= 100 | NCallExp func NIdentifierExp i + True: NAssignStmt i = 1 + False: NAssignStmt i = 0 + NIfStmt NBinaryExp NUnaryExp 273 NCallExp func 99 & NCallExp func 100 + True: NAssignStmt i = 1 + False: NAssignStmt i = 0 + NReturnStmt 0 + + +This is test IR: 058_short_circuit.sy + +g +int: g0 +Function: func entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: -1948228048 int: 0 + Load argNum:1 int: 0 + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 5 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 +Segmentation fault + +This is test: 059_short_circuit2.sy + +int func(int n) { + if (n <= 50) { + putint(n); + return 1; + } + else { + putint(n); + return 0; + } +} + +int main() { + int i; + + if (func(0) == 1 || func(50) == 1 && func(100) == 0) + i = 0; + else + i = 1; + + if (func(50) == 1 && func(40) == 1 || func(1) == 1 ) + i = 0; + else + i = 1; + + return 0; +} + + +This is test AST: 059_short_circuit2.sy + +NCompUnit + NFuncDecl int func + NVarDecl int n noinit + NIfStmt NBinaryExp NIdentifierExp n <= 50 + True: NBlockStmt + NExpStmt NCallExp putint NIdentifierExp n + NReturnStmt 1 + False: NBlockStmt + NExpStmt NCallExp putint NIdentifierExp n + NReturnStmt 0 + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NIfStmt NBinaryExp NBinaryExp NCallExp func 0 == 1 | NBinaryExp NBinaryExp NCallExp func 50 == 1 & NBinaryExp NCallExp func 100 == 0 + True: NAssignStmt i = 0 + False: NAssignStmt i = 1 + NIfStmt NBinaryExp NBinaryExp NBinaryExp NCallExp func 50 == 1 & NBinaryExp NCallExp func 40 == 1 | NBinaryExp NCallExp func 1 == 1 + True: NAssignStmt i = 0 + False: NAssignStmt i = 1 + NReturnStmt 0 + + +This is test IR: 059_short_circuit2.sy + +Function: func entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 2 + constant argNum:1 int: 1 + Br argNum:3 +Instruction: LE argNum:2 +Instruction: Load argNum:1 int: -690227664 int:50 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 4 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:0 int: 0 + Br argNum:2 +Instruction: Or argNum:2 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:0 Block or something int:1 +Instruction: And argNum:2 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:50 Block or something int:1 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:100 Block or something int:0 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 int:1 int: 0 + BlockType 0 InstructionListLength = 2 + Store argNum:2 int:0 int: 0 + Br argNum:2 +Instruction: Or argNum:2 +Instruction: And argNum:2 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:50 Block or something int:1 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:40 Block or something int:1 +Instruction: EQ argNum:2 +Instruction: Call argNum:2 int:1 Block or something int:1 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 int:1 int: 0 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + + + +This is test: 060_scope.sy + +int a = 7; + +int func() { + int b = a; + int a = 1; + if (a == b) { + a = a + 1; + return 1; + } + else + return 0; +} + +int main() { + int result = 0; + int i = 0; + while (i < 100) { + if (func() == 1) + result = result + 1; + i = i + 1; + } + if (result < 100) + putint(1); + else + putint(0); + return 0; +} + + +This is test AST: 060_scope.sy + +NCompUnit + NVarDecl int a init [7] + NFuncDecl int func + NDeclStmt NVarDecl int b init [NIdentifierExp a] + NDeclStmt NVarDecl int a init [1] + NIfStmt NBinaryExp NIdentifierExp a == NIdentifierExp b + True: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a + 1 + NReturnStmt 1 + False: NReturnStmt 0 + NFuncDecl int main + NDeclStmt NVarDecl int result init [0] + NDeclStmt NVarDecl int i init [0] + NWhileStmt NBinaryExp NIdentifierExp i < 100 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp func == 1 + True: NAssignStmt result = NBinaryExp NIdentifierExp result + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NIfStmt NBinaryExp NIdentifierExp result < 100 + True: NExpStmt NCallExp putint 1 + False: NExpStmt NCallExp putint 0 + NReturnStmt 0 + + +This is test IR: 060_scope.sy + +a +int: a7 +Function: func entry = 0 succ_bbs_= 2 + BlockType 0 InstructionListLength = 5 + Alloca argNum:0 + Store argNum:2 +Instruction: Load argNum:1 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int:1 int: 2 + Br argNum:3 +Instruction: EQ argNum:2 +Instruction: Load argNum:1 int: 2 +Instruction: Load argNum:1 int: 1 Block or somethingBlock or something + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + BlockType 0 InstructionListLength = 0 + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 5 + Alloca argNum:0 + Store argNum:2 int:0 int: 3 + Alloca argNum:0 + Store argNum:2 int:0 int: 4 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Call argNum:1 Block or something int:1 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 3 int:1 int: 3 + + + +This is test: 061_sort_test1.sy + +int n; +int bubblesort(int arr[]) +{ + int i; + int j; + i =0; + while(i < n-1){ + // Last i elements are already in place + j = 0; + while(j < n-i-1){ + if (arr[j] > arr[j+1]) { + // swap(&arr[j], &arr[j+1]); + int tmp; + tmp = arr[j+1]; + arr[j+1] = arr[j]; + arr[j] = tmp; + } + j = j + 1; + } + i = i + 1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = bubblesort(a); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} + + +This is test AST: 061_sort_test1.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int bubblesort + NVarDecl int arr noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NBinaryExp NIdentifierExp n - 1 + While: NBlockStmt + NAssignStmt j = 0 + NWhileStmt NBinaryExp NIdentifierExp j < NBinaryExp NBinaryExp NIdentifierExp n - NIdentifierExp i - 1 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp arr NIdentifierExp j > NIdentifierExp arr NBinaryExp NIdentifierExp j + 1 + True: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp arr NBinaryExp NIdentifierExp j + 1 + NAssignStmt arr[NBinaryExp NIdentifierExp j + 1] = NIdentifierExp arr NIdentifierExp j + NAssignStmt arr[NIdentifierExp j] = NIdentifierExp tmp + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NCallExp bubblesort NIdentifierExp a + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 061_sort_test1.sy + + +undefind global identifier + + +This is test: 062_sort_test2.sy + +int n; +int insertsort(int a[]) +{ + int i; + i = 1; + while(i-1&&temp NUnaryExp 277 1 & NBinaryExp NIdentifierExp temp < NIdentifierExp a NIdentifierExp j + While: NBlockStmt + NAssignStmt a[NBinaryExp NIdentifierExp j + 1] = NIdentifierExp a NIdentifierExp j + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NAssignStmt a[NBinaryExp NIdentifierExp j + 1] = NIdentifierExp temp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NCallExp insertsort NIdentifierExp a + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 062_sort_test2.sy + + +undefind global identifier + + +This is test: 063_sort_test3.sy + +int n; +int QuickSort(int arr[], int low, int high) +{ + if (low < high) + { + int i; + i = low; + int j; + j = high; + int k; + k = arr[low]; + while (i < j) + { + while(i < j && arr[j] > k - 1) + { + j = j - 1; + } + + if(i < j) + { + arr[i] = arr[j]; + i = i + 1; + } + + while(i < j && arr[i] < k) + { + i = i + 1; + } + + if(i < j) + { + arr[j] = arr[i]; + j = j - 1; + } + } + + arr[i] = k; + int tmp; + tmp = i - 1; + tmp = QuickSort(arr, low, tmp); + tmp = i + 1; + tmp = QuickSort(arr, tmp, high); + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + int tmp; + tmp = 9; + i = QuickSort(a, i, tmp); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} + + +This is test AST: 063_sort_test3.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int QuickSort + NVarDecl int arr noinit + NVarDecl int low noinit + NVarDecl int high noinit + NIfStmt NBinaryExp NIdentifierExp low < NIdentifierExp high + True: NBlockStmt + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NIdentifierExp low + NDeclStmt NVarDecl int j noinit + NAssignStmt j = NIdentifierExp high + NDeclStmt NVarDecl int k noinit + NAssignStmt k = NIdentifierExp arr NIdentifierExp low + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp j + While: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp i < NIdentifierExp j & NBinaryExp NIdentifierExp arr NIdentifierExp j > NBinaryExp NIdentifierExp k - 1 + While: NBlockStmt + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NIfStmt NBinaryExp NIdentifierExp i < NIdentifierExp j + True: NBlockStmt + NAssignStmt arr[NIdentifierExp i] = NIdentifierExp arr NIdentifierExp j + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp i < NIdentifierExp j & NBinaryExp NIdentifierExp arr NIdentifierExp i < NIdentifierExp k + While: NBlockStmt + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NIfStmt NBinaryExp NIdentifierExp i < NIdentifierExp j + True: NBlockStmt + NAssignStmt arr[NIdentifierExp j] = NIdentifierExp arr NIdentifierExp i + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NAssignStmt arr[NIdentifierExp i] = NIdentifierExp k + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NBinaryExp NIdentifierExp i - 1 + NAssignStmt tmp = NCallExp QuickSort NIdentifierExp arr NIdentifierExp low NIdentifierExp tmp + NAssignStmt tmp = NBinaryExp NIdentifierExp i + 1 + NAssignStmt tmp = NCallExp QuickSort NIdentifierExp arr NIdentifierExp tmp NIdentifierExp high + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = 9 + NAssignStmt i = NCallExp QuickSort NIdentifierExp a NIdentifierExp i NIdentifierExp tmp + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 063_sort_test3.sy + + +undefind global identifier + + +This is test: 064_sort_test4.sy + +int n; +int select_sort(int A[],int n) +{ + int i; + int j; + int min; + i =0; + while(i < n-1) + { + min=i;// + j = i + 1; + while(j < n) + { + if(A[min]>A[j]) + { + min=j; + } + j=j+1; + } + if(min!=i) + { + int tmp; + tmp = A[min]; + A[min] = A[i]; + A[i] = tmp; + } + i = i + 1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + i = select_sort(a, n); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} + + +This is test AST: 064_sort_test4.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int select_sort + NVarDecl int A noinit + NVarDecl int n noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NDeclStmt NVarDecl int min noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NBinaryExp NIdentifierExp n - 1 + While: NBlockStmt + NAssignStmt min = NIdentifierExp i + NAssignStmt j = NBinaryExp NIdentifierExp i + 1 + NWhileStmt NBinaryExp NIdentifierExp j < NIdentifierExp n + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp A NIdentifierExp min > NIdentifierExp A NIdentifierExp j + True: NBlockStmt + NAssignStmt min = NIdentifierExp j + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NIfStmt NBinaryExp NIdentifierExp min != NIdentifierExp i + True: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp A NIdentifierExp min + NAssignStmt A[NIdentifierExp min] = NIdentifierExp A NIdentifierExp i + NAssignStmt A[NIdentifierExp i] = NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NAssignStmt i = NCallExp select_sort NIdentifierExp a NIdentifierExp n + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 064_sort_test4.sy + + +undefind global identifier + + +This is test: 065_sort_test5.sy + +int n; +int swap (int array[], int i, int j){ + int temp; + temp = array[i]; + array[i] = array[j]; + array[j] = temp; + return 0; +} +int heap_ajust(int arr[], int start, int end) { + int dad; + dad = start; + int son; + son = dad * 2 + 1; + while (son < end + 1) { // + if (son < end && arr[son] < arr[son + 1]) + son = son + 1; + if (arr[dad] > arr[son]) + return 0; + else { + dad = swap(arr,dad,son); + dad = son; + son = dad * 2 + 1; + } + } + return 0; +} +int heap_sort(int arr[], int len) { + int i; + int tmp; + i = len / 2 - 1; + while ( i > -1) { + tmp = len - 1; + tmp = heap_ajust(arr, i, tmp); + i = i - 1; + } + i = len - 1; + while ( i > 0) { + int tmp0; + tmp0 = 0; + tmp = swap(arr,tmp0,i); + tmp = i - 1; + tmp = heap_ajust(arr, tmp0, tmp); + i = i-1; + } + return 0; +} + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + i = heap_sort(a, n); + while (i < n) { + int tmp; + tmp = a[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} + + +This is test AST: 065_sort_test5.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int swap + NVarDecl int array noinit + NVarDecl int i noinit + NVarDecl int j noinit + NDeclStmt NVarDecl int temp noinit + NAssignStmt temp = NIdentifierExp array NIdentifierExp i + NAssignStmt array[NIdentifierExp i] = NIdentifierExp array NIdentifierExp j + NAssignStmt array[NIdentifierExp j] = NIdentifierExp temp + NReturnStmt 0 + NFuncDecl int heap_ajust + NVarDecl int arr noinit + NVarDecl int start noinit + NVarDecl int end noinit + NDeclStmt NVarDecl int dad noinit + NAssignStmt dad = NIdentifierExp start + NDeclStmt NVarDecl int son noinit + NAssignStmt son = NBinaryExp NBinaryExp NIdentifierExp dad * 2 + 1 + NWhileStmt NBinaryExp NIdentifierExp son < NBinaryExp NIdentifierExp end + 1 + While: NBlockStmt + NIfStmt NBinaryExp NBinaryExp NIdentifierExp son < NIdentifierExp end & NBinaryExp NIdentifierExp arr NIdentifierExp son < NIdentifierExp arr NBinaryExp NIdentifierExp son + 1 + True: NAssignStmt son = NBinaryExp NIdentifierExp son + 1 + NIfStmt NBinaryExp NIdentifierExp arr NIdentifierExp dad > NIdentifierExp arr NIdentifierExp son + True: NReturnStmt 0 + False: NBlockStmt + NAssignStmt dad = NCallExp swap NIdentifierExp arr NIdentifierExp dad NIdentifierExp son + NAssignStmt dad = NIdentifierExp son + NAssignStmt son = NBinaryExp NBinaryExp NIdentifierExp dad * 2 + 1 + NReturnStmt 0 + NFuncDecl int heap_sort + NVarDecl int arr noinit + NVarDecl int len noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int tmp noinit + NAssignStmt i = NBinaryExp NBinaryExp NIdentifierExp len / 2 - 1 + NWhileStmt NBinaryExp NIdentifierExp i > NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt tmp = NBinaryExp NIdentifierExp len - 1 + NAssignStmt tmp = NCallExp heap_ajust NIdentifierExp arr NIdentifierExp i NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NAssignStmt i = NBinaryExp NIdentifierExp len - 1 + NWhileStmt NBinaryExp NIdentifierExp i > 0 + While: NBlockStmt + NDeclStmt NVarDecl int tmp0 noinit + NAssignStmt tmp0 = 0 + NAssignStmt tmp = NCallExp swap NIdentifierExp arr NIdentifierExp tmp0 NIdentifierExp i + NAssignStmt tmp = NBinaryExp NIdentifierExp i - 1 + NAssignStmt tmp = NCallExp heap_ajust NIdentifierExp arr NIdentifierExp tmp0 NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NAssignStmt i = NCallExp heap_sort NIdentifierExp a NIdentifierExp n + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 065_sort_test5.sy + +Segmentation fault + + +This is test: 066_sort_test6.sy + +int n; + +int counting_sort(int ini_arr[], int sorted_arr[], int n) { + int count_arr[10]; + int i; + int j; + int k; + k = 0; + i = 0; + j = 0; + while(k < 10){ + count_arr[k] = 0; + k = k + 1; + } + while(i < n) + { + count_arr[ini_arr[i]] = count_arr[ini_arr[i]] + 1; + i = i + 1; + } + k = 1; + while(k < 10){ + count_arr[k] = count_arr[k] + count_arr[k - 1]; + k = k + 1; + } + j = n; + while( j > 0){ + count_arr[ini_arr[j - 1]] = count_arr[ini_arr[j - 1]] - 1; + sorted_arr[count_arr[ini_arr[j - 1]]] = ini_arr[j - 1]; + j = j - 1; + } + return 0; +} + + +int main(){ + n = 10; + int a[10]; + a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; + a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; + int i; + i = 0; + int b[10]; + i = counting_sort(a, b, n); + while (i < n) { + int tmp; + tmp = b[i]; + putint(tmp); + tmp = 10; + putch(tmp); + i = i + 1; + } + return 0; +} + + +This is test AST: 066_sort_test6.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int counting_sort + NVarDecl int ini_arr noinit + NVarDecl int sorted_arr noinit + NVarDecl int n noinit + NDeclStmt NVarDecl int count_arr[10] noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NDeclStmt NVarDecl int k noinit + NAssignStmt k = 0 + NAssignStmt i = 0 + NAssignStmt j = 0 + NWhileStmt NBinaryExp NIdentifierExp k < 10 + While: NBlockStmt + NAssignStmt count_arr[NIdentifierExp k] = 0 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NAssignStmt count_arr[NIdentifierExp ini_arr NIdentifierExp i] = NBinaryExp NIdentifierExp count_arr NIdentifierExp ini_arr NIdentifierExp i + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt k = 1 + NWhileStmt NBinaryExp NIdentifierExp k < 10 + While: NBlockStmt + NAssignStmt count_arr[NIdentifierExp k] = NBinaryExp NIdentifierExp count_arr NIdentifierExp k + NIdentifierExp count_arr NBinaryExp NIdentifierExp k - 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NAssignStmt j = NIdentifierExp n + NWhileStmt NBinaryExp NIdentifierExp j > 0 + While: NBlockStmt + NAssignStmt count_arr[NIdentifierExp ini_arr NBinaryExp NIdentifierExp j - 1] = NBinaryExp NIdentifierExp count_arr NIdentifierExp ini_arr NBinaryExp NIdentifierExp j - 1 - 1 + NAssignStmt sorted_arr[NIdentifierExp count_arr NIdentifierExp ini_arr NBinaryExp NIdentifierExp j - 1] = NIdentifierExp ini_arr NBinaryExp NIdentifierExp j - 1 + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt n = 10 + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NDeclStmt NVarDecl int b[10] noinit + NAssignStmt i = NCallExp counting_sort NIdentifierExp a NIdentifierExp b NIdentifierExp n + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NDeclStmt NVarDecl int tmp noinit + NAssignStmt tmp = NIdentifierExp b NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp tmp + NAssignStmt tmp = 10 + NExpStmt NCallExp putch NIdentifierExp tmp + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 066_sort_test6.sy + + +undefind global identifier + + +This is test: 067_sort_test7.sy + +int buf[2][100]; + +// sort [l, r) +void merge_sort(int l, int r) +{ + if (l + 1 >= r) + return; + + int mid = (l + r) / 2; + merge_sort(l, mid); + merge_sort(mid, r); + + int i = l, j = mid, k = l; + while (i < mid && j < r) { + if (buf[0][i] < buf[0][j]) { + buf[1][k] = buf[0][i]; + i = i + 1; + } else { + buf[1][k] = buf[0][j]; + j = j + 1; + } + k = k + 1; + } + while (i < mid) { + buf[1][k] = buf[0][i]; + i = i + 1; + k = k + 1; + } + while (j < r) { + buf[1][k] = buf[0][j]; + j = j + 1; + k = k + 1; + } + + while (l < r) { + buf[0][l] = buf[1][l]; + l = l + 1; + } +} + +int main() +{ + int n = getarray(buf[0]); + merge_sort(0, n); + putarray(n, buf[0]); + return 0; +} + + +This is test AST: 067_sort_test7.sy + +NCompUnit + NVarDecl int buf[2][100] noinit + NFuncDecl void merge_sort + NVarDecl int l noinit + NVarDecl int r noinit + NIfStmt NBinaryExp NBinaryExp NIdentifierExp l + 1 >= NIdentifierExp r + True: NReturnStmt + NDeclStmt NVarDecl int mid init [NBinaryExp NBinaryExp NIdentifierExp l + NIdentifierExp r / 2] + NExpStmt NCallExp merge_sort NIdentifierExp l NIdentifierExp mid + NExpStmt NCallExp merge_sort NIdentifierExp mid NIdentifierExp r + NDeclStmt NVarDecl int i init [NIdentifierExp l] NVarDecl int j init [NIdentifierExp mid] NVarDecl int k init [NIdentifierExp l] + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp i < NIdentifierExp mid & NBinaryExp NIdentifierExp j < NIdentifierExp r + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp buf 0 NIdentifierExp i < NIdentifierExp buf 0 NIdentifierExp j + True: NBlockStmt + NAssignStmt buf[1][NIdentifierExp k] = NIdentifierExp buf 0 NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + False: NBlockStmt + NAssignStmt buf[1][NIdentifierExp k] = NIdentifierExp buf 0 NIdentifierExp j + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp mid + While: NBlockStmt + NAssignStmt buf[1][NIdentifierExp k] = NIdentifierExp buf 0 NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NWhileStmt NBinaryExp NIdentifierExp j < NIdentifierExp r + While: NBlockStmt + NAssignStmt buf[1][NIdentifierExp k] = NIdentifierExp buf 0 NIdentifierExp j + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NWhileStmt NBinaryExp NIdentifierExp l < NIdentifierExp r + While: NBlockStmt + NAssignStmt buf[0][NIdentifierExp l] = NIdentifierExp buf 1 NIdentifierExp l + NAssignStmt l = NBinaryExp NIdentifierExp l + 1 + NFuncDecl int main + NDeclStmt NVarDecl int n init [NCallExp getarray NIdentifierExp buf 0] + NExpStmt NCallExp merge_sort 0 NIdentifierExp n + NExpStmt NCallExp putarray NIdentifierExp n NIdentifierExp buf 0 + NReturnStmt 0 + + +This is test IR: 067_sort_test7.sy + +Segmentation fault + + +This is test: 068_genealogical_tree.sy + +int map[10][10]; +int indegree[10]; +int queue[10]; +void topo(int n) +{ + int m=0; + int t=0; + int i,j; + i=1; + j=1; + while(i<=n) + { + j=1; + while(j<=n) + { + if(indegree[j]==0) + { + + m=j; + break; + } + j=j+1; + } + queue[t]=m; + t=t+1; + indegree[m]=-1; + j=1; + while(j<=n) + + { + if(map[m][j]) + { + indegree[j]=indegree[j]-1; + } + j=j+1; + } + i=i+1; + } + i=0; + while(i 0){ + rem = m % n; + m = n; + n = rem; + } + return m; +} +int main(){ + int n,m; + int num; + m=getint(); + n=getint(); + num=fun(m,n); + putint(num); + + return 0; +} + + +This is test AST: 069_greatest_common_divisor.sy + +NCompUnit + NFuncDecl int fun + NVarDecl int m noinit + NVarDecl int n noinit + NDeclStmt NVarDecl int rem noinit + NWhileStmt NBinaryExp NIdentifierExp n > 0 + While: NBlockStmt + NAssignStmt rem = NBinaryExp NIdentifierExp m % NIdentifierExp n + NAssignStmt m = NIdentifierExp n + NAssignStmt n = NIdentifierExp rem + NReturnStmt NIdentifierExp m + NFuncDecl int main + NDeclStmt NVarDecl int n noinit NVarDecl int m noinit + NDeclStmt NVarDecl int num noinit + NAssignStmt m = NCallExp getint + NAssignStmt n = NCallExp getint + NAssignStmt num = NCallExp fun NIdentifierExp m NIdentifierExp n + NExpStmt NCallExp putint NIdentifierExp num + NReturnStmt 0 + + +This is test IR: 069_greatest_common_divisor.sy + +Function: fun entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + BlockType 0 InstructionListLength = 3 + Store argNum:2 +terminate called after throwing an instance of 'std::out_of_range' + what(): map::at +Aborted + + +This is test: 070_multiplication_puzzle.sy + +int a[6]={10,1,50,50,20,5}; +int dp[10][10]; +int main() +{ + int n; + n=6; + + int k,i,t,j,aa; + k=3; + while(k<=n) + { + i=0; + while(i 1 && array[loc - 1] != -1) { + mmerge(loc, loc - 1); + } + if (a < n && array[loc + n] != -1) { + mmerge(loc, loc + n); + } + if (a > 1 && array[loc - n] != -1) { + mmerge(loc, loc - n); + } + + if (array[0] != -1 && array[k] != -1 && findfa(0) == findfa(k)) { + flag = 1; + int tmp = i + 1; + putint(tmp); + putch(10); + } + } + + i = i + 1; + } + if (!flag) { + putint(-1); + putch(10); + } + } + return 0; +} + + +This is test AST: 072_percolation.sy + +NCompUnit + NVarDecl int array[110] noinit + NVarDecl int n noinit + NFuncDecl void init + NVarDecl int n noinit + NDeclStmt NVarDecl int i init [1] + NWhileStmt NBinaryExp NIdentifierExp i <= NBinaryExp NBinaryExp NIdentifierExp n * NIdentifierExp n + 1 + While: NBlockStmt + NAssignStmt array[NIdentifierExp i] = NUnaryExp 277 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NFuncDecl int findfa + NVarDecl int a noinit + NIfStmt NBinaryExp NIdentifierExp array NIdentifierExp a == NIdentifierExp a + True: NReturnStmt NIdentifierExp a + False: NBlockStmt + NAssignStmt array[NIdentifierExp a] = NCallExp findfa NIdentifierExp array NIdentifierExp a + NReturnStmt NIdentifierExp array NIdentifierExp a + NFuncDecl void mmerge + NVarDecl int a noinit + NVarDecl int b noinit + NDeclStmt NVarDecl int m init [NCallExp findfa NIdentifierExp a] + NDeclStmt NVarDecl int n init [NCallExp findfa NIdentifierExp b] + NIfStmt NBinaryExp NIdentifierExp m != NIdentifierExp n + True: NAssignStmt array[NIdentifierExp m] = NIdentifierExp n + NFuncDecl int main + NDeclStmt NVarDecl int t noinit NVarDecl int m noinit + NDeclStmt NVarDecl int a noinit NVarDecl int b noinit + NAssignStmt t = 1 + NWhileStmt NIdentifierExp t + While: NBlockStmt + NAssignStmt t = NBinaryExp NIdentifierExp t - 1 + NAssignStmt n = 4 + NAssignStmt m = 10 + NDeclStmt NVarDecl int i init [0] + NDeclStmt NVarDecl int flag init [0] + NExpStmt NCallExp init NIdentifierExp n + NDeclStmt NVarDecl int k init [NBinaryExp NBinaryExp NIdentifierExp n * NIdentifierExp n + 1] + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp m + While: NBlockStmt + NAssignStmt a = NCallExp getint + NAssignStmt b = NCallExp getint + NIfStmt NUnaryExp 273 NIdentifierExp flag + True: NBlockStmt + NDeclStmt NVarDecl int loc init [NBinaryExp NBinaryExp NIdentifierExp n * NBinaryExp NIdentifierExp a - 1 + NIdentifierExp b] + NAssignStmt array[NIdentifierExp loc] = NIdentifierExp loc + NIfStmt NBinaryExp NIdentifierExp a == 1 + True: NBlockStmt + NAssignStmt array[0] = 0 + NExpStmt NCallExp mmerge NIdentifierExp loc 0 + NIfStmt NBinaryExp NIdentifierExp a == NIdentifierExp n + True: NBlockStmt + NAssignStmt array[NIdentifierExp k] = NIdentifierExp k + NExpStmt NCallExp mmerge NIdentifierExp loc NIdentifierExp k + NIfStmt NBinaryExp NBinaryExp NIdentifierExp b < NIdentifierExp n & NBinaryExp NIdentifierExp array NBinaryExp NIdentifierExp loc + 1 != NUnaryExp 277 1 + True: NBlockStmt + NExpStmt NCallExp mmerge NIdentifierExp loc NBinaryExp NIdentifierExp loc + 1 + NIfStmt NBinaryExp NBinaryExp NIdentifierExp b > 1 & NBinaryExp NIdentifierExp array NBinaryExp NIdentifierExp loc - 1 != NUnaryExp 277 1 + True: NBlockStmt + NExpStmt NCallExp mmerge NIdentifierExp loc NBinaryExp NIdentifierExp loc - 1 + NIfStmt NBinaryExp NBinaryExp NIdentifierExp a < NIdentifierExp n & NBinaryExp NIdentifierExp array NBinaryExp NIdentifierExp loc + NIdentifierExp n != NUnaryExp 277 1 + True: NBlockStmt + NExpStmt NCallExp mmerge NIdentifierExp loc NBinaryExp NIdentifierExp loc + NIdentifierExp n + NIfStmt NBinaryExp NBinaryExp NIdentifierExp a > 1 & NBinaryExp NIdentifierExp array NBinaryExp NIdentifierExp loc - NIdentifierExp n != NUnaryExp 277 1 + True: NBlockStmt + NExpStmt NCallExp mmerge NIdentifierExp loc NBinaryExp NIdentifierExp loc - NIdentifierExp n + NIfStmt NBinaryExp NBinaryExp NBinaryExp NIdentifierExp array 0 != NUnaryExp 277 1 & NBinaryExp NIdentifierExp array NIdentifierExp k != NUnaryExp 277 1 & NBinaryExp NCallExp findfa 0 == NCallExp findfa NIdentifierExp k + True: NBlockStmt + NAssignStmt flag = 1 + NDeclStmt NVarDecl int tmp init [NBinaryExp NIdentifierExp i + 1] + NExpStmt NCallExp putint NIdentifierExp tmp + NExpStmt NCallExp putch 10 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NIfStmt NUnaryExp 273 NIdentifierExp flag + True: NBlockStmt + NExpStmt NCallExp putint NUnaryExp 277 1 + NExpStmt NCallExp putch 10 + NReturnStmt 0 + + +This is test IR: 072_percolation.sy + +Segmentation fault + + +This is test: 073_backpack.sy + +int V[200][200]={}; +int KnapSack(int n, int w[], int v[], int x[], int C) +{ + int i, j; + i=1; + while(i<=n) + { + j=0; + while(jtmp2) + { + V[i][j] = tmp1; + } + else + { + V[i][j] = tmp2; + } + + } + j=j+1; + } + i=i+1; + } + + j = C; + i=n; + while(i>=1) + { + if (V[i][j]>V[i - 1][j]) + { + x[i] = 1; + j = j - w[i]; + } + else + { + + x[i] = 0; + } + i=i-1; + } + return V[n][C]; +} + +int main() +{ + int s; + int w[6] = {0,2,2,6,5,4}; + int v[6] = {0,6,3,5,4,6}; + int x[6]; + int n = 5; + int C=10; + s = KnapSack(n, w, v, x, C); + putint(s); + return 0; + +} + + +This is test AST: 073_backpack.sy + +NCompUnit + NVarDecl int V[200][200] init + NFuncDecl int KnapSack + NVarDecl int n noinit + NVarDecl int w noinit + NVarDecl int v noinit + NVarDecl int x noinit + NVarDecl int C noinit + NDeclStmt NVarDecl int i noinit NVarDecl int j noinit + NAssignStmt i = 1 + NWhileStmt NBinaryExp NIdentifierExp i <= NIdentifierExp n + While: NBlockStmt + NAssignStmt j = 0 + NWhileStmt NBinaryExp NIdentifierExp j < NBinaryExp NIdentifierExp C + 1 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp j < NIdentifierExp w NIdentifierExp i + True: NAssignStmt V[NIdentifierExp i][NIdentifierExp j] = NIdentifierExp V NBinaryExp NIdentifierExp i - 1 NIdentifierExp j + False: NBlockStmt + NDeclStmt NVarDecl int tmp1 init [NIdentifierExp V NBinaryExp NIdentifierExp i - 1 NIdentifierExp j] + NDeclStmt NVarDecl int tmp2 init [NBinaryExp NIdentifierExp V NBinaryExp NIdentifierExp i - 1 NBinaryExp NIdentifierExp j - NIdentifierExp w NIdentifierExp i + NIdentifierExp v NIdentifierExp i] + NIfStmt NBinaryExp NIdentifierExp tmp1 > NIdentifierExp tmp2 + True: NBlockStmt + NAssignStmt V[NIdentifierExp i][NIdentifierExp j] = NIdentifierExp tmp1 + False: NBlockStmt + NAssignStmt V[NIdentifierExp i][NIdentifierExp j] = NIdentifierExp tmp2 + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt j = NIdentifierExp C + NAssignStmt i = NIdentifierExp n + NWhileStmt NBinaryExp NIdentifierExp i >= 1 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp V NIdentifierExp i NIdentifierExp j > NIdentifierExp V NBinaryExp NIdentifierExp i - 1 NIdentifierExp j + True: NBlockStmt + NAssignStmt x[NIdentifierExp i] = 1 + NAssignStmt j = NBinaryExp NIdentifierExp j - NIdentifierExp w NIdentifierExp i + False: NBlockStmt + NAssignStmt x[NIdentifierExp i] = 0 + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt NIdentifierExp V NIdentifierExp n NIdentifierExp C + NFuncDecl int main + NDeclStmt NVarDecl int s noinit + NDeclStmt NVarDecl int w[6] init [0][2][2][6][5][4] + NDeclStmt NVarDecl int v[6] init [0][6][3][5][4][6] + NDeclStmt NVarDecl int x[6] noinit + NDeclStmt NVarDecl int n init [5] + NDeclStmt NVarDecl int C init [10] + NAssignStmt s = NCallExp KnapSack NIdentifierExp n NIdentifierExp w NIdentifierExp v NIdentifierExp x NIdentifierExp C + NExpStmt NCallExp putint NIdentifierExp s + NReturnStmt 0 + + +This is test IR: 073_backpack.sy + + +undefind global identifier + + +This is test: 074_matrix_add.sy + +int M; +int L; +int N; + + +int add(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[]) +{ + int i; + i=0; + while(i -1) { + t = c2[i]; + j = len1 - 1; + while (j > -1) { + temp = result[n] + t * c1[j]; + if(temp >= 10) { + result[n] = (temp); + result[n-1] = result[n-1] + temp / 10; + } + else + result[n] = temp; + j = j - 1; + n = n - 1; + } + n = n + len1 - 1; + i = i - 1; + } + + if(result[0] != 0) + putint(result[0]); + + i = 1; + while (i <= len1 + len2 - 1) { + putint(result[i]); + i = i + 1; + } + + return 0; +} + +This is test AST: 078_big_int_mul.sy + +NCompUnit + NVarDecl const int len init [20] + NFuncDecl int main + NDeclStmt NVarDecl int i noinit NVarDecl int j noinit NVarDecl int t noinit NVarDecl int n noinit NVarDecl int temp noinit + NDeclStmt NVarDecl int mult1[NIdentifierExp len] init [1][2][3][4][5][6][7][8][9][0][1][2][3][4][5][6][7][8][9][0] + NDeclStmt NVarDecl int mult2[NIdentifierExp len] init [2][3][4][2][5][7][9][9][0][1][9][8][7][6][4][3][2][1][2][2] + NDeclStmt NVarDecl int len1 init [NIdentifierExp len] + NDeclStmt NVarDecl int len2 init [NIdentifierExp len] + NDeclStmt NVarDecl int c1[NBinaryExp NIdentifierExp len + 5] noinit + NDeclStmt NVarDecl int c2[NBinaryExp NIdentifierExp len + 5] noinit + NDeclStmt NVarDecl int result[NBinaryExp NIdentifierExp len * 2] init + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp len1 + While: NBlockStmt + NAssignStmt c1[NIdentifierExp i] = NIdentifierExp mult1 NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp len2 + While: NBlockStmt + NAssignStmt c2[NIdentifierExp i] = NIdentifierExp mult2 NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt n = NBinaryExp NBinaryExp NIdentifierExp len1 + NIdentifierExp len2 - 1 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i <= NIdentifierExp n + While: NBlockStmt + NAssignStmt result[NIdentifierExp i] = 0 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt temp = 0 + NAssignStmt i = NBinaryExp NIdentifierExp len2 - 1 + NWhileStmt NBinaryExp NIdentifierExp i > NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt t = NIdentifierExp c2 NIdentifierExp i + NAssignStmt j = NBinaryExp NIdentifierExp len1 - 1 + NWhileStmt NBinaryExp NIdentifierExp j > NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt temp = NBinaryExp NIdentifierExp result NIdentifierExp n + NBinaryExp NIdentifierExp t * NIdentifierExp c1 NIdentifierExp j + NIfStmt NBinaryExp NIdentifierExp temp >= 10 + True: NBlockStmt + NAssignStmt result[NIdentifierExp n] = NIdentifierExp temp + NAssignStmt result[NBinaryExp NIdentifierExp n - 1] = NBinaryExp NIdentifierExp result NBinaryExp NIdentifierExp n - 1 + NBinaryExp NIdentifierExp temp / 10 + False: NAssignStmt result[NIdentifierExp n] = NIdentifierExp temp + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NAssignStmt n = NBinaryExp NIdentifierExp n - 1 + NAssignStmt n = NBinaryExp NBinaryExp NIdentifierExp n + NIdentifierExp len1 - 1 + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NIfStmt NBinaryExp NIdentifierExp result 0 != 0 + True: NExpStmt NCallExp putint NIdentifierExp result 0 + NAssignStmt i = 1 + NWhileStmt NBinaryExp NIdentifierExp i <= NBinaryExp NBinaryExp NIdentifierExp len1 + NIdentifierExp len2 - 1 + While: NBlockStmt + NExpStmt NCallExp putint NIdentifierExp result NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 078_big_int_mul.sy + + +undefind global identifier + + +This is test: 079_calculator.sy + +int ints[10000]; +int intt; +int chas[10000]; +int chat; +int i=0, ii=1; +int c; +int get[10000]; +int get2[10000]; + +int isdigit(int x) { + if (x >= 48 && x <= 57) + return 1; + return 0; +} + +int power(int b, int a) { + int result = 1; + while (a != 0) { + result = result * b; + a = a - 1; + } + return result; +} + +int getstr(int get[]) { + int x = getch(); + int length = 0; + while (x != 13 && x != 10) { + get[length] = x; + length = length + 1; + x = getch(); + } + return length; +} + +void intpush(int x) +{ + intt = intt + 1; + ints[intt] = x; +} +void chapush(int x) +{ + chat = chat + 1; + chas[chat] = x; +} +int intpop() +{ + intt = intt - 1; + return ints[intt + 1]; +} +int chapop() +{ + chat = chat - 1; + return chas[chat + 1]; +} +void intadd(int x) +{ + ints[intt] = ints[intt] * 10; + ints[intt] = ints[intt] + x; +} + +int find() +{ + c = chapop(); + get2[ii] = 32; + get2[ii + 1] = c; + ii = ii + 2; + if (chat == 0) return 0; + return 1; +} + +int main() +{ + intt=0; + chat=0; + int lengets = getstr(get); + while (i < lengets) + { + if (isdigit(get[i]) == 1) + { + get2[ii] = get[i]; + ii = ii + 1; + } + else + { + if(get[i] == 40) chapush(40); + if(get[i] == 94) chapush(94); + if(get[i] == 41) + { + c = chapop(); + while (c != 40) + { + get2[ii] = 32; + get2[ii + 1]=c; + ii = ii + 2; + c = chapop(); + } + } + if (get[i] == 43) + { + while (chas[chat] == 43 || chas[chat] == 45 || chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(43); + } + if (get[i] == 45) + { + while (chas[chat] == 43 || chas[chat] == 45 ||chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if(find()==0)break; + } + chapush(45); + } + if(get[i] == 42) + { + while (chas[chat] == 42 || chas[chat] == 47 ||chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(42); + } + if (get[i] == 47) + { + while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(47); + } + if (get[i] == 37) + { + while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94) + { + if (find()==0)break; + } + chapush(37); + } + get2[ii] = 32; + ii = ii + 1; + } + i = i + 1; + } + while(chat > 0) + { + int c = chapop(); + get2[ii] = 32; + get2[ii + 1]=c; + ii = ii + 2; + } + get2[ii]= 64; + i = 1; + while (get2[i] != 64) + { + if (get2[i] == 43 || get2[i] == 45 || get2[i] == 42 || get2[i] == 47 || get2[i] == 37 || get2[i] == 94) + { + int a=intpop();int b=intpop();int c; + if (get2[i] == 43) c = a + b; + if (get2[i] == 45) c = b - a; + if (get2[i] == 42) c = a * b; + if (get2[i] == 47) c = b / a; + if (get2[i] == 37) c = b % a; + if (get2[i] == 94) c = power(b,a); + intpush(c); + } + else + { + if(get2[i] != 32) + { + intpush(get2[i] - 48); + ii=1; + while(get2[i+ii] != 32) + { + intadd(get2[i+ii] - 48); + ii = ii + 1; + } + i = i + ii-1; + } + } + i = i + 1; + } + putint(ints[1]); + return 0; +} + + +This is test AST: 079_calculator.sy + +NCompUnit + NVarDecl int ints[10000] noinit + NVarDecl int intt noinit + NVarDecl int chas[10000] noinit + NVarDecl int chat noinit + NVarDecl int i init [0] + NVarDecl int ii init [1] + NVarDecl int c noinit + NVarDecl int get[10000] noinit + NVarDecl int get2[10000] noinit + NFuncDecl int isdigit + NVarDecl int x noinit + NIfStmt NBinaryExp NBinaryExp NIdentifierExp x >= 48 & NBinaryExp NIdentifierExp x <= 57 + True: NReturnStmt 1 + NReturnStmt 0 + NFuncDecl int power + NVarDecl int b noinit + NVarDecl int a noinit + NDeclStmt NVarDecl int result init [1] + NWhileStmt NBinaryExp NIdentifierExp a != 0 + While: NBlockStmt + NAssignStmt result = NBinaryExp NIdentifierExp result * NIdentifierExp b + NAssignStmt a = NBinaryExp NIdentifierExp a - 1 + NReturnStmt NIdentifierExp result + NFuncDecl int getstr + NVarDecl int get noinit + NDeclStmt NVarDecl int x init [NCallExp getch] + NDeclStmt NVarDecl int length init [0] + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp x != 13 & NBinaryExp NIdentifierExp x != 10 + While: NBlockStmt + NAssignStmt get[NIdentifierExp length] = NIdentifierExp x + NAssignStmt length = NBinaryExp NIdentifierExp length + 1 + NAssignStmt x = NCallExp getch + NReturnStmt NIdentifierExp length + NFuncDecl void intpush + NVarDecl int x noinit + NAssignStmt intt = NBinaryExp NIdentifierExp intt + 1 + NAssignStmt ints[NIdentifierExp intt] = NIdentifierExp x + NFuncDecl void chapush + NVarDecl int x noinit + NAssignStmt chat = NBinaryExp NIdentifierExp chat + 1 + NAssignStmt chas[NIdentifierExp chat] = NIdentifierExp x + NFuncDecl int intpop + NAssignStmt intt = NBinaryExp NIdentifierExp intt - 1 + NReturnStmt NIdentifierExp ints NBinaryExp NIdentifierExp intt + 1 + NFuncDecl int chapop + NAssignStmt chat = NBinaryExp NIdentifierExp chat - 1 + NReturnStmt NIdentifierExp chas NBinaryExp NIdentifierExp chat + 1 + NFuncDecl void intadd + NVarDecl int x noinit + NAssignStmt ints[NIdentifierExp intt] = NBinaryExp NIdentifierExp ints NIdentifierExp intt * 10 + NAssignStmt ints[NIdentifierExp intt] = NBinaryExp NIdentifierExp ints NIdentifierExp intt + NIdentifierExp x + NFuncDecl int find + NAssignStmt c = NCallExp chapop + NAssignStmt get2[NIdentifierExp ii] = 32 + NAssignStmt get2[NBinaryExp NIdentifierExp ii + 1] = NIdentifierExp c + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 2 + NIfStmt NBinaryExp NIdentifierExp chat == 0 + True: NReturnStmt 0 + NReturnStmt 1 + NFuncDecl int main + NAssignStmt intt = 0 + NAssignStmt chat = 0 + NDeclStmt NVarDecl int lengets init [NCallExp getstr NIdentifierExp get] + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp lengets + While: NBlockStmt + NIfStmt NBinaryExp NCallExp isdigit NIdentifierExp get NIdentifierExp i == 1 + True: NBlockStmt + NAssignStmt get2[NIdentifierExp ii] = NIdentifierExp get NIdentifierExp i + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 1 + False: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 40 + True: NExpStmt NCallExp chapush 40 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 94 + True: NExpStmt NCallExp chapush 94 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 41 + True: NBlockStmt + NAssignStmt c = NCallExp chapop + NWhileStmt NBinaryExp NIdentifierExp c != 40 + While: NBlockStmt + NAssignStmt get2[NIdentifierExp ii] = 32 + NAssignStmt get2[NBinaryExp NIdentifierExp ii + 1] = NIdentifierExp c + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 2 + NAssignStmt c = NCallExp chapop + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 43 + True: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp chas NIdentifierExp chat == 43 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 45 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 42 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 47 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 37 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 94 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp find == 0 + True: NBreakStmt + NExpStmt NCallExp chapush 43 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 45 + True: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp chas NIdentifierExp chat == 43 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 45 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 42 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 47 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 37 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 94 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp find == 0 + True: NBreakStmt + NExpStmt NCallExp chapush 45 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 42 + True: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp chas NIdentifierExp chat == 42 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 47 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 37 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 94 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp find == 0 + True: NBreakStmt + NExpStmt NCallExp chapush 42 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 47 + True: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp chas NIdentifierExp chat == 42 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 47 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 37 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 94 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp find == 0 + True: NBreakStmt + NExpStmt NCallExp chapush 47 + NIfStmt NBinaryExp NIdentifierExp get NIdentifierExp i == 37 + True: NBlockStmt + NWhileStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp chas NIdentifierExp chat == 42 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 47 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 37 | NBinaryExp NIdentifierExp chas NIdentifierExp chat == 94 + While: NBlockStmt + NIfStmt NBinaryExp NCallExp find == 0 + True: NBreakStmt + NExpStmt NCallExp chapush 37 + NAssignStmt get2[NIdentifierExp ii] = 32 + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NWhileStmt NBinaryExp NIdentifierExp chat > 0 + While: NBlockStmt + NDeclStmt NVarDecl int c init [NCallExp chapop] + NAssignStmt get2[NIdentifierExp ii] = 32 + NAssignStmt get2[NBinaryExp NIdentifierExp ii + 1] = NIdentifierExp c + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 2 + NAssignStmt get2[NIdentifierExp ii] = 64 + NAssignStmt i = 1 + NWhileStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i != 64 + While: NBlockStmt + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp get2 NIdentifierExp i == 43 | NBinaryExp NIdentifierExp get2 NIdentifierExp i == 45 | NBinaryExp NIdentifierExp get2 NIdentifierExp i == 42 | NBinaryExp NIdentifierExp get2 NIdentifierExp i == 47 | NBinaryExp NIdentifierExp get2 NIdentifierExp i == 37 | NBinaryExp NIdentifierExp get2 NIdentifierExp i == 94 + True: NBlockStmt + NDeclStmt NVarDecl int a init [NCallExp intpop] + NDeclStmt NVarDecl int b init [NCallExp intpop] + NDeclStmt NVarDecl int c noinit + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 43 + True: NAssignStmt c = NBinaryExp NIdentifierExp a + NIdentifierExp b + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 45 + True: NAssignStmt c = NBinaryExp NIdentifierExp b - NIdentifierExp a + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 42 + True: NAssignStmt c = NBinaryExp NIdentifierExp a * NIdentifierExp b + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 47 + True: NAssignStmt c = NBinaryExp NIdentifierExp b / NIdentifierExp a + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 37 + True: NAssignStmt c = NBinaryExp NIdentifierExp b % NIdentifierExp a + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i == 94 + True: NAssignStmt c = NCallExp power NIdentifierExp b NIdentifierExp a + NExpStmt NCallExp intpush NIdentifierExp c + False: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp get2 NIdentifierExp i != 32 + True: NBlockStmt + NExpStmt NCallExp intpush NBinaryExp NIdentifierExp get2 NIdentifierExp i - 48 + NAssignStmt ii = 1 + NWhileStmt NBinaryExp NIdentifierExp get2 NBinaryExp NIdentifierExp i + NIdentifierExp ii != 32 + While: NBlockStmt + NExpStmt NCallExp intadd NBinaryExp NIdentifierExp get2 NBinaryExp NIdentifierExp i + NIdentifierExp ii - 48 + NAssignStmt ii = NBinaryExp NIdentifierExp ii + 1 + NAssignStmt i = NBinaryExp NBinaryExp NIdentifierExp i + NIdentifierExp ii - 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NExpStmt NCallExp putint NIdentifierExp ints 1 + NReturnStmt 0 + + +This is test IR: 079_calculator.sy + +Segmentation fault + + +This is test: 080_color.sy + +const int maxn = 18; +const int mod = 1000000007; +int dp[maxn][maxn][maxn][maxn][maxn][7]; +int list[200]; + +int equal(int a, int b) { + if (a == b) + return 1; + return 0; +} + +int dfs(int a, int b, int c, int d, int e, int last){ + if(dp[a][b][c][d][e][last] != -1) + return dp[a][b][c][d][e][last]; + if(a + b + c + d + e == 0) + return 1; + int ans = 0; + if (a) ans = (ans + (a - equal(last, 2)) * dfs(a - 1, b, c, d, e, 1)) % mod; + if (b) ans = (ans + (b - equal(last, 3)) * dfs(a + 1, b - 1, c, d, e, 2)) % mod; + if (c) ans = (ans + (c - equal(last, 4)) * dfs(a, b + 1, c - 1, d, e, 3)) % mod; + if (d) ans = (ans + (d - equal(last, 5)) * dfs(a, b, c + 1, d - 1, e, 4)) % mod; + if (e) ans = (ans + e * dfs(a, b, c, d + 1, e - 1, 5)) % mod; + dp[a][b][c][d][e][last] = ans % mod; + return dp[a][b][c][d][e][last]; +} + +int cns[20]; + +int main(){ + int n = getint(); + int i = 0; + while (i < maxn) { + int j = 0; + while(j < maxn) { + int k = 0; + while(k < maxn) { + int l = 0; + while (l < maxn) { + int m = 0; + while (m < maxn) { + int h = 0; + while (h < 7) { + dp[i][j][k][l][m][h] = -1; + h = h + 1; + } + m = m + 1; + } + l = l + 1; + } + k = k + 1; + } + j = j + 1; + } + i = i + 1; + } + + i = 0; + while (i < n) { + list[i] = getint(); + cns[list[i]] = cns[list[i]] + 1; + i = i + 1; + } + + int ans = dfs(cns[1], cns[2], cns[3], cns[4], cns[5], 0); + + putint(ans); + + return ans; +} + +This is test AST: 080_color.sy + +NCompUnit + NVarDecl const int maxn init [18] + NVarDecl const int mod init [1000000007] + NVarDecl int dp[NIdentifierExp maxn][NIdentifierExp maxn][NIdentifierExp maxn][NIdentifierExp maxn][NIdentifierExp maxn][7] noinit + NVarDecl int list[200] noinit + NFuncDecl int equal + NVarDecl int a noinit + NVarDecl int b noinit + NIfStmt NBinaryExp NIdentifierExp a == NIdentifierExp b + True: NReturnStmt 1 + NReturnStmt 0 + NFuncDecl int dfs + NVarDecl int a noinit + NVarDecl int b noinit + NVarDecl int c noinit + NVarDecl int d noinit + NVarDecl int e noinit + NVarDecl int last noinit + NIfStmt NBinaryExp NIdentifierExp dp NIdentifierExp a NIdentifierExp b NIdentifierExp c NIdentifierExp d NIdentifierExp e NIdentifierExp last != NUnaryExp 277 1 + True: NReturnStmt NIdentifierExp dp NIdentifierExp a NIdentifierExp b NIdentifierExp c NIdentifierExp d NIdentifierExp e NIdentifierExp last + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp a + NIdentifierExp b + NIdentifierExp c + NIdentifierExp d + NIdentifierExp e == 0 + True: NReturnStmt 1 + NDeclStmt NVarDecl int ans init [0] + NIfStmt NIdentifierExp a + True: NAssignStmt ans = NBinaryExp NBinaryExp NIdentifierExp ans + NBinaryExp NBinaryExp NIdentifierExp a - NCallExp equal NIdentifierExp last 2 * NCallExp dfs NBinaryExp NIdentifierExp a - 1 NIdentifierExp b NIdentifierExp c NIdentifierExp d NIdentifierExp e 1 % NIdentifierExp mod + NIfStmt NIdentifierExp b + True: NAssignStmt ans = NBinaryExp NBinaryExp NIdentifierExp ans + NBinaryExp NBinaryExp NIdentifierExp b - NCallExp equal NIdentifierExp last 3 * NCallExp dfs NBinaryExp NIdentifierExp a + 1 NBinaryExp NIdentifierExp b - 1 NIdentifierExp c NIdentifierExp d NIdentifierExp e 2 % NIdentifierExp mod + NIfStmt NIdentifierExp c + True: NAssignStmt ans = NBinaryExp NBinaryExp NIdentifierExp ans + NBinaryExp NBinaryExp NIdentifierExp c - NCallExp equal NIdentifierExp last 4 * NCallExp dfs NIdentifierExp a NBinaryExp NIdentifierExp b + 1 NBinaryExp NIdentifierExp c - 1 NIdentifierExp d NIdentifierExp e 3 % NIdentifierExp mod + NIfStmt NIdentifierExp d + True: NAssignStmt ans = NBinaryExp NBinaryExp NIdentifierExp ans + NBinaryExp NBinaryExp NIdentifierExp d - NCallExp equal NIdentifierExp last 5 * NCallExp dfs NIdentifierExp a NIdentifierExp b NBinaryExp NIdentifierExp c + 1 NBinaryExp NIdentifierExp d - 1 NIdentifierExp e 4 % NIdentifierExp mod + NIfStmt NIdentifierExp e + True: NAssignStmt ans = NBinaryExp NBinaryExp NIdentifierExp ans + NBinaryExp NIdentifierExp e * NCallExp dfs NIdentifierExp a NIdentifierExp b NIdentifierExp c NBinaryExp NIdentifierExp d + 1 NBinaryExp NIdentifierExp e - 1 5 % NIdentifierExp mod + NAssignStmt dp[NIdentifierExp a][NIdentifierExp b][NIdentifierExp c][NIdentifierExp d][NIdentifierExp e][NIdentifierExp last] = NBinaryExp NIdentifierExp ans % NIdentifierExp mod + NReturnStmt NIdentifierExp dp NIdentifierExp a NIdentifierExp b NIdentifierExp c NIdentifierExp d NIdentifierExp e NIdentifierExp last + NVarDecl int cns[20] noinit + NFuncDecl int main + NDeclStmt NVarDecl int n init [NCallExp getint] + NDeclStmt NVarDecl int i init [0] + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp maxn + While: NBlockStmt + NDeclStmt NVarDecl int j init [0] + NWhileStmt NBinaryExp NIdentifierExp j < NIdentifierExp maxn + While: NBlockStmt + NDeclStmt NVarDecl int k init [0] + NWhileStmt NBinaryExp NIdentifierExp k < NIdentifierExp maxn + While: NBlockStmt + NDeclStmt NVarDecl int l init [0] + NWhileStmt NBinaryExp NIdentifierExp l < NIdentifierExp maxn + While: NBlockStmt + NDeclStmt NVarDecl int m init [0] + NWhileStmt NBinaryExp NIdentifierExp m < NIdentifierExp maxn + While: NBlockStmt + NDeclStmt NVarDecl int h init [0] + NWhileStmt NBinaryExp NIdentifierExp h < 7 + While: NBlockStmt + NAssignStmt dp[NIdentifierExp i][NIdentifierExp j][NIdentifierExp k][NIdentifierExp l][NIdentifierExp m][NIdentifierExp h] = NUnaryExp 277 1 + NAssignStmt h = NBinaryExp NIdentifierExp h + 1 + NAssignStmt m = NBinaryExp NIdentifierExp m + 1 + NAssignStmt l = NBinaryExp NIdentifierExp l + 1 + NAssignStmt k = NBinaryExp NIdentifierExp k + 1 + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NAssignStmt list[NIdentifierExp i] = NCallExp getint + NAssignStmt cns[NIdentifierExp list NIdentifierExp i] = NBinaryExp NIdentifierExp cns NIdentifierExp list NIdentifierExp i + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NDeclStmt NVarDecl int ans init [NCallExp dfs NIdentifierExp cns 1 NIdentifierExp cns 2 NIdentifierExp cns 3 NIdentifierExp cns 4 NIdentifierExp cns 5 0] + NExpStmt NCallExp putint NIdentifierExp ans + NReturnStmt NIdentifierExp ans + + +This is test IR: 080_color.sy + +Segmentation fault + + +This is test: 100_array_concat.sy + + +int concat(int a0[],int b0[],int c0[]) +{ + int i; + i=0; + while(i<3) + { + c0[i]=a0[i]; + + i=i+1; + } + int j; + j=0; + while(j<3) + { + c0[i]=b0[j]; + i=i+1; + j=j+1; + } + + return 0; + +} + +int main() +{ + int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3]; + int i; + i=0; + while(i<3) + { + a0[i]=i; + a1[i]=i; + a2[i]=i; + b0[i]=i; + b1[i]=i; + b2[i]=i; + i=i+1; + } + i=concat( a0,b0, c0); + int x; + while(i<6) + { + x = c0[i]; + putint(x); + i=i+1; + } + x = 10; + putch(x); + + return 0; +} + + +This is test AST: 100_array_concat.sy + +NCompUnit + NFuncDecl int concat + NVarDecl int a0 noinit + NVarDecl int b0 noinit + NVarDecl int c0 noinit + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 3 + While: NBlockStmt + NAssignStmt c0[NIdentifierExp i] = NIdentifierExp a0 NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NDeclStmt NVarDecl int j noinit + NAssignStmt j = 0 + NWhileStmt NBinaryExp NIdentifierExp j < 3 + While: NBlockStmt + NAssignStmt c0[NIdentifierExp i] = NIdentifierExp b0 NIdentifierExp j + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NReturnStmt 0 + NFuncDecl int main + NDeclStmt NVarDecl int a0[3] noinit + NDeclStmt NVarDecl int a1[3] noinit + NDeclStmt NVarDecl int a2[3] noinit + NDeclStmt NVarDecl int b0[3] noinit + NDeclStmt NVarDecl int b1[3] noinit + NDeclStmt NVarDecl int b2[3] noinit + NDeclStmt NVarDecl int c0[6] noinit + NDeclStmt NVarDecl int c1[3] noinit + NDeclStmt NVarDecl int c2[3] noinit + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 3 + While: NBlockStmt + NAssignStmt a0[NIdentifierExp i] = NIdentifierExp i + NAssignStmt a1[NIdentifierExp i] = NIdentifierExp i + NAssignStmt a2[NIdentifierExp i] = NIdentifierExp i + NAssignStmt b0[NIdentifierExp i] = NIdentifierExp i + NAssignStmt b1[NIdentifierExp i] = NIdentifierExp i + NAssignStmt b2[NIdentifierExp i] = NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = NCallExp concat NIdentifierExp a0 NIdentifierExp b0 NIdentifierExp c0 + NDeclStmt NVarDecl int x noinit + NWhileStmt NBinaryExp NIdentifierExp i < 6 + While: NBlockStmt + NAssignStmt x = NIdentifierExp c0 NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp x + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt x = 10 + NExpStmt NCallExp putch NIdentifierExp x + NReturnStmt 0 + + +This is test IR: 100_array_concat.sy + + +undefind global identifier + + +This is test: 101_insert_order.sy + +//int n; +int N; +int insert(int a[],int x) +{ + int p; + int i; + p=0; + + while(x>a[p]&&pp) + { + a[i]=a[i-1]; + a[p]=x; + i=i-1; + + } + + return 0; +} + +int main() +{ + N=10; + int a[11]; + //a[0]=1; + a[0]=1; + a[1]=3; + a[2]=4; + a[3]=7; + a[4]=8; + a[5]=11; + a[6]=13; + a[7]=18; + a[8]=56; + a[9]=78; + int x; + int i; + i=0; + x=getint(); + x=insert(a,x); + //while() + while(i NIdentifierExp a NIdentifierExp p & NBinaryExp NIdentifierExp p < NIdentifierExp N + While: NAssignStmt p = NBinaryExp NIdentifierExp p + 1 + NAssignStmt i = NIdentifierExp N + NWhileStmt NBinaryExp NIdentifierExp i > NIdentifierExp p + While: NBlockStmt + NAssignStmt a[NIdentifierExp i] = NIdentifierExp a NBinaryExp NIdentifierExp i - 1 + NAssignStmt a[NIdentifierExp p] = NIdentifierExp x + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt N = 10 + NDeclStmt NVarDecl int a[11] noinit + NAssignStmt a[0] = 1 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 4 + NAssignStmt a[3] = 7 + NAssignStmt a[4] = 8 + NAssignStmt a[5] = 11 + NAssignStmt a[6] = 13 + NAssignStmt a[7] = 18 + NAssignStmt a[8] = 56 + NAssignStmt a[9] = 78 + NDeclStmt NVarDecl int x noinit + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NAssignStmt x = NCallExp getint + NAssignStmt x = NCallExp insert NIdentifierExp a NIdentifierExp x + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp N + While: NBlockStmt + NAssignStmt x = NIdentifierExp a NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp x + NAssignStmt x = 10 + NExpStmt NCallExp putch NIdentifierExp x + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 101_insert_order.sy + + +undefind global identifier + + +This is test: 102_line_search.sy + + +int main() +{ + //newline=10; + int i; + int sum; + int a[10]; + sum=0; + //m = 1478; + //int t; + i=0; + while(i<10) + { + a[i]=i+1; + i=i+1; + } + int x; + int high; + int low; + int mid; + int n; + n=10; + x=getint(); + high=n-1; + low=0; + mid=(high+low)/2; + int flag; + flag=0; + //int i; + i=0; + int j; + j=0; + while(i<10 && flag==0) + { + if(a[i]==x) + { + flag=1; + j=i; + } + + i=i+1; + + } + + if(flag==1) + putint(j); + else + { + x = 0; + putint(x); + } + + + + x= 10; + putch(x); + + return 0; +} + + +This is test AST: 102_line_search.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int sum noinit + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt sum = 0 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 10 + While: NBlockStmt + NAssignStmt a[NIdentifierExp i] = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NDeclStmt NVarDecl int x noinit + NDeclStmt NVarDecl int high noinit + NDeclStmt NVarDecl int low noinit + NDeclStmt NVarDecl int mid noinit + NDeclStmt NVarDecl int n noinit + NAssignStmt n = 10 + NAssignStmt x = NCallExp getint + NAssignStmt high = NBinaryExp NIdentifierExp n - 1 + NAssignStmt low = 0 + NAssignStmt mid = NBinaryExp NBinaryExp NIdentifierExp high + NIdentifierExp low / 2 + NDeclStmt NVarDecl int flag noinit + NAssignStmt flag = 0 + NAssignStmt i = 0 + NDeclStmt NVarDecl int j noinit + NAssignStmt j = 0 + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp i < 10 & NBinaryExp NIdentifierExp flag == 0 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp a NIdentifierExp i == NIdentifierExp x + True: NBlockStmt + NAssignStmt flag = 1 + NAssignStmt j = NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NIfStmt NBinaryExp NIdentifierExp flag == 1 + True: NExpStmt NCallExp putint NIdentifierExp j + False: NBlockStmt + NAssignStmt x = 0 + NExpStmt NCallExp putint NIdentifierExp x + NAssignStmt x = 10 + NExpStmt NCallExp putch NIdentifierExp x + NReturnStmt 0 + + +This is test IR: 102_line_search.sy + + +undefind global identifier + + +This is test: 81_go_upstairs.sy + +int climbStairs(int n) { + if(n < 4) + return n; + int dp[10]; + dp[0] = 0; + dp[1] = 1; + dp[2] = 2; + int i; + i = 3; + while(i -1 && s[c] == 0){ + c = c - 1; + } + if(c == -1) + return 0; + int i; + i = c; + while(i > -1){ + if(s[i] == 0) + return n - i - 1 - (n - 1 - c); + i = i - 1; + } + return c - i; +} +int main(){ + int res; + int a[10]; + a[0]=-4;a[1]=3;a[2]=9;a[3]=-2;a[4]=0; + a[5]=1;a[6]=-6;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = lengthOfLastWord(a, res); + return res; +} + +This is test AST: 84_last_word_length.sy + +NCompUnit + NFuncDecl int lengthOfLastWord + NVarDecl int s noinit + NVarDecl int n noinit + NIfStmt NBinaryExp NIdentifierExp n == 0 + True: NReturnStmt 0 + NDeclStmt NVarDecl int c noinit + NAssignStmt c = NBinaryExp NIdentifierExp n - 1 + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp c > NUnaryExp 277 1 & NBinaryExp NIdentifierExp s NIdentifierExp c == 0 + While: NBlockStmt + NAssignStmt c = NBinaryExp NIdentifierExp c - 1 + NIfStmt NBinaryExp NIdentifierExp c == NUnaryExp 277 1 + True: NReturnStmt 0 + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NIdentifierExp c + NWhileStmt NBinaryExp NIdentifierExp i > NUnaryExp 277 1 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp s NIdentifierExp i == 0 + True: NReturnStmt NBinaryExp NBinaryExp NBinaryExp NIdentifierExp n - NIdentifierExp i - 1 - NBinaryExp NBinaryExp NIdentifierExp n - 1 - NIdentifierExp c + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt NBinaryExp NIdentifierExp c - NIdentifierExp i + NFuncDecl int main + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = NUnaryExp 277 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = NUnaryExp 277 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = NUnaryExp 277 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NAssignStmt res = 10 + NAssignStmt res = NCallExp lengthOfLastWord NIdentifierExp a NIdentifierExp res + NReturnStmt NIdentifierExp res + + +This is test IR: 84_last_word_length.sy + +Segmentation fault + + +This is test: 85_multi.sy + +int main() +{ + //newline=10; + int i; + int sum; + sum=0; + //m = 1478; + //int t; + i=0; + while(i<21) + { + sum=sum*i; + i=i+1; + } + + putint(sum); + + return 0; +} + + +This is test AST: 85_multi.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int sum noinit + NAssignStmt sum = 0 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 21 + While: NBlockStmt + NAssignStmt sum = NBinaryExp NIdentifierExp sum * NIdentifierExp i + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NExpStmt NCallExp putint NIdentifierExp sum + NReturnStmt 0 + + +This is test IR: 85_multi.sy + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 6 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 int:0 int: 1 + Store argNum:2 int:0 int: 0 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Mul argNum:2 +Instruction: Load argNum:1 int: 1 +Instruction: Load argNum:1 int: 0 int: 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:1 int: 0 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + + + +This is test: 86_max_subsequence_sum.sy + +int maxSubArray(int nums[], int n) { + if(n == 0) + return 0; + if(n == 1) + return nums[0]; + int sum; + sum = nums[0]; + int max; + max = sum; + int i; + i = 1; + while(i < n){ + if(sum < 0) + sum = 0; + sum = sum + nums[i]; + if(max < sum) + max = sum; + i = i + 1; + } + return max; +} +int main(){ + int res; + int a[10]; + a[0]=-4;a[1]=3;a[2]=9;a[3]=-2;a[4]=0; + a[5]=1;a[6]=-6;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = maxSubArray(a, res); + return res; +} + +This is test AST: 86_max_subsequence_sum.sy + +NCompUnit + NFuncDecl int maxSubArray + NVarDecl int nums noinit + NVarDecl int n noinit + NIfStmt NBinaryExp NIdentifierExp n == 0 + True: NReturnStmt 0 + NIfStmt NBinaryExp NIdentifierExp n == 1 + True: NReturnStmt NIdentifierExp nums 0 + NDeclStmt NVarDecl int sum noinit + NAssignStmt sum = NIdentifierExp nums 0 + NDeclStmt NVarDecl int max noinit + NAssignStmt max = NIdentifierExp sum + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 1 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp sum < 0 + True: NAssignStmt sum = 0 + NAssignStmt sum = NBinaryExp NIdentifierExp sum + NIdentifierExp nums NIdentifierExp i + NIfStmt NBinaryExp NIdentifierExp max < NIdentifierExp sum + True: NAssignStmt max = NIdentifierExp sum + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt NIdentifierExp max + NFuncDecl int main + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = NUnaryExp 277 4 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = NUnaryExp 277 2 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = NUnaryExp 277 6 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NAssignStmt res = 10 + NAssignStmt res = NCallExp maxSubArray NIdentifierExp a NIdentifierExp res + NReturnStmt NIdentifierExp res + + +This is test IR: 86_max_subsequence_sum.sy + +Segmentation fault + + +This is test: 87_enum.sy + +int main() +{ + int i; + int j; + int k; + int t; + i=0;j=0;k=0; + while(i<21) + { + while(j<101-i) + { + k=100-i-j; + if(5*i+1*j+k/2==100) + { + putint(i); + putint(j); + putint(k); + t=10; + putch(t); + } + j=j+1; + } + i=i+1; + } + + return 0; +} + + +This is test AST: 87_enum.sy + +NCompUnit + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NDeclStmt NVarDecl int k noinit + NDeclStmt NVarDecl int t noinit + NAssignStmt i = 0 + NAssignStmt j = 0 + NAssignStmt k = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 21 + While: NBlockStmt + NWhileStmt NBinaryExp NIdentifierExp j < NBinaryExp 101 - NIdentifierExp i + While: NBlockStmt + NAssignStmt k = NBinaryExp NBinaryExp 100 - NIdentifierExp i - NIdentifierExp j + NIfStmt NBinaryExp NBinaryExp NBinaryExp NBinaryExp 5 * NIdentifierExp i + NBinaryExp 1 * NIdentifierExp j + NBinaryExp NIdentifierExp k / 2 == 100 + True: NBlockStmt + NExpStmt NCallExp putint NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp j + NExpStmt NCallExp putint NIdentifierExp k + NAssignStmt t = 10 + NExpStmt NCallExp putch NIdentifierExp t + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 87_enum.sy + +Function: main entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 11 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:0 int: 0 + Store argNum:2 int:0 int: 1 + Store argNum:2 int:0 int: 2 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Sub argNum:2 int:100 +Instruction: Load argNum:1 int: 0 +Instruction: Load argNum:1 int: 1 int: 2 + Br argNum:2 +Instruction: EQ argNum:2 +Instruction: Add argNum:2 +Instruction: Add argNum:2 +Instruction: Mul argNum:2 int:5 +Instruction: Load argNum:1 int: 0 +Instruction: Mul argNum:2 int:1 +Instruction: Load argNum:1 int: 1 +Instruction: Div argNum:2 +Instruction: Load argNum:1 int: 2 int:2 int:100 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 int:10 int: 3 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 1 int:1 int: 1 + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 int:1 int: 0 + BlockType 0 InstructionListLength = 1 + constant argNum:1 int: 0 + + + +This is test: 88_exchange_value.sy + +int n; + +int main() +{ + //newline=10; + int i; + int j; + //m = 1478; + //int t; + i=getint(); + j=getint(); + int temp; + temp=i; + i=j; + j=temp; + + putint(i); + temp = 10; + putch(temp); + putint(j); + temp = 10; + putch(temp); + + return 0; +} + + +This is test AST: 88_exchange_value.sy + +NCompUnit + NVarDecl int n noinit + NFuncDecl int main + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NAssignStmt i = NCallExp getint + NAssignStmt j = NCallExp getint + NDeclStmt NVarDecl int temp noinit + NAssignStmt temp = NIdentifierExp i + NAssignStmt i = NIdentifierExp j + NAssignStmt j = NIdentifierExp temp + NExpStmt NCallExp putint NIdentifierExp i + NAssignStmt temp = 10 + NExpStmt NCallExp putch NIdentifierExp temp + NExpStmt NCallExp putint NIdentifierExp j + NAssignStmt temp = 10 + NExpStmt NCallExp putch NIdentifierExp temp + NReturnStmt 0 + + +This is test IR: 88_exchange_value.sy + +n +int: n +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 14 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Store argNum:2 +Segmentation fault + + +This is test: 89_itera_sqrt.sy + +int fsqrt(int a) +{ + int x0=0; + int x1; + x1=a/2; + while(x0-x1!=0) + { + x0=x1; + x1=(x0+a/x0); + x1=x1/2; + } + + return x1; + +} + +int main() +{ + int a; + a=400; + int res; + res=fsqrt(a); + putint(res); + res = 10; + putch(res); + return 0; +} + + +This is test AST: 89_itera_sqrt.sy + +NCompUnit + NFuncDecl int fsqrt + NVarDecl int a noinit + NDeclStmt NVarDecl int x0 init [0] + NDeclStmt NVarDecl int x1 noinit + NAssignStmt x1 = NBinaryExp NIdentifierExp a / 2 + NWhileStmt NBinaryExp NBinaryExp NIdentifierExp x0 - NIdentifierExp x1 != 0 + While: NBlockStmt + NAssignStmt x0 = NIdentifierExp x1 + NAssignStmt x1 = NBinaryExp NIdentifierExp x0 + NBinaryExp NIdentifierExp a / NIdentifierExp x0 + NAssignStmt x1 = NBinaryExp NIdentifierExp x1 / 2 + NReturnStmt NIdentifierExp x1 + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 400 + NDeclStmt NVarDecl int res noinit + NAssignStmt res = NCallExp fsqrt NIdentifierExp a + NExpStmt NCallExp putint NIdentifierExp res + NAssignStmt res = 10 + NExpStmt NCallExp putch NIdentifierExp res + NReturnStmt 0 + + +This is test IR: 89_itera_sqrt.sy + +Function: fsqrt entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 5 + Alloca argNum:0 + Store argNum:2 int:0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 +Instruction: Div argNum:2 +Instruction: Load argNum:1 int: -1621514704 int:2 int: 1 + BlockType 0 InstructionListLength = 3 + Store argNum:2 +Instruction: Load argNum:1 int: 1 int: 0 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 0 +Instruction: Div argNum:2 +Instruction: Load argNum:1 int: -1621514704 +Instruction: Load argNum:1 int: 0 int: 1 + Store argNum:2 +Instruction: Div argNum:2 +Instruction: Load argNum:1 int: 1 int:2 int: 1 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 1 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 8 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Store argNum:2 int:400 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 +Instruction: Call argNum:2 +Instruction: Load argNum:1 int: 2 Block or something int: 3 + Store argNum:2 int:10 int: 3 + constant argNum:1 int: 0 + + + +This is test: 90_max_container.sy + +int maxArea(int height[], int n) { + int i; + int j; + i = 0; + j = n - 1; + int max_val; + max_val = -1; + while(i < j){ + int area; + if(height[i] < height[j]) + area = (j - i) * height[i]; + else + area = (j - i) * height[j]; + if(area > max_val){ + max_val = area; + } + if(height[i] > height[j]) + j = j - 1; + else + i = i + 1; + } + return max_val; +} + +int main(){ + int res; + int a[10]; + a[0]=3;a[1]=3;a[2]=9;a[3]=0;a[4]=0; + a[5]=1;a[6]=1;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = maxArea(a, res); + return res; +} + +This is test AST: 90_max_container.sy + +NCompUnit + NFuncDecl int maxArea + NVarDecl int height noinit + NVarDecl int n noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NAssignStmt i = 0 + NAssignStmt j = NBinaryExp NIdentifierExp n - 1 + NDeclStmt NVarDecl int max_val noinit + NAssignStmt max_val = NUnaryExp 277 1 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp j + While: NBlockStmt + NDeclStmt NVarDecl int area noinit + NIfStmt NBinaryExp NIdentifierExp height NIdentifierExp i < NIdentifierExp height NIdentifierExp j + True: NAssignStmt area = NBinaryExp NBinaryExp NIdentifierExp j - NIdentifierExp i * NIdentifierExp height NIdentifierExp i + False: NAssignStmt area = NBinaryExp NBinaryExp NIdentifierExp j - NIdentifierExp i * NIdentifierExp height NIdentifierExp j + NIfStmt NBinaryExp NIdentifierExp area > NIdentifierExp max_val + True: NBlockStmt + NAssignStmt max_val = NIdentifierExp area + NIfStmt NBinaryExp NIdentifierExp height NIdentifierExp i > NIdentifierExp height NIdentifierExp j + True: NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + False: NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt NIdentifierExp max_val + NFuncDecl int main + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 3 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 0 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 1 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NAssignStmt res = 10 + NAssignStmt res = NCallExp maxArea NIdentifierExp a NIdentifierExp res + NReturnStmt NIdentifierExp res + + +This is test IR: 90_max_container.sy + + +undefind global identifier + + +This is test: 91_int_factor_sum.sy + +int N; + +int newline; + +int factor(int n ) +{ + int i; + int sum; + sum=0; + i=1; + while(i -1){ + j=n-2; + while(j > -1){ + dp[i*3+j] = dp[(i+1)*3+j] + dp[i*3+j+1]; + j = j - 1; + } + i = i - 1; + } + return dp[0]; +} +int main(){ + int res; + int n; + n=3; + res = uniquePaths(n, n); + return res; +} + +This is test AST: 92_unique_path.sy + +NCompUnit + NFuncDecl int uniquePaths + NVarDecl int m noinit + NVarDecl int n noinit + NIfStmt NBinaryExp NBinaryExp NIdentifierExp m == 1 | NBinaryExp NIdentifierExp n == 1 + True: NReturnStmt 1 + NDeclStmt NVarDecl int dp[9] noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int j noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp m + While: NBlockStmt + NAssignStmt dp[NBinaryExp NBinaryExp NBinaryExp NIdentifierExp i * 3 + NIdentifierExp n - 1] = 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NIdentifierExp n + While: NBlockStmt + NAssignStmt dp[NBinaryExp NBinaryExp NBinaryExp NIdentifierExp m - 1 * 3 + NIdentifierExp i] = 1 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt i = NBinaryExp NIdentifierExp m - 2 + NWhileStmt NBinaryExp NIdentifierExp i > NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt j = NBinaryExp NIdentifierExp n - 2 + NWhileStmt NBinaryExp NIdentifierExp j > NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt dp[NBinaryExp NBinaryExp NIdentifierExp i * 3 + NIdentifierExp j] = NBinaryExp NIdentifierExp dp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp i + 1 * 3 + NIdentifierExp j + NIdentifierExp dp NBinaryExp NBinaryExp NBinaryExp NIdentifierExp i * 3 + NIdentifierExp j + 1 + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt NIdentifierExp dp 0 + NFuncDecl int main + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int n noinit + NAssignStmt n = 3 + NAssignStmt res = NCallExp uniquePaths NIdentifierExp n NIdentifierExp n + NReturnStmt NIdentifierExp res + + +This is test IR: 92_unique_path.sy + +Segmentation fault + + +This is test: 93_decbinoct.sy + +int dec2bin(int a) +{ + int res; + int k; + int i; + int temp; + res=0; + k=1; + temp=a; + while(temp!=0) + { + i=temp%2; + res=k*i+res; + k=k*10; + temp=temp/2; + } + return res; + +} + +int main() +{ + int a; + a=400; + int res; + res=dec2bin(a); + putint(res); + res = 10; + putch(res); + return 0; +} + + +This is test AST: 93_decbinoct.sy + +NCompUnit + NFuncDecl int dec2bin + NVarDecl int a noinit + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int k noinit + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int temp noinit + NAssignStmt res = 0 + NAssignStmt k = 1 + NAssignStmt temp = NIdentifierExp a + NWhileStmt NBinaryExp NIdentifierExp temp != 0 + While: NBlockStmt + NAssignStmt i = NBinaryExp NIdentifierExp temp % 2 + NAssignStmt res = NBinaryExp NBinaryExp NIdentifierExp k * NIdentifierExp i + NIdentifierExp res + NAssignStmt k = NBinaryExp NIdentifierExp k * 10 + NAssignStmt temp = NBinaryExp NIdentifierExp temp / 2 + NReturnStmt NIdentifierExp res + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 400 + NDeclStmt NVarDecl int res noinit + NAssignStmt res = NCallExp dec2bin NIdentifierExp a + NExpStmt NCallExp putint NIdentifierExp res + NAssignStmt res = 10 + NExpStmt NCallExp putch NIdentifierExp res + NReturnStmt 0 + + +This is test IR: 93_decbinoct.sy + +Function: dec2bin entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 11 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Alloca argNum:0 + Store argNum:2 int: 0 int: 2 + Alloca argNum:0 + Store argNum:2 int: 0 int: 3 + Store argNum:2 int:0 int: 0 + Store argNum:2 int:1 int: 1 + Store argNum:2 +Instruction: Load argNum:1 int: -830237136 int: 3 + BlockType 0 InstructionListLength = 4 + Store argNum:2 +terminate called after throwing an instance of 'std::out_of_range' + what(): map::at +Aborted + + +This is test: 94_lcm.sy + +int n; + +int gcd(int m,int n) +{ + int a; + int b; + a=m; + b=n; + + int t; + int r; + + if(m n - 2) + return 1; + int dp[10]; + int i; + i = 0; + while(i -1){ + int j; + if(nums[i] < n - 1 - i){ + j = nums[i]; + } + else + j = n - 1 - i; + while(j > -1){ + if(dp[i+j] != 0){ + dp[i] = 1; + } + j = j - 1; + } + i = i - 1; + } + + return dp[0]; +} +int main(){ + int res; + int a[10]; + a[0]=3;a[1]=3;a[2]=9;a[3]=0;a[4]=0; + a[5]=1;a[6]=1;a[7]=5;a[8]=7;a[9]=8; + res = 10; + res = canJump(a, res); + return res; +} + +This is test AST: 95_jump_game.sy + +NCompUnit + NFuncDecl int canJump + NVarDecl int nums noinit + NVarDecl int n noinit + NIfStmt NBinaryExp NIdentifierExp n == 1 + True: NReturnStmt 1 + NIfStmt NBinaryExp NIdentifierExp nums 0 > NBinaryExp NIdentifierExp n - 2 + True: NReturnStmt 1 + NDeclStmt NVarDecl int dp[10] noinit + NDeclStmt NVarDecl int i noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < NBinaryExp NIdentifierExp n - 1 + While: NBlockStmt + NAssignStmt dp[NIdentifierExp i] = 0 + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NAssignStmt dp[NBinaryExp NIdentifierExp n - 1] = 1 + NAssignStmt i = NBinaryExp NIdentifierExp n - 2 + NWhileStmt NBinaryExp NIdentifierExp i > NUnaryExp 277 1 + While: NBlockStmt + NDeclStmt NVarDecl int j noinit + NIfStmt NBinaryExp NIdentifierExp nums NIdentifierExp i < NBinaryExp NBinaryExp NIdentifierExp n - 1 - NIdentifierExp i + True: NBlockStmt + NAssignStmt j = NIdentifierExp nums NIdentifierExp i + False: NAssignStmt j = NBinaryExp NBinaryExp NIdentifierExp n - 1 - NIdentifierExp i + NWhileStmt NBinaryExp NIdentifierExp j > NUnaryExp 277 1 + While: NBlockStmt + NIfStmt NBinaryExp NIdentifierExp dp NBinaryExp NIdentifierExp i + NIdentifierExp j != 0 + True: NBlockStmt + NAssignStmt dp[NIdentifierExp i] = 1 + NAssignStmt j = NBinaryExp NIdentifierExp j - 1 + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt NIdentifierExp dp 0 + NFuncDecl int main + NDeclStmt NVarDecl int res noinit + NDeclStmt NVarDecl int a[10] noinit + NAssignStmt a[0] = 3 + NAssignStmt a[1] = 3 + NAssignStmt a[2] = 9 + NAssignStmt a[3] = 0 + NAssignStmt a[4] = 0 + NAssignStmt a[5] = 1 + NAssignStmt a[6] = 1 + NAssignStmt a[7] = 5 + NAssignStmt a[8] = 7 + NAssignStmt a[9] = 8 + NAssignStmt res = 10 + NAssignStmt res = NCallExp canJump NIdentifierExp a NIdentifierExp res + NReturnStmt NIdentifierExp res + + +This is test IR: 95_jump_game.sy + +Segmentation fault + + +This is test: 96_int_split.sy + +int N; + +int newline; + +int split(int n ,int a[]) +{ + int i; + i=N-1; + while(i!=-1) + { + a[i]=n%10; + n=n/10; + i=i-1; + + } + + return 0; +} + +int main() +{ + N=4; + newline=10; + int i; + int m; + int b[4]; + m = 1478; + m = split(m,b); + int t; + i=0; + while(i<4) + { + t=b[i]; + putint(t); + putch(newline); + i=i+1; + + } + return 0; +} + + +This is test AST: 96_int_split.sy + +NCompUnit + NVarDecl int N noinit + NVarDecl int newline noinit + NFuncDecl int split + NVarDecl int n noinit + NVarDecl int a noinit + NDeclStmt NVarDecl int i noinit + NAssignStmt i = NBinaryExp NIdentifierExp N - 1 + NWhileStmt NBinaryExp NIdentifierExp i != NUnaryExp 277 1 + While: NBlockStmt + NAssignStmt a[NIdentifierExp i] = NBinaryExp NIdentifierExp n % 10 + NAssignStmt n = NBinaryExp NIdentifierExp n / 10 + NAssignStmt i = NBinaryExp NIdentifierExp i - 1 + NReturnStmt 0 + NFuncDecl int main + NAssignStmt N = 4 + NAssignStmt newline = 10 + NDeclStmt NVarDecl int i noinit + NDeclStmt NVarDecl int m noinit + NDeclStmt NVarDecl int b[4] noinit + NAssignStmt m = 1478 + NAssignStmt m = NCallExp split NIdentifierExp m NIdentifierExp b + NDeclStmt NVarDecl int t noinit + NAssignStmt i = 0 + NWhileStmt NBinaryExp NIdentifierExp i < 4 + While: NBlockStmt + NAssignStmt t = NIdentifierExp b NIdentifierExp i + NExpStmt NCallExp putint NIdentifierExp t + NExpStmt NCallExp putch NIdentifierExp newline + NAssignStmt i = NBinaryExp NIdentifierExp i + 1 + NReturnStmt 0 + + +This is test IR: 96_int_split.sy + + +undefind global identifier + + +This is test: 97_enc_dec.sy + +int enc(int a) +{ + if(a>25) + a=a+60; + else + { + a=a-15; + } + + return a; + +} + +int dec(int a) +{ + if (a>85) + a=a-59; + else + { + a=a+14; + } + + return a; + +} + +int main() +{ + int a; + a=400; + int res; + res=enc(a); + res=dec(res); + putint(res); + res = 10; + putch(res); + return 0; +} + + +This is test AST: 97_enc_dec.sy + +NCompUnit + NFuncDecl int enc + NVarDecl int a noinit + NIfStmt NBinaryExp NIdentifierExp a > 25 + True: NAssignStmt a = NBinaryExp NIdentifierExp a + 60 + False: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a - 15 + NReturnStmt NIdentifierExp a + NFuncDecl int dec + NVarDecl int a noinit + NIfStmt NBinaryExp NIdentifierExp a > 85 + True: NAssignStmt a = NBinaryExp NIdentifierExp a - 59 + False: NBlockStmt + NAssignStmt a = NBinaryExp NIdentifierExp a + 14 + NReturnStmt NIdentifierExp a + NFuncDecl int main + NDeclStmt NVarDecl int a noinit + NAssignStmt a = 400 + NDeclStmt NVarDecl int res noinit + NAssignStmt res = NCallExp enc NIdentifierExp a + NAssignStmt res = NCallExp dec NIdentifierExp res + NExpStmt NCallExp putint NIdentifierExp res + NAssignStmt res = 10 + NExpStmt NCallExp putch NIdentifierExp res + NReturnStmt 0 + + +This is test IR: 97_enc_dec.sy + +Function: enc entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:60 int: 2076849712 + Br argNum:2 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:25 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:15 int: 2076849712 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 2076849712 + +Function: dec entry = 0 succ_bbs_= 1 + BlockType 0 InstructionListLength = 2 + Store argNum:2 +Instruction: Sub argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:59 int: 2076849712 + Br argNum:2 +Instruction: GT argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:85 Block or something + BlockType 0 InstructionListLength = 1 + Store argNum:2 +Instruction: Add argNum:2 +Instruction: Load argNum:1 int: 2076849712 int:14 int: 2076849712 + BlockType 0 InstructionListLength = 1 + Load argNum:1 int: 2076849712 + +Function: main entry = 0 succ_bbs_= 0 + BlockType 0 InstructionListLength = 9 + Alloca argNum:0 + Store argNum:2 int: 0 int: 0 + Store argNum:2 int:400 int: 0 + Alloca argNum:0 + Store argNum:2 int: 0 int: 1 + Store argNum:2 +Instruction: Call argNum:2 +Instruction: Load argNum:1 int: 0 Block or something int: 1 + Store argNum:2 +Instruction: Call argNum:2 +Instruction: Load argNum:1 int: 1 Block or something int: 1 + Store argNum:2 int:10 int: 1 + constant argNum:1 int: 0 + + + +This is test: 98_palindrome_number.sy + +int palindrome(int n) +{ + int a[4]; + int j; + int flag; + j=0; + while(j<4) + { + a[j]=n%10; + n=n/10; + j=j+1; + } + + if(a[0]==a[3] && a[1]==a[2]) + { + flag=1; + }else{ + flag=0; + } + return flag; +} + +int main() +{ + int test; + test=1221; + int flag; + flag=palindrome(test); + if(flag==1) + putint(test); + else + { + flag = 0; + putint(flag); + } + + flag = 10; + putch(flag); + + return 0; + +} + + +This is test AST: 98_palindrome_number.sy + +NCompUnit + NFuncDecl int palindrome + NVarDecl int n noinit + NDeclStmt NVarDecl int a[4] noinit + NDeclStmt NVarDecl int j noinit + NDeclStmt NVarDecl int flag noinit + NAssignStmt j = 0 + NWhileStmt NBinaryExp NIdentifierExp j < 4 + While: NBlockStmt + NAssignStmt a[NIdentifierExp j] = NBinaryExp NIdentifierExp n % 10 + NAssignStmt n = NBinaryExp NIdentifierExp n / 10 + NAssignStmt j = NBinaryExp NIdentifierExp j + 1 + NIfStmt NBinaryExp NBinaryExp NIdentifierExp a 0 == NIdentifierExp a 3 & NBinaryExp NIdentifierExp a 1 == NIdentifierExp a 2 + True: NBlockStmt + NAssignStmt flag = 1 + False: NBlockStmt + NAssignStmt flag = 0 + NReturnStmt NIdentifierExp flag + NFuncDecl int main + NDeclStmt NVarDecl int test noinit + NAssignStmt test = 1221 + NDeclStmt NVarDecl int flag noinit + NAssignStmt flag = NCallExp palindrome NIdentifierExp test + NIfStmt NBinaryExp NIdentifierExp flag == 1 + True: NExpStmt NCallExp putint NIdentifierExp test + False: NBlockStmt + NAssignStmt flag = 0 + NExpStmt NCallExp putint NIdentifierExp flag + NAssignStmt flag = 10 + NExpStmt NCallExp putch NIdentifierExp flag + NReturnStmt 0 + + +This is test IR: 98_palindrome_number.sy + + +undefind global identifier + + +This is test: 99_bin_search.sy + + +int main() +{ + //newline=10; + int i; + int sum; + int a[10]; + sum=0; + //m = 1478; + //int t; + i=0; + while(i<10) + { + a[i]=i+1; + i=i+1; + } + int x; + int high; + int low; + int mid; + int n; + n=10; + x=getint(); + high=n-1; + low=0; + mid=(high+low)/2; + while(a[mid]!=x && low < high) + { + mid=(high+low)/2; + if(x