├── .gitignore ├── .travis.yml ├── Demos └── normal.txt ├── Documents ├── FileDispatcher.doc ├── FileDispatcher.pdf ├── Library.doc ├── Library.pdf ├── QLanguage指令集.doc ├── QLanguage指令集.pdf ├── 内存池性能分析报告.txt ├── 性能分析报告.xls ├── 编码规范.doc └── 编码规范.pdf ├── GeneratorFiles ├── Calculator.txt ├── NewQLanguage.txt ├── QLanguage.txt ├── QParserGenerator.txt └── Test.txt ├── Models ├── Parser.cpp ├── Parser.h ├── ParserTable.cpp └── ParserTable.h ├── Other ├── VS2012 │ └── QLanguage.natvis └── 进度计划表.xls ├── README.md ├── Source ├── CMakeLists.txt ├── Calculator │ ├── CMakeLists.txt │ ├── Calculator.cpp │ ├── Calculator.x64.ParserTable │ ├── Calculator.x86.ParserTable │ └── Parser │ │ ├── Parser.cpp │ │ └── Parser.h ├── FileDispatcher │ ├── CMakeLists.txt │ ├── Data │ │ ├── DataManager.cpp │ │ └── DataManager.h │ ├── Gui │ │ ├── FileInfoWidget.cpp │ │ ├── FileInfoWidget.h │ │ ├── FileList.cpp │ │ ├── FileList.h │ │ ├── MainWindow.cpp │ │ ├── MainWindow.h │ │ ├── Page.cpp │ │ └── Page.h │ └── main.cpp ├── OS │ ├── Makefile │ ├── bochsrc.bxrc │ ├── boot.ld │ ├── head.ld │ ├── kernel.ld │ ├── src │ │ ├── boot │ │ │ ├── boot.asm │ │ │ ├── head.asm │ │ │ └── pm.h │ │ └── init │ │ │ └── init.cpp │ └── tools │ │ └── make_bin.cpp ├── QCore │ ├── CMakeLists.txt │ ├── Library │ │ ├── algo.h │ │ ├── allocator.h │ │ ├── almighty_container.h │ │ ├── btree.h │ │ ├── buffer.cpp │ │ ├── buffer.h │ │ ├── callstack.cpp │ │ ├── callstack.h │ │ ├── char_traits.h │ │ ├── combinator │ │ │ ├── alt.h │ │ │ ├── combinator.h │ │ │ ├── ref.h │ │ │ ├── rule.h │ │ │ ├── seq.h │ │ │ └── while.h │ │ ├── construct.h │ │ ├── definition.h │ │ ├── error.h │ │ ├── fstream.h │ │ ├── function.h │ │ ├── function_additional.h │ │ ├── graph │ │ │ ├── bitmap.cpp │ │ │ ├── bitmap.h │ │ │ └── bmp │ │ │ │ └── structs.h │ │ ├── hash.h │ │ ├── hashmap.h │ │ ├── hashset.h │ │ ├── hashtable.h │ │ ├── ios.h │ │ ├── iostream.cpp │ │ ├── iostream.h │ │ ├── istream.h │ │ ├── iterator.h │ │ ├── list.h │ │ ├── map.h │ │ ├── memory.cpp │ │ ├── memory.h │ │ ├── ostream.h │ │ ├── pair.h │ │ ├── queue.h │ │ ├── rbtree.h │ │ ├── regex │ │ │ ├── regex.cpp │ │ │ └── regex.h │ │ ├── set.h │ │ ├── stack.h │ │ ├── stdstream.h │ │ ├── string.h │ │ ├── system.h │ │ ├── traits.h │ │ ├── typedef.h │ │ └── vector.h │ └── QCore.cpp ├── QCoreUnitTest │ ├── CMakeLists.txt │ ├── QCoreUnitTest.cpp │ └── Units │ │ ├── TestBase.cpp │ │ ├── TestBase.h │ │ ├── TestCombinator.cpp │ │ ├── TestCombinator.h │ │ ├── TestHashMap.cpp │ │ ├── TestHashMap.h │ │ ├── TestHashSet.cpp │ │ ├── TestHashSet.h │ │ ├── TestHashTable.cpp │ │ ├── TestHashTable.h │ │ ├── TestList.cpp │ │ ├── TestList.h │ │ ├── TestMap.cpp │ │ ├── TestMap.h │ │ ├── TestMemoryPool.cpp │ │ ├── TestMemoryPool.h │ │ ├── TestRBTree.cpp │ │ ├── TestRBTree.h │ │ ├── TestRegex.cpp │ │ ├── TestRegex.h │ │ ├── TestSet.cpp │ │ ├── TestSet.h │ │ ├── TestStream.cpp │ │ ├── TestStream.h │ │ ├── TestString.cpp │ │ ├── TestString.h │ │ ├── TestTraits.cpp │ │ ├── TestTraits.h │ │ ├── TestVecotr.cpp │ │ └── TestVector.h ├── QLanguage │ ├── CMakeLists.txt │ ├── Lexer │ │ ├── Lexer.cpp │ │ └── Lexer.h │ ├── Parser │ │ ├── BasicParser.cpp │ │ ├── BasicParser.h │ │ ├── LALR1.cpp │ │ ├── LALR1.h │ │ ├── LALR1ParserTable.cpp │ │ ├── LRProduction.cpp │ │ ├── LRProduction.h │ │ ├── Parser.cpp │ │ ├── Parser.h │ │ ├── ParserTable.cpp │ │ ├── ParserTable.h │ │ ├── Production.cpp │ │ ├── Production.h │ │ └── SyntaxTree │ │ │ ├── README │ │ │ ├── SyntaxTree_ArrayLst.cpp │ │ │ ├── SyntaxTree_ArrayLst.h │ │ │ ├── SyntaxTree_ArrayValue.cpp │ │ │ ├── SyntaxTree_ArrayValue.h │ │ │ ├── SyntaxTree_Assign.cpp │ │ │ ├── SyntaxTree_Assign.h │ │ │ ├── SyntaxTree_Attribute.cpp │ │ │ ├── SyntaxTree_Attribute.h │ │ │ ├── SyntaxTree_Base.cpp │ │ │ ├── SyntaxTree_Base.h │ │ │ ├── SyntaxTree_Block.cpp │ │ │ ├── SyntaxTree_Block.h │ │ │ ├── SyntaxTree_Break.cpp │ │ │ ├── SyntaxTree_Break.h │ │ │ ├── SyntaxTree_Call.cpp │ │ │ ├── SyntaxTree_Call.h │ │ │ ├── SyntaxTree_CallList.cpp │ │ │ ├── SyntaxTree_CallList.h │ │ │ ├── SyntaxTree_Class.cpp │ │ │ ├── SyntaxTree_Class.h │ │ │ ├── SyntaxTree_ClassContent.cpp │ │ │ ├── SyntaxTree_ClassContent.h │ │ │ ├── SyntaxTree_ClassContentList.cpp │ │ │ ├── SyntaxTree_ClassContentList.h │ │ │ ├── SyntaxTree_ClassInherit.cpp │ │ │ ├── SyntaxTree_ClassInherit.h │ │ │ ├── SyntaxTree_ClassName.cpp │ │ │ ├── SyntaxTree_ClassName.h │ │ │ ├── SyntaxTree_Continue.cpp │ │ │ ├── SyntaxTree_Continue.h │ │ │ ├── SyntaxTree_DeclareList.cpp │ │ │ ├── SyntaxTree_DeclareList.h │ │ │ ├── SyntaxTree_DeclareName.cpp │ │ │ ├── SyntaxTree_DeclareName.h │ │ │ ├── SyntaxTree_Do.cpp │ │ │ ├── SyntaxTree_Do.h │ │ │ ├── SyntaxTree_Else.cpp │ │ │ ├── SyntaxTree_Else.h │ │ │ ├── SyntaxTree_Exp.cpp │ │ │ ├── SyntaxTree_Exp.h │ │ │ ├── SyntaxTree_Ext.h │ │ │ ├── SyntaxTree_For.cpp │ │ │ ├── SyntaxTree_For.h │ │ │ ├── SyntaxTree_Function.cpp │ │ │ ├── SyntaxTree_Function.h │ │ │ ├── SyntaxTree_FunctionDeclare.cpp │ │ │ ├── SyntaxTree_FunctionDeclare.h │ │ │ ├── SyntaxTree_GlobalFunction.cpp │ │ │ ├── SyntaxTree_GlobalFunction.h │ │ │ ├── SyntaxTree_If.cpp │ │ │ ├── SyntaxTree_If.h │ │ │ ├── SyntaxTree_Interface.cpp │ │ │ ├── SyntaxTree_Interface.h │ │ │ ├── SyntaxTree_InterfaceContentList.cpp │ │ │ ├── SyntaxTree_InterfaceContentList.h │ │ │ ├── SyntaxTree_Item.cpp │ │ │ ├── SyntaxTree_Item.h │ │ │ ├── SyntaxTree_ItemList.cpp │ │ │ ├── SyntaxTree_ItemList.h │ │ │ ├── SyntaxTree_MemberList.cpp │ │ │ ├── SyntaxTree_MemberList.h │ │ │ ├── SyntaxTree_Name.cpp │ │ │ ├── SyntaxTree_Name.h │ │ │ ├── SyntaxTree_Paramter.cpp │ │ │ ├── SyntaxTree_Paramter.h │ │ │ ├── SyntaxTree_ParamterList.cpp │ │ │ ├── SyntaxTree_ParamterList.h │ │ │ ├── SyntaxTree_Return.cpp │ │ │ ├── SyntaxTree_Return.h │ │ │ ├── SyntaxTree_Stmt.cpp │ │ │ ├── SyntaxTree_Stmt.h │ │ │ ├── SyntaxTree_StmtList.cpp │ │ │ ├── SyntaxTree_StmtList.h │ │ │ ├── SyntaxTree_Switch.cpp │ │ │ ├── SyntaxTree_Switch.h │ │ │ ├── SyntaxTree_SwitchContent.cpp │ │ │ ├── SyntaxTree_SwitchContent.h │ │ │ ├── SyntaxTree_SwitchContentList.cpp │ │ │ ├── SyntaxTree_SwitchContentList.h │ │ │ ├── SyntaxTree_Template.cpp │ │ │ ├── SyntaxTree_Template.h │ │ │ ├── SyntaxTree_TemplateItem.cpp │ │ │ ├── SyntaxTree_TemplateItem.h │ │ │ ├── SyntaxTree_TemplateList.cpp │ │ │ ├── SyntaxTree_TemplateList.h │ │ │ ├── SyntaxTree_Type.cpp │ │ │ ├── SyntaxTree_Type.h │ │ │ ├── SyntaxTree_Value.cpp │ │ │ ├── SyntaxTree_Value.h │ │ │ ├── SyntaxTree_ValueList.cpp │ │ │ ├── SyntaxTree_ValueList.h │ │ │ ├── SyntaxTree_Values.cpp │ │ │ ├── SyntaxTree_Values.h │ │ │ ├── SyntaxTree_ValuesList.cpp │ │ │ ├── SyntaxTree_ValuesList.h │ │ │ ├── SyntaxTree_While.cpp │ │ │ └── SyntaxTree_While.h │ ├── QLanguage.cpp │ ├── QLanguage.x64.ParserTable │ ├── QLanguage.x86.ParserTable │ ├── Rules.txt │ └── VirtualMachine │ │ ├── Variant.cpp │ │ ├── Variant.h │ │ ├── Variant_Ext.cpp │ │ ├── opcodes.cpp │ │ └── opcodes.h ├── QParserGenerator │ ├── CMakeLists.txt │ ├── Parser │ │ ├── Parser.cpp │ │ └── Parser.h │ ├── QParserGenerator.cpp │ └── README ├── WordSegmentation │ ├── CMakeLists.txt │ ├── Common │ │ └── LexicographicTreeNode.h │ └── WordSegmentation.cpp ├── check_bits.cmake └── warning2error.cmake └── Tools ├── QLanguage ├── DEB │ ├── control │ ├── makeall.sh │ └── makedeb.sh └── RPM │ ├── QLanguage.spec │ ├── rpm_package.sh │ └── x86_64 │ └── QLanguage-1.0-1.el6.x86_64.rpm ├── QParserGenerator ├── DEB │ ├── QParserGenerator_Deb_AMD64.deb │ ├── control │ ├── makeall.sh │ └── makedeb.sh └── WIN │ ├── QParserGenerator.x64.exe │ └── QParserGenerator.x86.exe ├── input.txt ├── makebinary.sh └── update.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | Makefile 3 | cmake_install.cmake 4 | *.cbp 5 | *.a 6 | *.user 7 | /Source/QCore/CMakeFiles 8 | /Source/QLanguage/CMakeFiles 9 | /Source/QLanguage-build 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | script: cmake ./Source && make 5 | after_script: ./QCoreUnitTest/QCoreUnitTest < ./Tools/input.txt 6 | notifications: 7 | recipients: 8 | - lwch748@gmail.com 9 | email: 10 | on_success: change 11 | on_failure: always 12 | -------------------------------------------------------------------------------- /Demos/normal.txt: -------------------------------------------------------------------------------- 1 | interface Object 2 | { 3 | void construct(); 4 | 5 | string toString(); 6 | } 7 | 8 | class Rect public implement Object 9 | { 10 | public void construct() 11 | { 12 | left = top = right = bottom = 0; 13 | } 14 | 15 | public void construct(int left, int top, int right, int bottom) 16 | { 17 | this.left = left; 18 | this.top = top; 19 | this.right = right; 20 | this.bottom = bottom; 21 | } 22 | 23 | public int width() 24 | { 25 | return right - left; 26 | } 27 | 28 | public int height() 29 | { 30 | return top - bottom; 31 | } 32 | 33 | public string toString() 34 | { 35 | return ""; 36 | } 37 | 38 | public int left, top, right, bottom; 39 | } 40 | 41 | class IntegerArray public implement Object 42 | { 43 | public void construct(int values[]) 44 | { 45 | this.values = values; 46 | } 47 | 48 | public string toString() 49 | { 50 | return ""; 51 | } 52 | 53 | public int values[]; 54 | } 55 | 56 | class IntegerArray2 public implement Object 57 | { 58 | public void construct(int values[][]) 59 | { 60 | this.values = values; 61 | } 62 | 63 | public string toString() 64 | { 65 | return ""; 66 | } 67 | 68 | public int values[][]; 69 | } 70 | 71 | template 72 | class TemplateObject public implement Object 73 | { 74 | template 75 | int value() 76 | { 77 | return n; 78 | } 79 | } 80 | 81 | template 82 | int template_function(T m) 83 | { 84 | } 85 | 86 | auto closure(auto x) 87 | { 88 | return { 89 | return x; 90 | } 91 | } 92 | 93 | int main() 94 | { 95 | Rect r = {1, 2, 3, 4}; 96 | int width = r.width(); 97 | int height = r.height(); 98 | IntegerArray a1 = {1, 2, 3, 4}; 99 | IntegerArray a2 = {{1}, {2, 3}, {4}}; 100 | Object o = r as Object; 101 | width -= 100; 102 | width = height = 100; 103 | width = -100; 104 | int width = closure(width)(); 105 | return 0; 106 | } -------------------------------------------------------------------------------- /Documents/FileDispatcher.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/FileDispatcher.doc -------------------------------------------------------------------------------- /Documents/FileDispatcher.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/FileDispatcher.pdf -------------------------------------------------------------------------------- /Documents/Library.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/Library.doc -------------------------------------------------------------------------------- /Documents/Library.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/Library.pdf -------------------------------------------------------------------------------- /Documents/QLanguage指令集.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/QLanguage指令集.doc -------------------------------------------------------------------------------- /Documents/QLanguage指令集.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/QLanguage指令集.pdf -------------------------------------------------------------------------------- /Documents/性能分析报告.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/性能分析报告.xls -------------------------------------------------------------------------------- /Documents/编码规范.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/编码规范.doc -------------------------------------------------------------------------------- /Documents/编码规范.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Documents/编码规范.pdf -------------------------------------------------------------------------------- /GeneratorFiles/Calculator.txt: -------------------------------------------------------------------------------- 1 | %token "+" "-" "*" "/" "(" ")" "sin" "cos" "log"; 2 | 3 | %start sym; 4 | 5 | value_type -> "{Real}" 6 | | "{Digit}" 7 | ; 8 | 9 | sym -> "+" exp 10 | | "-" exp 11 | | exp 12 | ; 13 | 14 | exp -> exp "+" term 15 | | exp "-" term 16 | | term 17 | ; 18 | 19 | term -> term "*" factor 20 | | term "/" factor 21 | | factor 22 | ; 23 | 24 | factor -> "sin" bracket 25 | | "cos" bracket 26 | | "log" bracket 27 | | bracket 28 | | value_type 29 | ; 30 | 31 | bracket -> "(" sym ")" 32 | ; 33 | -------------------------------------------------------------------------------- /GeneratorFiles/QParserGenerator.txt: -------------------------------------------------------------------------------- 1 | %token "%" "token" "start" "|" "-" ">" ";" "[" "]"; 2 | 3 | %start start; 4 | 5 | strings -> strings "{String}" 6 | | "{String}" 7 | ; 8 | 9 | vs -> vs "{Letter}" 10 | | vs "{String}" 11 | | "{Letter}" 12 | | "{String}" 13 | ; 14 | 15 | option -> "[" vs "]" 16 | ; 17 | 18 | oneProductionRight -> oneProductionRight option 19 | | oneProductionRight vs 20 | | option 21 | | vs 22 | ; 23 | 24 | someProductionRight -> someProductionRight "|" oneProductionRight 25 | | oneProductionRight 26 | ; 27 | 28 | token -> "%" "token" strings ";" 29 | ; 30 | 31 | someTokens -> someTokens token 32 | | token 33 | ; 34 | 35 | production -> "{Letter}" "-" ">" someProductionRight ";" 36 | ; 37 | 38 | someProductions -> someProductions production 39 | | production 40 | ; 41 | 42 | start -> someTokens "%" "start" "{Letter}" ";" someProductions 43 | | "%" "start" "{Letter}" ";" someProductions 44 | ; 45 | -------------------------------------------------------------------------------- /GeneratorFiles/Test.txt: -------------------------------------------------------------------------------- 1 | %token "=" "+" "*" "id"; 2 | 3 | %start S; 4 | 5 | S -> L "=" R 6 | | R "+" 7 | | R 8 | ; 9 | 10 | L -> "*" R 11 | | "id" 12 | ; 13 | 14 | R -> L 15 | ; -------------------------------------------------------------------------------- /Models/Parser.cpp: -------------------------------------------------------------------------------- 1 | #include "Parser.h" 2 | 3 | namespace QLanguage 4 | { 5 | Parser::Parser(const vector& productions) : BasicParser(productions) 6 | { 7 | } 8 | 9 | Parser::~Parser() 10 | { 11 | } 12 | 13 | bool Parser::shift(const string& s) 14 | { 15 | shifts.push_back(s); 16 | return true; 17 | } 18 | 19 | bool Parser::reduce(ushort i) 20 | { 21 | return true; 22 | } 23 | } -------------------------------------------------------------------------------- /Models/Parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARSER_H_ 2 | #define _PARSER_H_ 3 | 4 | #include "../../QLanguage/Parser/BasicParser.h" 5 | 6 | namespace QLanguage 7 | { 8 | class Parser : public BasicParser 9 | { 10 | public: 11 | Parser(const vector& productions); 12 | virtual ~Parser(); 13 | 14 | virtual bool shift(const string& s); 15 | virtual bool reduce(ushort i); 16 | protected: 17 | vector shifts; 18 | }; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Models/ParserTable.h: -------------------------------------------------------------------------------- 1 | #ifndef _PARSER_TABLE_H_ 2 | #define _PARSER_TABLE_H_ 3 | 4 | #include "../../QCore/Library/typedef.h" 5 | #include "../../QCore/Library/vector.h" 6 | #include "../../QLanguage/Parser/Production.h" 7 | #include "../../QLanguage/Lexer/Lexer.h" 8 | #include "../../QLanguage/Parser/BasicParser.h" 9 | 10 | namespace QLanguage 11 | { 12 | using namespace Library; 13 | 14 | class ParserTable 15 | { 16 | public: 17 | ParserTable(); 18 | 19 | bool loadFromData(const char* data, size_t size); 20 | bool parse(const list& l, BasicParser* pParser); 21 | protected: 22 | const bool compareString(const char* data, size_t size, const char* compare)const; 23 | long index_of_vt(const string& str, long idx = 0); 24 | long getGoTo(ushort s, const Production::Item& i); 25 | public: 26 | vector rules; 27 | protected: 28 | Rule::Context ruleContext; 29 | vector > table; 30 | vector vts; 31 | vector vns; 32 | vector items; 33 | uint iStart; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Other/进度计划表.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Other/进度计划表.xls -------------------------------------------------------------------------------- /Source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 3 | 4 | PROJECT(QLanguage) 5 | 6 | SUBDIRS(QCore) 7 | SUBDIRS(QCoreUnitTest) 8 | SUBDIRS(QLanguage) 9 | SUBDIRS(QParserGenerator) 10 | SUBDIRS(Calculator) -------------------------------------------------------------------------------- /Source/Calculator/Calculator.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/06 3 | created: 6:5:2013 22:43 4 | filename: \Calculator\Calculator.cpp 5 | file path: \Calculator 6 | file base: Calculator 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../QCore/Library/fstream.h" 13 | 14 | #include "../QLanguage/Lexer/Lexer.h" 15 | #include "../QLanguage/Parser/Production.h" 16 | 17 | #include "../QLanguage/Parser/ParserTable.h" 18 | #include "Parser/Parser.h" 19 | 20 | #include 21 | 22 | using namespace QLanguage; 23 | using namespace QLanguage::Library; 24 | 25 | int main() 26 | { 27 | #ifdef X86 28 | fstream fs("Calculator.x86.ParserTable", fstream::in | fstream::binary); 29 | #else 30 | fstream fs("Calculator.x64.ParserTable", fstream::in | fstream::binary); 31 | #endif 32 | string str(fs.size() + 1); 33 | 34 | fs.readAll(const_cast(str.c_str()), str.capacity()); 35 | const_cast(str.c_str())[fs.size()] = 0; 36 | str.setsize(fs.size()); 37 | fs.close(); 38 | 39 | ParserTable parserTable; 40 | parserTable.loadFromData(str.c_str(), str.size()); 41 | 42 | string expression; 43 | cout << "Please input expression:" << endl; 44 | cin >> expression; 45 | 46 | Lexer lexer; 47 | if (lexer.parse(expression)) 48 | { 49 | Parser parser(parserTable.rules); 50 | try 51 | { 52 | if (!parserTable.parse(lexer.result, &parser)) cerr << "Parser error"; 53 | } 54 | catch (const error& e) 55 | { 56 | e.print(); 57 | } 58 | catch (const error& e) 59 | { 60 | e.print(); 61 | } 62 | catch (const error& e) 63 | { 64 | e.print(); 65 | } 66 | } 67 | else cerr << "Lexer error"; 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /Source/Calculator/Calculator.x64.ParserTable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/Calculator/Calculator.x64.ParserTable -------------------------------------------------------------------------------- /Source/Calculator/Calculator.x86.ParserTable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/Calculator/Calculator.x86.ParserTable -------------------------------------------------------------------------------- /Source/Calculator/Parser/Parser.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/10 3 | created: 10:5:2013 12:54 4 | filename: \Calculator\Parser\Parser.h 5 | file path: \Calculator\Parser 6 | file base: Parser 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _PARSER_H_ 13 | #define _PARSER_H_ 14 | 15 | #include "../../QLanguage/Parser/BasicParser.h" 16 | 17 | namespace QLanguage 18 | { 19 | class Parser : public BasicParser 20 | { 21 | public: 22 | Parser(const vector& productions); 23 | virtual ~Parser(); 24 | 25 | virtual bool shift(const string& s); 26 | virtual bool reduce(ushort i); 27 | 28 | bool reduceReal(); 29 | bool reduceDigit(); 30 | bool reduceAdd(); 31 | bool reduceSub(); 32 | bool reduceMul(); 33 | bool reduceDiv(); 34 | bool reduceBrackets(); 35 | bool reduceSin(); 36 | bool reduceCos(); 37 | bool reduceLog(); 38 | bool reduceSymValue(); 39 | protected: 40 | vector shifts; 41 | stack numbers; 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Source/FileDispatcher/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 3 | 4 | PROJECT(FileDispatcher) 5 | 6 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../check_bits.cmake) 7 | 8 | # Qt5 Begin 9 | FIND_PACKAGE(Qt5Widgets REQUIRED) 10 | FIND_PACKAGE(Qt5Gui REQUIRED) 11 | FIND_PACKAGE(Qt5Sql REQUIRED) 12 | 13 | INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDE_DIRS}) 14 | INCLUDE_DIRECTORIES(${Qt5Gui_INCLUDES_DIRS}) 15 | INCLUDE_DIRECTORIES(${Qt5Sql_INCLUDES_DIRS}) 16 | 17 | ADD_DEFINITIONS(${Qt5Widgets_DEFINITIONS}) 18 | ADD_DEFINITIONS(${Qt5Gui_DEFINITIONS}) 19 | ADD_DEFINITIONS(${Qt5Sql_DEFINITIONS}) 20 | 21 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} 22 | ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} 23 | ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} 24 | ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} 25 | ${Qt5Sql_EXECUTABLE_COMPILE_FLAGS}") 26 | 27 | SET(QT_USE_QTMAIN TRUE) 28 | # Qt5 End 29 | 30 | # Data Begin 31 | FILE(GLOB DATA_HEADERS "Data/*.h") 32 | FILE(GLOB DATA_SOURCES "Data/*.cpp") 33 | SET (DATA ${DATA_HEADERS} ${DATA_SOURCES}) 34 | SOURCE_GROUP(Data FILES ${DATA}) 35 | # Data End 36 | 37 | # Gui Begin 38 | FILE(GLOB GUI_HEADERS "Gui/*.h") 39 | FILE(GLOB GUI_SOURCES "Gui/*.cpp") 40 | SET (GUI ${GUI_HEADERS} ${GUI_SOURCES}) 41 | SOURCE_GROUP(Gui FILES ${GUI}) 42 | 43 | QT5_WRAP_CPP(GUI_HEADERS_MOC ${GUI_HEADERS}) 44 | SOURCE_GROUP(MOC FILES ${GUI_HEADERS_MOC}) 45 | 46 | LIST(APPEND GUI ${GUI_HEADERS_MOC}) 47 | # Gui End 48 | 49 | # Source Begin 50 | FILE(GLOB HEADERS "*.h") 51 | FILE(GLOB SOURCES "*.cpp") 52 | 53 | QT5_WRAP_CPP(HEADERS_MOC ${HEADERS}) 54 | SOURCE_GROUP(MOC FILES ${HEADERS_MOC}) 55 | # Source End 56 | 57 | SET(FILES 58 | ${DATA} 59 | ${GUI} 60 | ${HEADERS} 61 | ${SOURCES} 62 | ${HEADERS_MOC} 63 | ) 64 | 65 | IF(WIN32) 66 | ADD_EXECUTABLE(FileDispatcher WIN32 ${FILES}) 67 | ELSE(WIN32) 68 | ADD_EXECUTABLE(FileDispatcher ${FILES}) 69 | ENDIF(WIN32) 70 | TARGET_LINK_LIBRARIES(FileDispatcher 71 | ${Qt5Core_QTMAIN_LIBRARIES} 72 | ${Qt5Widgets_LIBRARIES} 73 | ${Qt5Gui_LIBRARIES} 74 | ${Qt5Sql_LIBRARIES}) 75 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Data/DataManager.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/23 3 | created: 23:6:2013 13:54 4 | filename: \FileDispatcher\Data\DataManager.cpp 5 | file path: \FileDispatcher\Data 6 | file base: DataManager 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include 13 | #include 14 | 15 | #include "DataManager.h" 16 | 17 | DataManager gDataManager; 18 | 19 | DataManager::DataManager() 20 | : conn(QSqlDatabase::addDatabase("QSQLITE")) 21 | { 22 | conn.setDatabaseName("test.db"); 23 | conn.open(); 24 | } 25 | 26 | DataManager::~DataManager() 27 | { 28 | if (conn.isOpen()) conn.close(); 29 | } 30 | 31 | QSqlQuery DataManager::exec(const QString& query)const 32 | { 33 | if (conn.isOpen()) return conn.exec(query); 34 | return QSqlQuery(); 35 | } 36 | 37 | bool DataManager::createTable(const QString& tableName, const QString& parameters) 38 | { 39 | return QSqlQuery(QString("CREATE TABLE IF NOT EXISTS %1(%2)").arg(tableName).arg(parameters)).exec(); 40 | } 41 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Data/DataManager.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/23 3 | created: 23:6:2013 13:54 4 | filename: \FileDispatcher\Data\DataManager.h 5 | file path: \FileDispatcher\Data 6 | file base: DataManager 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _DATA_MANAGER_H_ 13 | #define _DATA_MANAGER_H_ 14 | 15 | #include 16 | 17 | class DataManager 18 | { 19 | public: 20 | DataManager(); 21 | ~DataManager(); 22 | 23 | bool createTable(const QString& tableName, const QString& parameters); 24 | protected: 25 | QSqlQuery exec(const QString& query)const; 26 | protected: 27 | QSqlDatabase conn; 28 | }; 29 | 30 | extern DataManager gDataManager; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/FileInfoWidget.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 16:29 4 | filename: \FileDispatcher\FileInfoWidget.h 5 | file path: \FileDispatcher 6 | file base: FileInfoWidget 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _FILE_DISPATCHER_FILE_INFO_WIDGET_H_ 13 | #define _FILE_DISPATCHER_FILE_INFO_WIDGET_H_ 14 | 15 | #include 16 | 17 | class QItemSelection; 18 | class QLabel; 19 | class QResizeEvent; 20 | 21 | class FileInfoWidget : public QWidget 22 | { 23 | Q_OBJECT 24 | public: 25 | FileInfoWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0); 26 | ~FileInfoWidget(); 27 | protected: 28 | void setupUi(); 29 | protected slots: 30 | void slotSelectionChanged(const QItemSelection&, const QItemSelection&); 31 | protected: 32 | QLabel* mpImage; 33 | QLabel* mpAbsolutePath; 34 | QLabel* mpPermissions; 35 | QLabel* mpSize; 36 | QPixmap transparentImage; 37 | 38 | static QSize imageSize; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/FileList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 15:31 4 | filename: \FileDispatcher\FileList.cpp 5 | file path: \FileDispatcher 6 | file base: FileList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include 13 | #include 14 | #include "FileList.h" 15 | 16 | FileList::FileList(QWidget* parent /* = 0 */) 17 | : QTreeView(parent) 18 | { 19 | QFileSystemModel* pModel = new QFileSystemModel(this); 20 | pModel->setRootPath(QDir::homePath()); 21 | setModel(pModel); 22 | 23 | setSelectionMode(QAbstractItemView::SingleSelection); 24 | header()->setSectionResizeMode(QHeaderView::ResizeToContents); 25 | } 26 | 27 | FileList::~FileList() 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/FileList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 15:25 4 | filename: \FileDispatcher\FileList.h 5 | file path: \FileDispatcher 6 | file base: FileList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _FILE_DISPATCHER_FILE_LIST_H_ 13 | #define _FILE_DISPATCHER_FILE_LIST_H_ 14 | 15 | #include 16 | 17 | class FileList : public QTreeView 18 | { 19 | Q_OBJECT 20 | public: 21 | FileList(QWidget* parent = 0); 22 | ~FileList(); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 13:20 4 | filename: \FileDispatcher\MainWindow.cpp 5 | file path: \FileDispatcher 6 | file base: MainWindow 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include 13 | #include 14 | #include 15 | 16 | #include "Page.h" 17 | #include "MainWindow.h" 18 | 19 | MainWindow::MainWindow(QWidget* parent /* = 0 */, Qt::WindowFlags flags /* = 0 */) 20 | : QMainWindow(parent, flags) 21 | { 22 | setupMenu(); 23 | setCentralWidget(new Page(this)); 24 | 25 | setWindowTitle("File Dispatcher"); 26 | } 27 | 28 | MainWindow::~MainWindow() 29 | { 30 | } 31 | 32 | void MainWindow::setupMenu() 33 | { 34 | mpMenuFile = new QMenu(QString::fromLocal8Bit("&File"), this); 35 | 36 | mpMenuFile->addAction(QString::fromLocal8Bit("&Exit"), this, SLOT(slotExit())); 37 | 38 | menuBar()->addMenu(mpMenuFile); 39 | 40 | mpMenuHelp = new QMenu(QString::fromLocal8Bit("&Help"), this); 41 | 42 | mpMenuHelp->addAction(QString::fromLocal8Bit("&About"), this, SLOT(slotAbout())); 43 | 44 | menuBar()->addMenu(mpMenuHelp); 45 | } 46 | 47 | void MainWindow::slotExit() 48 | { 49 | QApplication::exit(); 50 | } 51 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 13:17 4 | filename: \FileDispatcher\MainWindow.h 5 | file path: \FileDispatcher 6 | file base: MainWindow 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _FILE_DISPATCHER_MAIN_WINDOW_H_ 13 | #define _FILE_DISPATCHER_MAIN_WINDOW_H_ 14 | 15 | #include 16 | 17 | class QMenu; 18 | 19 | class MainWindow : public QMainWindow 20 | { 21 | Q_OBJECT 22 | public: 23 | MainWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); 24 | ~MainWindow(); 25 | protected: 26 | void setupMenu(); 27 | protected slots: 28 | void slotExit(); 29 | protected: 30 | QMenu* mpMenuFile; 31 | QMenu* mpMenuHelp; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/Page.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 15:41 4 | filename: \FileDispatcher\Page.cpp 5 | file path: \FileDispatcher 6 | file base: Page 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include 13 | #include 14 | #include 15 | 16 | #include "FileList.h" 17 | #include "FileInfoWidget.h" 18 | #include "Page.h" 19 | 20 | Page::Page(QWidget* parent /* = 0 */, Qt::WindowFlags flags /* = 0 */) 21 | : QWidget(parent, flags) 22 | { 23 | setupUi(); 24 | } 25 | 26 | Page::~Page() 27 | { 28 | } 29 | 30 | void Page::setupUi() 31 | { 32 | QVBoxLayout* pLayout = new QVBoxLayout(this); 33 | pLayout->setSpacing(0); 34 | pLayout->setMargin(0); 35 | 36 | QLineEdit* pSearchEdit = new QLineEdit(this); 37 | pLayout->addWidget(pSearchEdit); 38 | 39 | QGridLayout* pGridLayout = new QGridLayout(this); 40 | 41 | mpFileList = new FileList(this); 42 | pGridLayout->addWidget(mpFileList, 0, 0); 43 | 44 | mpFileInfoWidget = new FileInfoWidget(this); 45 | pGridLayout->addWidget(mpFileInfoWidget, 0, 1); 46 | 47 | connect(mpFileList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), mpFileInfoWidget, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&))); 48 | 49 | // 3:1 50 | pGridLayout->setColumnStretch(0, 3); 51 | pGridLayout->setColumnStretch(1, 1); 52 | pLayout->addLayout(pGridLayout); 53 | 54 | setLayout(pLayout); 55 | } 56 | -------------------------------------------------------------------------------- /Source/FileDispatcher/Gui/Page.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 15:36 4 | filename: \FileDispatcher\Page.h 5 | file path: \FileDispatcher 6 | file base: Page 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _FILE_DISPATCHER_PAGE_H_ 13 | #define _FILE_DISPATCHER_PAGE_H_ 14 | 15 | #include 16 | 17 | class FileList; 18 | class FileInfoWidget; 19 | 20 | class Page : public QWidget 21 | { 22 | Q_OBJECT 23 | 24 | friend class FileInfoWidget; 25 | public: 26 | Page(QWidget* parent = 0, Qt::WindowFlags flags = 0); 27 | ~Page(); 28 | protected: 29 | void setupUi(); 30 | protected: 31 | FileList* mpFileList; 32 | FileInfoWidget* mpFileInfoWidget; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Source/FileDispatcher/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/16 3 | created: 16:6:2013 12:40 4 | filename: \FileDispatcher\main.cpp 5 | file path: \FileDispatcher 6 | file base: main 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include 13 | 14 | #include "Gui/MainWindow.h" 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | QApplication app(argc, argv); 19 | 20 | MainWindow window; 21 | window.showMaximized(); 22 | 23 | return app.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /Source/OS/Makefile: -------------------------------------------------------------------------------- 1 | AS = as 2 | GCC = gcc 3 | LD = ld 4 | OBJCOPY = objcopy 5 | 6 | GCC_FLAGS = -O0 -Wall -nostdlib -nostdinc -ansi -c 7 | 8 | OBJCOPY_FLAGS = -R.pdr -R.comment -R.note -S -O binary 9 | 10 | all: final/os.bin 11 | 12 | out/boot.asm.o: src/boot/boot.asm 13 | $(AS) $< -o $@ 14 | 15 | out/head.asm.o: src/boot/head.asm 16 | $(AS) $< -o $@ -Isrc/boot 17 | 18 | out/init.c.o: src/init/init.cpp 19 | $(GCC) $(GCC_FLAGS) $< -o $@ 20 | 21 | out/kernel.elf: out/init.c.o 22 | $(LD) out/init.c.o -o $@ -Tkernel.ld 23 | 24 | out/kernel.bin: out/kernel.elf 25 | $(OBJCOPY) $(OBJCOPY_FLAGS) $< $@ 26 | 27 | out/boot.elf: out/boot.asm.o 28 | $(LD) $< -o $@ -Tboot.ld 29 | 30 | out/boot.bin: out/boot.elf 31 | $(OBJCOPY) $(OBJCOPY_FLAGS) $< $@ 32 | 33 | out/head.elf: out/head.asm.o 34 | $(LD) $< -o $@ -Thead.ld 35 | 36 | out/head.bin: out/head.elf 37 | $(OBJCOPY) $(OBJCOPY_FLAGS) $< $@ 38 | 39 | out/make_bin: tools/make_bin.cpp 40 | $(GCC) $< -o $@ 41 | 42 | final/os.bin: out/make_bin out/boot.bin out/head.bin out/kernel.bin 43 | @out/make_bin out/boot.bin out/head.bin out/kernel.bin final/os.bin 44 | 45 | clean: 46 | @rm -fr out/* 47 | 48 | run: final/os.bin 49 | @bochs 50 | -------------------------------------------------------------------------------- /Source/OS/bochsrc.bxrc: -------------------------------------------------------------------------------- 1 | megs: 32 2 | romimage: file=$BXSHARE/BIOS-bochs-latest 3 | vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest 4 | vga: extension=vbe 5 | floppya: 1_44=final/os.bin, status=inserted 6 | boot: a 7 | log: bochsout.txt 8 | mouse: enabled=0 9 | cpu: ips=15000000 10 | vga_update_interval: 150000 11 | -------------------------------------------------------------------------------- /Source/OS/boot.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x7C00; 4 | .text : 5 | { 6 | _ftext = .; 7 | } = 0 8 | } -------------------------------------------------------------------------------- /Source/OS/head.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x0000; 4 | .text : 5 | { 6 | _ftext = .; 7 | } = 0 8 | } 9 | -------------------------------------------------------------------------------- /Source/OS/kernel.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x12013; 4 | .text : 5 | { 6 | _ftext = .; 7 | } = 0 8 | } 9 | -------------------------------------------------------------------------------- /Source/OS/src/boot/boot.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/OS/src/boot/boot.asm -------------------------------------------------------------------------------- /Source/OS/src/boot/head.asm: -------------------------------------------------------------------------------- 1 | .include "pm.h" 2 | 3 | .code16 4 | .text 5 | jmp LABEL_BEGIN 6 | 7 | LABEL_GDT: Descriptor 0, 0, 0 8 | LABEL_DESC_DATA: Descriptor 0, 0xFFFFFFFF, DA_DRW 9 | LABEL_DESC_CODE32: Descriptor 0, 0xFFFF, (DA_CR + DA_32) 10 | LABEL_DESC_KERNEL: Descriptor 0x12000, 0xFFFF, (DA_CR + DA_32) 11 | 12 | .set GdtLen, (. - LABEL_GDT) 13 | 14 | GdtPtr: .short (GdtLen - 1) 15 | .int 0 16 | 17 | .set SelectorData, (LABEL_DESC_DATA - LABEL_GDT) 18 | .set SelectorCode32, (LABEL_DESC_CODE32 - LABEL_GDT) 19 | .set SelectorKernel, (LABEL_DESC_KERNEL - LABEL_GDT) 20 | 21 | LABEL_BEGIN: 22 | mov %cs, %ax 23 | mov %ax, %ds 24 | mov %ax, %es 25 | mov %ax, %ss 26 | 27 | mov $0, %sp 28 | 29 | mov $0x13, %al 30 | mov $0, %ah 31 | int $0x10 32 | 33 | xor %eax, %eax 34 | mov %cs, %ax 35 | shl $4, %eax 36 | addl $(LABEL_CODE32), %eax 37 | movw %ax, (LABEL_DESC_CODE32 + 2) 38 | shr $16, %eax 39 | movb %al, (LABEL_DESC_CODE32 + 4) 40 | movb %ah, (LABEL_DESC_CODE32 + 7) 41 | 42 | xor %eax, %eax 43 | mov %ds, %ax 44 | shl $4, %eax 45 | add $(LABEL_GDT), %eax 46 | movl %eax, (GdtPtr + 2) 47 | 48 | lgdtw GdtPtr 49 | 50 | cli 51 | 52 | inb $0x92, %al 53 | orb $0b00000010, %al 54 | outb %al, $0x92 55 | 56 | movl %cr0, %eax 57 | orl $1, %eax 58 | movl %eax, %cr0 59 | 60 | ljmpl $SelectorCode32, $0 61 | 62 | LABEL_CODE32: 63 | .code32 64 | mov $SelectorData, %ax 65 | mov %ax, %ds 66 | mov %ax, %es 67 | mov %ax, %fs 68 | mov %ax, %gs 69 | mov %ax, %ss 70 | 71 | mov $0x20000, %esp 72 | 73 | mov $(init + 0x10000), %esi 74 | mov $0x12000, %edi 75 | mov $0xFFFF, %ecx 76 | call memcpy 77 | 78 | ljmpl $SelectorKernel, $0x0 79 | memcpy: 80 | mov (%esi), %eax 81 | inc %esi 82 | mov %eax, (%edi) 83 | inc %edi 84 | dec %ecx 85 | jnz memcpy 86 | ret 87 | init: 88 | mov $SelectorData, %ax 89 | mov %ax, %ds 90 | mov %ax, %es 91 | mov %ax, %fs 92 | mov %ax, %gs 93 | mov %ax, %ss 94 | 95 | mov $0x20000, %esp 96 | -------------------------------------------------------------------------------- /Source/OS/src/boot/pm.h: -------------------------------------------------------------------------------- 1 | /* GDT Descriptor Attributes 2 | DA_ : Descriptor Attribute 3 | D : Data Segment 4 | C : Code Segment 5 | S : System Segment 6 | R : Read-only 7 | RW : Read/Write 8 | A : Access */ 9 | .set DA_32, 0x4000 /* 32-bit segment */ 10 | 11 | /* Descriptor privilege level */ 12 | .set DA_DPL0, 0x00 /* DPL = 0 */ 13 | .set DA_DPL1, 0x20 /* DPL = 1 */ 14 | .set DA_DPL2, 0x40 /* DPL = 2 */ 15 | .set DA_DPL3, 0x60 /* DPL = 3 */ 16 | 17 | /* GDT Code- and Data-Segment Types */ 18 | .set DA_DR, 0x90 /* Read-Only */ 19 | .set DA_DRW, 0x92 /* Read/Write */ 20 | .set DA_DRWA, 0x93 /* Read/Write, accessed */ 21 | .set DA_C, 0x98 /* Execute-Only */ 22 | .set DA_CR, 0x9A /* Execute/Read */ 23 | .set DA_CCO, 0x9C /* Execute-Only, conforming */ 24 | .set DA_CCOR, 0x9E /* Execute/Read-Only, conforming */ 25 | 26 | /* GDT System-Segment and Gate-Descriptor Types */ 27 | .set DA_LDT, 0x82 /* LDT */ 28 | .set DA_TaskGate, 0x85 /* Task Gate */ 29 | .set DA_386TSS, 0x89 /* 32-bit TSS(Available) */ 30 | .set DA_386CGate, 0x8C /* 32-bit Call Gate */ 31 | .set DA_386IGate, 0x8E /* 32-bit Interrupt Gate */ 32 | .set DA_386TGate, 0x8F /* 32-bit Trap Gate */ 33 | 34 | /* Selector Attributes */ 35 | .set SA_RPL0, 0 36 | .set SA_RPL1, 1 37 | .set SA_RPL2, 2 38 | .set SA_RPL3, 3 39 | .set SA_TIG, 0 40 | .set SA_TIL, 4 41 | 42 | /* MACROS */ 43 | 44 | /* Segment Descriptor data structure. 45 | Usage: Descriptor Base, Limit, Attr 46 | Base: 4byte 47 | Limit: 4byte (low 20 bits available) 48 | Attr: 2byte (lower 4 bits of higher byte are always 0) */ 49 | .macro Descriptor Base, Limit, Attr 50 | .short \Limit & 0xFFFF 51 | .short \Base & 0xFFFF 52 | .byte (\Base >> 16) & 0xFF 53 | .short ((\Limit >> 8) & 0xF00) | (\Attr & 0xF0FF) 54 | .byte (\Base >> 24) & 0xFF 55 | .endm 56 | 57 | /* Gate Descriptor data structure. 58 | Usage: Gate Selector, Offset, PCount, Attr 59 | Selector: 2byte 60 | Offset: 4byte 61 | PCount: byte 62 | Attr: byte */ 63 | .macro Gate Selector, Offset, PCount, Attr 64 | .short (\Offset & 0xFFFF) 65 | .short \Selector 66 | .short (\PCount & 0x1F) | ((\Attr << 8) & 0xFF00) 67 | .short ((\Offset >> 16) & 0xFFFF) 68 | .endm 69 | -------------------------------------------------------------------------------- /Source/OS/tools/make_bin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | if(argc > 2) 7 | { 8 | FILE* fOut = fopen(argv[argc - 1], "wb+"); 9 | if(fOut == NULL) return 0; 10 | 11 | for(int i = 1; i < argc - 1; ++i) 12 | { 13 | FILE* fp = fopen(argv[i], "rb"); 14 | 15 | if(fp == NULL) continue; 16 | 17 | fseek(fp, 0L, SEEK_END); 18 | long len = ftell(fp); 19 | fseek(fp, 0L, SEEK_SET); 20 | 21 | char* buffer = (char*)malloc(len); 22 | if(buffer == NULL) continue; 23 | fread(buffer, sizeof(char), len, fp); 24 | fwrite(buffer, sizeof(char), len, fOut); 25 | free(buffer); 26 | 27 | fclose(fp); 28 | 29 | printf("append %s successed\n", argv[i]); 30 | } 31 | fclose(fOut); 32 | 33 | printf("make %s successed", argv[argc - 1]); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Source/QCore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 3 | 4 | PROJECT(QCore) 5 | 6 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../check_bits.cmake) 7 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../warning2error.cmake) 8 | 9 | SET(DEBUG_LEVEL "3" CACHE STRING "1;2;3") 10 | SET_PROPERTY(CACHE DEBUG_LEVEL PROPERTY STRINGS "1" "2" "3") 11 | 12 | ADD_DEFINITIONS(-DDEBUG_LEVEL=${DEBUG_LEVEL}) 13 | 14 | # Common Library 15 | FILE(GLOB Library_Headers "Library/*.h") 16 | FILE(GLOB Library_Sources "Library/*.cpp") 17 | SET (Library ${Library_Headers} ${Library_Sources}) 18 | SOURCE_GROUP(Library FILES ${Library}) 19 | 20 | # Regex Library 21 | FILE(GLOB Library_Regex_Headers "Library/regex/*.h") 22 | FILE(GLOB Library_Regex_Sources "Library/regex/*.cpp") 23 | SET (Library_Regex ${Library_Regex_Headers} ${Library_Regex_Sources}) 24 | SOURCE_GROUP(Library\\regex FILES ${Library_Regex}) 25 | 26 | # Combinator Library 27 | FILE(GLOB Library_Combinator_Headers "Library/combinator/*.h") 28 | FILE(GLOB Library_Combinator_Sources "Library/combinator/*.cpp") 29 | SET (Library_Combinator ${Library_Combinator_Headers} ${Library_Combinator_Sources}) 30 | SOURCE_GROUP(Library\\combinator FILES ${Library_Combinator}) 31 | 32 | # Graph Library 33 | FILE(GLOB Library_Graph_BMP_Headers "Library/graph/bmp/*.h") 34 | FILE(GLOB Library_Graph_BMP_Sources "Library/graph/bmp/*.cpp") 35 | SET (Library_Graph_BMP ${Library_Graph_BMP_Headers} ${Library_Graph_BMP_Sources}) 36 | SOURCE_GROUP(Library\\graph\\bmp FILES ${Library_Graph_BMP}) 37 | 38 | FILE(GLOB Library_Graph_Headers "Library/graph/*.h") 39 | FILE(GLOB Library_Graph_Sources "Library/graph/*.cpp") 40 | SET (Library_Graph ${Library_Graph_Headers} ${Library_Graph_Sources}) 41 | SOURCE_GROUP(Library\\graph FILES ${Library_Graph}) 42 | 43 | LIST (APPEND Library_Graph 44 | ${Library_Graph_BMP} 45 | ) 46 | 47 | # Files 48 | SET (FILES 49 | ${Library} 50 | ${Library_Regex} 51 | ${Library_Combinator} 52 | ${Library_Graph} 53 | QCore.cpp 54 | ) 55 | 56 | SET(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1") 57 | SET(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG") 58 | SET(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG") 59 | SET(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /W4 /O2 /Ob1 /D NDEBUG") 60 | 61 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") 62 | 63 | ADD_LIBRARY(QCore STATIC ${FILES}) 64 | SET_TARGET_PROPERTIES(QCore PROPERTIES LINKER_LANGUAGE CXX) 65 | -------------------------------------------------------------------------------- /Source/QCore/Library/almighty_container.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/11 3 | created: 11:4:2013 10:15 4 | filename: \QCore\Library\almighty_container.h 5 | file path: \QCore\Library 6 | file base: almighty_container 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_ALMIGHTY_CONTAINER_H_ 13 | #define _QLANGUAGE_LIBRARY_ALMIGHTY_CONTAINER_H_ 14 | 15 | #include "definition.h" 16 | 17 | NAMESPACE_QLANGUAGE_LIBRARY_START 18 | template 19 | class almighty_container 20 | { 21 | public: 22 | typedef T value_type; 23 | 24 | almighty_container(const value_type& x) : pointer(&x) {} 25 | virtual ~almighty_container() {} 26 | public: 27 | const value_type* pointer; 28 | }; 29 | 30 | template 31 | class almighty_container 32 | { 33 | public: 34 | typedef T value_type; 35 | 36 | almighty_container(value_type& x) : pointer(&x) {} 37 | virtual ~almighty_container() {} 38 | public: 39 | const value_type* pointer; 40 | }; 41 | 42 | template 43 | class almighty_container 44 | { 45 | public: 46 | typedef T value_type; 47 | 48 | almighty_container(const value_type& x) : pointer(&x) {} 49 | virtual ~almighty_container() {} 50 | public: 51 | const value_type* pointer; 52 | }; 53 | 54 | template 55 | class almighty_container 56 | { 57 | public: 58 | typedef T value_type; 59 | 60 | almighty_container(T* x) : pointer(x) {} 61 | virtual ~almighty_container() {} 62 | public: 63 | const value_type* pointer; 64 | }; 65 | 66 | template 67 | class almighty_container 68 | { 69 | public: 70 | typedef T value_type; 71 | 72 | almighty_container(const T* x) : pointer(x) {} 73 | virtual ~almighty_container() {} 74 | public: 75 | const value_type* pointer; 76 | }; 77 | NAMESPACE_QLANGUAGE_LIBRARY_END 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /Source/QCore/Library/buffer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/08 3 | created: 8:4:2013 16:30 4 | filename: \QCore\Library\buffer.h 5 | file path: \QCore\Library 6 | file base: buffer 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_BUFFER_H_ 13 | #define _QLANGUAGE_LIBRARY_BUFFER_H_ 14 | 15 | #include "definition.h" 16 | #include "vector.h" 17 | #include "char_traits.h" 18 | 19 | NAMESPACE_QLANGUAGE_LIBRARY_START 20 | class buffer 21 | { 22 | public: 23 | typedef char value_type; 24 | typedef vector > container_type; 25 | #ifdef MSVC 26 | typedef container_type::size_type size_type; 27 | #else 28 | typedef container_type::size_type size_type; 29 | #endif 30 | typedef char_traits _char_traits; 31 | 32 | enum { align = 1024, half_align = align / 2 }; 33 | 34 | buffer(); 35 | virtual ~buffer(); 36 | 37 | value_type* read(size_type size); 38 | bool append(const value_type* p); 39 | bool append(const value_type* p, size_type size); 40 | bool append(const string& s); 41 | 42 | inline value_type* reserve(size_type size) 43 | { 44 | container.reserve(size); 45 | container.setsize(size); 46 | return container.begin(); 47 | } 48 | 49 | inline void clear() { container.clear(); } 50 | inline const size_type size()const { return container.size(); } 51 | inline const bool empty()const { return container.empty(); } 52 | inline const size_type ROUND_UP(size_type bytes)const { return (bytes + align - 1) & ~(align - 1); } 53 | inline const value_type* pointer()const { return container.begin(); } 54 | void step(size_type size); 55 | protected: 56 | container_type container; 57 | }; 58 | NAMESPACE_QLANGUAGE_LIBRARY_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Source/QCore/Library/callstack.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/01/02 3 | created: 2:1:2013 15:55 4 | filename: \QCore\Library\callstack.h 5 | file path: \QCore\Library 6 | file base: callstack 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QLANGUAGE_LIBRARY_CALLSTACK_H_ 14 | #define _QLANGUAGE_LIBRARY_CALLSTACK_H_ 15 | 16 | #ifdef _DEBUG 17 | 18 | #ifdef WIN32 19 | #include 20 | #include 21 | #include 22 | #include 23 | #endif 24 | 25 | #include "definition.h" 26 | 27 | NAMESPACE_QLANGUAGE_LIBRARY_START 28 | 29 | class CallStack 30 | { 31 | public: 32 | CallStack(); 33 | ~CallStack(); 34 | 35 | struct FuncInfo 36 | { 37 | char szFuncName[512]; 38 | char szFilePath[1024]; 39 | DWORD dwLineNumber; 40 | }; 41 | 42 | DWORD stackTrace(LPVOID* pCallStack, DWORD dwMaxDepth); 43 | void getFuncInfo(LPVOID dwFunc, FuncInfo& info); 44 | 45 | static CallStack& getInstance(); 46 | protected: 47 | bool loadAllModules(); 48 | 49 | static bool loaded; 50 | 51 | enum { maxBufferLength = 4096 }; 52 | char szBuffer[maxBufferLength]; 53 | #ifdef WIN32 54 | HANDLE hProcess; 55 | #endif 56 | enum { iMax = 4096 }; 57 | #ifdef WIN32 58 | HMODULE hModule[iMax]; 59 | #endif 60 | char szModuleName[iMax]; 61 | char szImageName[iMax]; 62 | }; 63 | 64 | NAMESPACE_QLANGUAGE_LIBRARY_END 65 | 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Source/QCore/Library/combinator/alt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/07 3 | created: 7:12:2012 22:54 4 | filename: \QCore\Library\combinator\alt.h 5 | file path: \QCore\Library\combinator 6 | file base: alt 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_COMBINATOR_ALT_H_ 13 | #define _QLANGUAGE_LIBRARY_COMBINATOR_ALT_H_ 14 | 15 | #include "combinator.h" 16 | 17 | NAMESPACE_QLANGUAGE_LIBRARY_START 18 | namespace combinator 19 | { 20 | template 21 | class CombinatorAlt : public Combinator 22 | { 23 | typedef Combinator combinator_type; 24 | public: 25 | CombinatorAlt(combinator_type* first, combinator_type* second) : first(first), second(second) {} 26 | virtual ~CombinatorAlt() {} 27 | 28 | virtual bool parse(const I& input, O& output) 29 | { 30 | O result; 31 | if (first && first->parse(input, result)) 32 | { 33 | output += result; 34 | return true; 35 | } 36 | if (second && second->parse(input, result)) 37 | { 38 | output += result; 39 | return true; 40 | } 41 | return false; 42 | } 43 | 44 | RELEASE_ACHIEVE 45 | protected: 46 | combinator_type* first; 47 | combinator_type* second; 48 | }; 49 | } 50 | NAMESPACE_QLANGUAGE_LIBRARY_END 51 | 52 | #endif -------------------------------------------------------------------------------- /Source/QCore/Library/combinator/ref.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/09 3 | created: 9:12:2012 20:45 4 | filename: \QCore\Library\combinator\ref.h 5 | file path: \QCore\Library\combinator 6 | file base: ref 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_COMBINATOR_REF_H_ 13 | #define _QLANGUAGE_LIBRARY_COMBINATOR_REF_H_ 14 | 15 | #include "combinator.h" 16 | 17 | NAMESPACE_QLANGUAGE_LIBRARY_START 18 | namespace combinator 19 | { 20 | template 21 | class CombinatorRef : public Combinator 22 | { 23 | typedef CombinatorRef self; 24 | typedef Combinator combinator_type; 25 | public: 26 | CombinatorRef(combinator_type*& ref) : ref(ref) {} 27 | virtual ~CombinatorRef() {} 28 | 29 | virtual inline bool parse(const I& input, O& output) 30 | { 31 | return ref ? ref->parse(input, output) : false; 32 | } 33 | 34 | void setRef(combinator_type*& ref) 35 | { 36 | this->ref = ref; 37 | } 38 | 39 | RELEASE_ACHIEVE 40 | public: 41 | combinator_type*& ref; 42 | }; 43 | } 44 | NAMESPACE_QLANGUAGE_LIBRARY_END 45 | 46 | #endif -------------------------------------------------------------------------------- /Source/QCore/Library/combinator/seq.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/07 3 | created: 7:12:2012 22:53 4 | filename: \QCore\Library\combinator\seq.h 5 | file path: \QCore\Library\combinator 6 | file base: seq 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_COMBINATOR_SEQ_H_ 13 | #define _QLANGUAGE_LIBRARY_COMBINATOR_SEQ_H_ 14 | 15 | #include "combinator.h" 16 | 17 | NAMESPACE_QLANGUAGE_LIBRARY_START 18 | namespace combinator 19 | { 20 | template 21 | class CombinatorSeq : public Combinator 22 | { 23 | typedef Combinator combinator_type; 24 | public: 25 | CombinatorSeq(combinator_type* first, combinator_type* second) : first(first), second(second) {} 26 | virtual ~CombinatorSeq() {} 27 | 28 | virtual bool parse(const I& input, O& output) 29 | { 30 | O result1, result2; 31 | if (first && first->parse(input, result1)) 32 | { 33 | if (second && second->parse(Combinator::input(result1), result2)) 34 | { 35 | output += result1; 36 | output += result2; 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | RELEASE_ACHIEVE 44 | protected: 45 | combinator_type* first; 46 | combinator_type* second; 47 | }; 48 | } 49 | NAMESPACE_QLANGUAGE_LIBRARY_END 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Source/QCore/Library/combinator/while.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/07 3 | created: 7:12:2012 22:54 4 | filename: \QCore\Library\combinator\while.h 5 | file path: \QCore\Library\combinator 6 | file base: while 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_COMBINATOR_WHILE_H_ 13 | #define _QLANGUAGE_LIBRARY_COMBINATOR_WHILE_H_ 14 | 15 | #include "combinator.h" 16 | 17 | NAMESPACE_QLANGUAGE_LIBRARY_START 18 | namespace combinator 19 | { 20 | template 21 | class CombinatorWhile : public Combinator 22 | { 23 | typedef Combinator combinator_type; 24 | typedef int size_type; 25 | public: 26 | CombinatorWhile(combinator_type* pCombinator, bool bOnceMore) : pCombinator(pCombinator), bOnceMore(bOnceMore) {} 27 | virtual ~CombinatorWhile() {} 28 | 29 | virtual bool parse(const I& input, O& output) 30 | { 31 | if (!pCombinator) return false; 32 | if (bOnceMore && (end(input) || !pCombinator->parse(input, output))) return false; 33 | while (true) 34 | { 35 | if (!end(input) && pCombinator->parse(input, output)) 36 | { 37 | input = input(output); 38 | } 39 | else 40 | { 41 | return true; 42 | } 43 | } 44 | return false; 45 | } 46 | 47 | RELEASE_ACHIEVE 48 | protected: 49 | combinator_type* pCombinator; 50 | bool bOnceMore; 51 | }; 52 | } 53 | NAMESPACE_QLANGUAGE_LIBRARY_END 54 | 55 | #endif -------------------------------------------------------------------------------- /Source/QCore/Library/definition.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:32 4 | filename: \QCore\Library\definition.h 5 | file path: \QCore\Library 6 | file base: definition 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QLANGUAGE_LIBRARY_DEFINITION_H_ 14 | #define _QLANGUAGE_LIBRARY_DEFINITION_H_ 15 | 16 | #define NAMESPACE_QLANGUAGE_LIBRARY_START namespace QLanguage { namespace Library { 17 | #define NAMESPACE_QLANGUAGE_LIBRARY_END } } 18 | 19 | #include "error.h" 20 | #include "typedef.h" 21 | 22 | NAMESPACE_QLANGUAGE_LIBRARY_START 23 | #define THROW_OUT_OF_RANGE throw error("out of range", __FILE__, __LINE__) 24 | NAMESPACE_QLANGUAGE_LIBRARY_END 25 | 26 | using QLanguage::Library::ushort; 27 | using QLanguage::Library::uint; 28 | using QLanguage::Library::uchar; 29 | using QLanguage::Library::ulong; 30 | using QLanguage::Library::llong; 31 | using QLanguage::Library::ullong; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Source/QCore/Library/function_additional.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/05 3 | created: 5:5:2013 0:03 4 | filename: \QCore\Library\function_additional.h 5 | file path: \QCore\Library 6 | file base: function_additional 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_FUNCTION_ADDITIONAL_H_ 13 | #define _QLANGUAGE_LIBRARY_FUNCTION_ADDITIONAL_H_ 14 | 15 | #include "definition.h" 16 | #include "vector.h" 17 | 18 | NAMESPACE_QLANGUAGE_LIBRARY_START 19 | template 20 | void push_back_vector(vector& v, const T& x) 21 | { 22 | v.push_back(x); 23 | } 24 | 25 | template 26 | void push_back_unique_vector(vector& v, const T& x) 27 | { 28 | v.push_back_unique(x); 29 | } 30 | NAMESPACE_QLANGUAGE_LIBRARY_END 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Source/QCore/Library/graph/bitmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/03/10 3 | created: 10:3:2013 21:03 4 | filename: \QCore\Library\graph\bitmap.h 5 | file path: \QCore\Library\graph 6 | file base: bitmap 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_GRAPH_BITMAP_H_ 13 | #define _QLANGUAGE_LIBRARY_GRAPH_BITMAP_H_ 14 | 15 | #include "bmp/structs.h" 16 | 17 | #include "../allocator.h" 18 | #include "../definition.h" 19 | #include "../typedef.h" 20 | #include "../string.h" 21 | 22 | NAMESPACE_QLANGUAGE_LIBRARY_START 23 | using namespace QLanguage::Library; 24 | namespace graph 25 | { 26 | class Bitmap 27 | { 28 | typedef allocator BitsAlloc; 29 | typedef allocator<_RGBQUAD> QuadAlloc; 30 | public: 31 | enum DepthType 32 | { 33 | Unknown, // 未知 34 | Index1 = 1, // 双色 35 | Index4 = 4, // 16色 36 | Index8 = 8, // 256色 37 | RGB = 24, // RGB 38 | }; 39 | public: 40 | Bitmap(); 41 | Bitmap(size_t width, size_t height, DepthType type = RGB, _RGBQUAD* quadTable = NULL); 42 | ~Bitmap(); 43 | 44 | void setQuadTable(_RGBQUAD* quadTable); 45 | 46 | uchar* line(size_t y); 47 | 48 | void save(const string& path); 49 | protected: 50 | void copyQuadTable(_RGBQUAD* quadTable); 51 | void clearQuadTable(); 52 | const size_t ROUND_UP(size_t bytes, size_t align)const; 53 | protected: 54 | DepthType type; 55 | uchar* bits; 56 | size_t width; 57 | size_t height; 58 | size_t sizePreLine; 59 | _RGBQUAD* pQuadTable; 60 | }; 61 | } 62 | NAMESPACE_QLANGUAGE_LIBRARY_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/QCore/Library/ios.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/08 3 | created: 8:4:2013 16:07 4 | filename: \QCore\Library\ios.h 5 | file path: \QCore\Library 6 | file base: ios 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_IOS_H_ 13 | #define _QLANGUAGE_LIBRARY_IOS_H_ 14 | 15 | #include 16 | 17 | #include "definition.h" 18 | #include "string.h" 19 | 20 | NAMESPACE_QLANGUAGE_LIBRARY_START 21 | template 22 | class basic_ios 23 | { 24 | typedef basic_ios self; 25 | public: 26 | typedef T value_type; 27 | typedef size_t size_type; 28 | typedef typename unsigned_type::type _unsigned; 29 | typedef typename signed_type::type _signed; 30 | 31 | enum radix_type 32 | { 33 | binary, 34 | octonary, 35 | decimal, 36 | hexadecimal 37 | }; 38 | 39 | basic_ios() : radix(decimal) {} 40 | protected: 41 | radix_type radix; 42 | }; 43 | NAMESPACE_QLANGUAGE_LIBRARY_END 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Source/QCore/Library/iostream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/29 3 | created: 29:4:2013 18:06 4 | filename: \QCore\Library\iostream.cpp 5 | file path: \QCore\Library 6 | file base: iostream 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "iostream.h" 13 | 14 | NAMESPACE_QLANGUAGE_LIBRARY_START 15 | basic_stdstream cout(basic_stdstream::out); 16 | basic_stdstream cin(basic_stdstream::in); 17 | basic_stdstream cerr(basic_stdstream::error); 18 | NAMESPACE_QLANGUAGE_LIBRARY_END 19 | -------------------------------------------------------------------------------- /Source/QCore/Library/iostream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/29 3 | created: 29:4:2013 18:04 4 | filename: \QCore\Library\iostream.h 5 | file path: \QCore\Library 6 | file base: iostream 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LIBRARY_IOSTREAM_H_ 13 | #define _QLANGUAGE_LIBRARY_IOSTREAM_H_ 14 | 15 | #include "definition.h" 16 | #include "stdstream.h" 17 | 18 | NAMESPACE_QLANGUAGE_LIBRARY_START 19 | extern basic_stdstream cout; 20 | extern basic_stdstream cin; 21 | extern basic_stdstream cerr; 22 | NAMESPACE_QLANGUAGE_LIBRARY_END 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Source/QCore/Library/pair.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:35 4 | filename: \QCore\Library\pair.h 5 | file path: \QCore\Library 6 | file base: pair 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QLANGUAGE_LIBRARY_PAIR_H_ 14 | #define _QLANGUAGE_LIBRARY_PAIR_H_ 15 | 16 | namespace QLanguage 17 | { 18 | namespace Library 19 | { 20 | template 21 | struct pair 22 | { 23 | typedef T1 first_type; 24 | typedef T2 second_type; 25 | 26 | T1 first; 27 | T2 second; 28 | 29 | pair() : first(T1()), second(T2()) 30 | { 31 | } 32 | 33 | pair(const T1& _first, const T2& _second) : first(_first), second(_second) 34 | { 35 | } 36 | 37 | pair(const pair& p) : first(p.first), second(p.second) 38 | { 39 | } 40 | 41 | template 42 | pair(const pair& p) : first(static_cast(p.first)), second(p.second) 43 | { 44 | } 45 | 46 | template 47 | pair(const pair& p) : first(p.first), second(static_cast(p.second)) 48 | { 49 | } 50 | 51 | template 52 | pair(const pair& p) : first(static_cast(p.first)), second(static_cast(p.second)) 53 | { 54 | } 55 | 56 | inline const bool operator<(const pair& x)const 57 | { 58 | return first < x.first && second < x.second; 59 | } 60 | 61 | inline const bool operator==(const pair& x)const 62 | { 63 | return first == x.first && second == x.second; 64 | } 65 | 66 | inline const bool operator!=(const pair& x)const 67 | { 68 | return first != x.first || second != x.second; 69 | } 70 | }; 71 | } 72 | } 73 | 74 | #endif -------------------------------------------------------------------------------- /Source/QCore/Library/system.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/01/02 3 | created: 2:1:2013 20:41 4 | filename: \QCore\Library\system.h 5 | file path: \QCore\Library 6 | file base: system 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QLANGUAGE_LIBRARY_SYSTEM_H_ 14 | #define _QLANGUAGE_LIBRARY_SYSTEM_H_ 15 | 16 | #include "definition.h" 17 | 18 | NAMESPACE_QLANGUAGE_LIBRARY_START 19 | inline bool isX86() 20 | { 21 | return sizeof(void*) == 4; 22 | } 23 | 24 | inline bool isX64() 25 | { 26 | return sizeof(void*) == 8; 27 | } 28 | 29 | inline bool isWindows() 30 | { 31 | #ifdef WIN32 32 | return true; 33 | #else 34 | return false; 35 | #endif 36 | } 37 | 38 | inline bool isUnix() 39 | { 40 | #ifdef unix 41 | return true; 42 | #else 43 | return false; 44 | #endif 45 | } 46 | 47 | #define WINDOWS 0 48 | #define UNIX 1 49 | 50 | enum 51 | { 52 | optr_type = (sizeof(void*) == 4) ? 86 : 64, 53 | #ifdef WIN32 54 | os_type = WINDOWS, 55 | #else 56 | os_type = UNIX, 57 | #endif 58 | }; 59 | 60 | NAMESPACE_QLANGUAGE_LIBRARY_END 61 | 62 | #endif -------------------------------------------------------------------------------- /Source/QCore/QCore.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:37 4 | filename: \QCore\QCore.cpp 5 | file path: \QCore 6 | file base: QCore 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #include "Library/combinator/alt.h" 14 | #include "Library/combinator/combinator.h" 15 | #include "Library/combinator/ref.h" 16 | #include "Library/combinator/rule.h" 17 | #include "Library/combinator/seq.h" 18 | #include "Library/combinator/while.h" 19 | 20 | #include "Library/graph/bmp/structs.h" 21 | #include "Library/graph/bitmap.h" 22 | 23 | #include "Library/regex/regex.h" 24 | 25 | #include "Library/algo.h" 26 | #include "Library/allocator.h" 27 | #include "Library/btree.h" 28 | #include "Library/buffer.h" 29 | #include "Library/callstack.h" 30 | #include "Library/char_traits.h" 31 | #include "Library/construct.h" 32 | #include "Library/definition.h" 33 | #include "Library/error.h" 34 | #include "Library/fstream.h" 35 | #include "Library/function.h" 36 | #include "Library/hash.h" 37 | #include "Library/hashmap.h" 38 | #include "Library/hashset.h" 39 | #include "Library/hashtable.h" 40 | #include "Library/ios.h" 41 | #include "Library/istream.h" 42 | #include "Library/iterator.h" 43 | #include "Library/list.h" 44 | #include "Library/map.h" 45 | #include "Library/memory.h" 46 | #include "Library/ostream.h" 47 | #include "Library/pair.h" 48 | #include "Library/queue.h" 49 | #include "Library/rbtree.h" 50 | #include "Library/set.h" 51 | #include "Library/stack.h" 52 | #include "Library/string.h" 53 | #include "Library/system.h" 54 | #include "Library/traits.h" 55 | #include "Library/typedef.h" 56 | #include "Library/vector.h" 57 | 58 | namespace QLanguage 59 | { 60 | namespace Library 61 | { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 3 | 4 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../check_bits.cmake) 5 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/../warning2error.cmake) 6 | 7 | IF(NOT MSVC) 8 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wl,-Map=QCoreUnitTest.map") 9 | ENDIF() 10 | 11 | PROJECT(QCoreUnitTest) 12 | 13 | SET(DEBUG_LEVEL "3" CACHE STRING "1;2;3") 14 | SET_PROPERTY(CACHE DEBUG_LEVEL PROPERTY STRINGS "1" "2" "3") 15 | 16 | SET(ENABLE_SPEED_TEST OFF CACHE BOOL OFF) 17 | 18 | ADD_DEFINITIONS(-DDEBUG_LEVEL=${DEBUG_LEVEL}) 19 | 20 | IF (ENABLE_SPEED_TEST) 21 | ADD_DEFINITIONS(-DTEST_SPEED) 22 | ENDIF () 23 | 24 | FILE(GLOB Units_Headers "Units/*.h") 25 | FILE(GLOB Units_Sources "Units/*.cpp") 26 | SET (Units ${Units_Headers} ${Units_Sources}) 27 | SOURCE_GROUP(Units FILES ${Units}) 28 | 29 | LIST (APPEND FILES 30 | ${Units} 31 | QCoreUnitTest.cpp 32 | ) 33 | 34 | SET(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1 -D_DEBUG") 35 | SET(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG") 36 | SET(CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG") 37 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /W4 /O2 /Ob1 /D NDEBUG") 38 | 39 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") 40 | 41 | ADD_EXECUTABLE(QCoreUnitTest ${FILES}) 42 | 43 | TARGET_LINK_LIBRARIES(QCoreUnitTest QCore) 44 | 45 | IF(WIN32) 46 | TARGET_LINK_LIBRARIES(QCoreUnitTest dbghelp psapi) 47 | ENDIF(WIN32) 48 | 49 | #SET_TARGET_PROPERTIES(QCoreUnitTest PROPERTIES COMPILE_FLAGS "-save-temps") 50 | 51 | IF (NOT TARGET QCore) 52 | SUBDIRS(../QCore) 53 | ENDIF() 54 | 55 | ADD_DEPENDENCIES(QCoreUnitTest QCore) 56 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestBase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/02/17 3 | created: 17:2:2013 21:35 4 | filename: \QCoreUnitTest\Units\TestBase.cpp 5 | file path: \QCoreUnitTest\Units 6 | file base: TestBase 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #include "TestBase.h" 14 | 15 | #ifndef WIN32 16 | #include 17 | #endif 18 | 19 | namespace QLanguage 20 | { 21 | namespace Library 22 | { 23 | } 24 | } -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestCombinator.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/09 3 | created: 9:12:2012 20:59 4 | filename: \QCoreUnitTest\Units\TestCombinator.cpp 5 | file path: \QCoreUnitTest\Units 6 | file base: TestCombinator 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../../QCore/Library/string.h" 13 | #include "../../QCore/Library/function.h" 14 | #include "TestCombinator.h" 15 | 16 | namespace QLanguage 17 | { 18 | namespace UnitTest 19 | { 20 | class TestCombinatorResult : public CombinatorResult 21 | { 22 | public: 23 | TestCombinatorResult operator+(const TestCombinatorResult& result) 24 | { 25 | return TestCombinatorResult(); 26 | } 27 | 28 | inline TestCombinatorResult& operator+=(const TestCombinatorResult& x) 29 | { 30 | return *this; 31 | } 32 | }; 33 | 34 | class TestCombinatorResultSelector : public DefaultCombinatorResultSelector 35 | { 36 | public: 37 | const string operator()(const TestCombinatorResult& result)const 38 | { 39 | return result.result; 40 | } 41 | }; 42 | 43 | typedef CombinatorRule CombinatorRule_Type; 44 | 45 | TEST_CASE(TestCombinator) 46 | { 47 | // CombinatorRule_Type a, b, c, d, e; 48 | // CombinatorRule_Type f = a + b; 49 | // CombinatorRule_Type g = c | f; 50 | // a = d + e; 51 | // TestCombinatorResult result; 52 | // g.parse("test", result); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestCombinator.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/12/09 3 | created: 9:12:2012 20:56 4 | filename: \QCoreUnitTest\Units\TestCombinator.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestCombinator 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QCORE_UNIT_TEST_LIBRARY_COMBINATOR_H_ 13 | #define _QCORE_UNIT_TEST_LIBRARY_COMBINATOR_H_ 14 | 15 | #include "TestBase.h" 16 | #include "../../QCore/Library/combinator/rule.h" 17 | 18 | using namespace QLanguage; 19 | using namespace QLanguage::Library; 20 | using namespace QLanguage::Library::combinator; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestHashMap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/01 3 | created: 1:4:2013 14:39 4 | filename: \QCoreUnitTest\Units\TestHashMap.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestHashMap 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_HASHMAP_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_HASHMAP_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/hashmap.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestHashSet.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/01 3 | created: 1:4:2013 14:38 4 | filename: \QCoreUnitTest\Units\TestHashSet.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestHashSet 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_SET_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_SET_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/hashset.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestHashTable.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:38 4 | filename: \QCoreUnitTest\Units\TestHashTable.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestHashTable 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_HASHTABLE_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_HASHTABLE_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/hashtable.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:39 4 | filename: \QCoreUnitTest\Units\TestList.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_LIST_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_LIST_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/list.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestMap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:39 4 | filename: \QCoreUnitTest\Units\TestMap.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestMap 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_MAP_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_MAP_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/map.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestMemoryPool.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:39 4 | filename: \QCoreUnitTest\Units\TestMemoryPool.cpp 5 | file path: \QCoreUnitTest\Units 6 | file base: TestMemoryPool 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #include "../../QCore/Library/fstream.h" 14 | #include "TestMemoryPool.h" 15 | 16 | namespace QLanguage 17 | { 18 | namespace UnitTest 19 | { 20 | TEST_CASE(TestMemoryPool_Speed) 21 | { 22 | fstream stream("memory_pool_report.txt", fstream::out); 23 | MemoryPool pool; 24 | 25 | const size_t size = 1000; 26 | struct type1 27 | { 28 | long a; long b; long c; long d; 29 | long e; long f; long g; long h; 30 | long i; long j; long k; long l; 31 | long m; long n; long o; long p; 32 | 33 | type1() {} 34 | }; 35 | 36 | struct type2 37 | { 38 | type1 a; type1 b; type1 c; type1 d; 39 | type1 e; type1 f; type1 g; type1 h; 40 | type1 i; type1 j; type1 k; type1 l; 41 | type1 m; type1 n; type1 o; type1 p; 42 | 43 | type2() {} 44 | }; 45 | 46 | struct type 47 | { 48 | type2 a; 49 | type2 b; 50 | 51 | type() {} 52 | }; 53 | 54 | for (size_t j = 0; j < 10; ++j) 55 | { 56 | clock_t start = clock(); 57 | for (size_t i = 0; i < size; ++i) 58 | { 59 | type* ptr = static_cast(pool.allocate(sizeof(type), NULL)); 60 | construct(ptr); 61 | destruct(ptr, has_destruct(*ptr)); 62 | pool.deallocate(ptr, sizeof(type)); 63 | } 64 | stream << (clock() - start) * 1000 / CLOCKS_PER_SEC << ','; 65 | start = clock(); 66 | for (size_t i = 0; i < size; ++i) 67 | { 68 | type* ptr = new type; 69 | delete ptr; 70 | } 71 | stream << (clock() - start) * 1000 / CLOCKS_PER_SEC << endl; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestMemoryPool.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:40 4 | filename: \QCoreUnitTest\Units\TestMemoryPool.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestMemoryPool 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_MEMORYPOOL_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_MEMORYPOOL_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/memory.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestRBTree.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:40 4 | filename: \QCoreUnitTest\Units\TestRBTree.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestRBTree 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_RBTREE_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_RBTREE_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/rbtree.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestRegex.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/01/20 3 | created: 20:1:2013 17:52 4 | filename: \QCoreUnitTest\Units\TestRegex.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestRegex 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QCORE_UINT_TEST_LIBRARY_REGEX_H_ 13 | #define _QCORE_UINT_TEST_LIBRARY_REGEX_H_ 14 | 15 | #include "TestBase.h" 16 | #include "../../QCore/Library/regex/regex.h" 17 | 18 | using namespace QLanguage; 19 | using namespace QLanguage::Library; 20 | using namespace QLanguage::Library::regex; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestSet.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:41 4 | filename: \QCoreUnitTest\Units\TestSet.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestSet 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_SET_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_SET_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/set.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/08 3 | created: 8:4:2013 17:09 4 | filename: \QCoreUnitTest\Units\TestStream.cpp 5 | file path: \QCoreUnitTest\Units 6 | file base: TestStream 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "TestStream.h" 13 | 14 | namespace QLanguage 15 | { 16 | namespace UnitTest 17 | { 18 | TEST_CASE(TestStream) 19 | { 20 | #ifdef MSVC 21 | fstream fs("C:\\test.txt", fstream::in | fstream::out); 22 | TEST_ASSERT(fs.size() != 0, "file size error!"); 23 | fs << 'a' << " for test." << endl; 24 | TEST_ASSERT(fs.size() + fs.write_cache_size() != 13, "file size and cache size error!"); 25 | fs.flush(); 26 | TEST_ASSERT(fs.size() != 13, "file size error!"); 27 | 28 | bool b = false; 29 | short s = 1; 30 | ushort us = 2; 31 | int i = 3; 32 | uint ui = 4; 33 | long l = 5; 34 | ulong ul = 6; 35 | llong ll = 7; 36 | ullong ull = 8; 37 | fs << b << s << us << i << ui << l << ul << ll << ull; 38 | TEST_ASSERT(fs.size() + fs.write_cache_size() != 22, "file size and cache size error!"); 39 | fs.flush(); 40 | TEST_ASSERT(fs.size() != 22, "file size error!"); 41 | fs.seek(-9, fstream::current); 42 | fs >> s; 43 | #else 44 | int i; 45 | #endif 46 | cout << 100 << endl; 47 | cout << "please input 100:" << endl; 48 | cin >> i; 49 | TEST_ASSERT(i != 100, "input number is not 100"); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestStream.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/04/08 3 | created: 8:4:2013 17:07 4 | filename: \QCoreUnitTest\Units\TestStream.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestStream 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QCORE_UNIT_TEST_LIBRARY_STREAM_H_ 13 | #define _QCORE_UNIT_TEST_LIBRARY_STREAM_H_ 14 | 15 | #include "TestBase.h" 16 | #include "../../QCore/Library/fstream.h" 17 | #include "../../QCore/Library/iostream.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestString.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:41 4 | filename: \QCoreUnitTest\Units\TestString.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestString 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_STRING_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_STRING_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/string.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestTraits.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:41 4 | filename: \QCoreUnitTest\Units\TestTraits.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestTraits 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_TRAITS_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_TRAITS_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/traits.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/QCoreUnitTest/Units/TestVector.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2012/11/29 3 | created: 29:11:2012 23:42 4 | filename: \QCoreUnitTest\Units\TestVector.h 5 | file path: \QCoreUnitTest\Units 6 | file base: TestVector 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QCORE_UNIT_TEST_LIBRARY_VECTOR_H_ 14 | #define _QCORE_UNIT_TEST_LIBRARY_VECTOR_H_ 15 | 16 | #include "TestBase.h" 17 | #include "../../QCore/Library/vector.h" 18 | 19 | using namespace QLanguage; 20 | using namespace QLanguage::Library; 21 | 22 | #endif -------------------------------------------------------------------------------- /Source/QLanguage/Parser/BasicParser.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/05 3 | created: 5:5:2013 20:20 4 | filename: \QLanguage\Parser\BasicParser.cpp 5 | file path: \QLanguage\Parser 6 | file base: BasicParser 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "BasicParser.h" 13 | 14 | namespace QLanguage 15 | { 16 | BasicParser::BasicParser(const vector& productions) : inputProductions(productions) 17 | { 18 | } 19 | 20 | BasicParser::~BasicParser() 21 | { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/BasicParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/05 3 | created: 5:5:2013 20:19 4 | filename: \QLanguage\Parser\BasicParser.h 5 | file path: \QLanguage\Parser 6 | file base: BasicParser 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_BASIC_PARSER_H_ 13 | #define _QLANGUAGE_BASIC_PARSER_H_ 14 | 15 | #include "Production.h" 16 | #include "../../QCore/Library/vector.h" 17 | 18 | namespace QLanguage 19 | { 20 | class BasicParser 21 | { 22 | public: 23 | BasicParser(const vector& productions); 24 | virtual ~BasicParser(); 25 | 26 | virtual bool shift(const string& s)=0; 27 | virtual bool reduce(ushort i)=0; 28 | protected: 29 | vector inputProductions; 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/LRProduction.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/03/10 3 | created: 10:3:2013 17:44 4 | filename: \QLanguage\Parser\LRProduction.h 5 | file path: \QLanguage\Parser 6 | file base: LRProduction 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_LRPRODUCTION_H_ 13 | #define _QLANGUAGE_LRPRODUCTION_H_ 14 | 15 | #include "Production.h" 16 | 17 | namespace QLanguage 18 | { 19 | class LALR1Production : public Production 20 | { 21 | typedef Production parent; 22 | public: 23 | struct Item 24 | { 25 | enum { Rule, End }type; 26 | regex::Rule rule; 27 | 28 | Item(); 29 | Item(const regex::Rule& rule); 30 | 31 | inline const bool operator==(const Item& x)const 32 | { 33 | return type == x.type && (type == End ? true : rule == x.rule); 34 | } 35 | 36 | inline const bool operator==(const Production::Item& x)const 37 | { 38 | return type == End ? false : rule == x.rule; 39 | } 40 | 41 | inline const bool operator!=(const Item& x)const 42 | { 43 | return type != x.type || (type == End ? true : rule != x.rule); 44 | } 45 | 46 | Item& operator=(const Item& x); 47 | }; 48 | 49 | LALR1Production(); 50 | LALR1Production(const Production::Item& left, const vector& right); 51 | LALR1Production(const Production::Item& left, const Production::Item& right, size_t pos); 52 | LALR1Production(const Production& p, size_t pos); 53 | LALR1Production(const LALR1Production& p); 54 | LALR1Production(const LALR1Production& p, size_t pos); 55 | 56 | const bool operator==(const LALR1Production& p)const; 57 | const bool operator!=(const LALR1Production& p)const; 58 | 59 | LALR1Production& operator=(const LALR1Production& p); 60 | 61 | inline LALR1Production stepUp() 62 | { 63 | LALR1Production x(*this); 64 | ++x.idx; 65 | return x; 66 | } 67 | 68 | void print(Library::ostream& stream)const; 69 | public: 70 | size_t idx; 71 | vector wildCards; 72 | }; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/ParserTable.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/06 3 | created: 6:5:2013 22:57 4 | filename: \QLanguage\Parser\ParserTable.h 5 | file path: \QLanguage\Parser 6 | file base: ParserTable 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _PARSER_TABLE_H_ 13 | #define _PARSER_TABLE_H_ 14 | 15 | #include "../../QCore/Library/typedef.h" 16 | #include "../../QCore/Library/vector.h" 17 | #include "../../QLanguage/Parser/Production.h" 18 | #include "../../QLanguage/Lexer/Lexer.h" 19 | #include "../../QLanguage/Parser/BasicParser.h" 20 | 21 | namespace QLanguage 22 | { 23 | using namespace Library; 24 | 25 | class ParserTable 26 | { 27 | public: 28 | ParserTable(); 29 | 30 | bool loadFromData(const char* data, size_t size); 31 | bool parse(const list& l, BasicParser* pParser); 32 | protected: 33 | const bool compareString(const char* data, size_t size, const char* compare)const; 34 | long index_of_vt(const string& str, long idx = 0); 35 | long getGoTo(ushort s, const Production::Item& i); 36 | public: 37 | vector rules; 38 | protected: 39 | Rule::Context ruleContext; 40 | vector > table; 41 | vector vts; 42 | vector vns; 43 | vector items; 44 | uint iStart; 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/README: -------------------------------------------------------------------------------- 1 | 一、有hash函数的结构 2 | 1.SyntaxTree_Attribute 3 | hash = hash("public" | "private" | "protected") 4 | 2.SyntaxTree_Class 5 | hash = hash(name) 6 | 3.SyntaxTree_ClassName 7 | hash = hash(name) 8 | 4.SyntaxTree_DeclareName 9 | hash = hash(name) 10 | 5.SyntaxTree_Function 11 | hash = hash(template) + hash(attribute) * 2 + hash(returnType) * 2 + hash(name) + hash(parameters) * 2 12 | 6.SyntaxTree_FunctionDeclare 13 | hash = hash(template) + hash(returnType) * 2 + hash(name) + hash(parameters) * 2 14 | 7.SyntaxTree_GlobalFunction 15 | hash = hash(template) + hash(return) * 2 + hash(name) + hash(parameters) * 2 16 | 8.SyntaxTree_Interface 17 | hash = hash(name) 18 | 9.SyntaxTree_Paramter 19 | hash = hash(type) + arrayLst.size() 20 | 10.SyntaxTree_ParamterList 21 | hash = Σhash(childs[i]) << (childs.size() - i) 22 | 11.SyntaxTree_Type 23 | hash = hash(name) + isUnsigned() ? hash("unsigned") : 0 24 | 12.SyntaxTree_Value 25 | hash = hash(value) 26 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ArrayLst.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 12:23 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ArrayLst.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ArrayLst 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ARRAY_LST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ARRAY_LST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ArrayLst : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ArrayLst(); 24 | virtual ~SyntaxTree_ArrayLst(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ArrayLst"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_ArrayLst*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_ArrayLst*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ArrayValue.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 11:27 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ArrayValue.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ArrayValue 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #include "../Parser.h" 14 | #include "SyntaxTree_ArrayValue.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_ArrayValue::SyntaxTree_ArrayValue(SyntaxTree_Values* pValues) 19 | : parent(sizeof(SyntaxTree_ArrayValue)) 20 | , pValues(pValues) 21 | { 22 | } 23 | 24 | SyntaxTree_ArrayValue::~SyntaxTree_ArrayValue() 25 | { 26 | } 27 | 28 | void SyntaxTree_ArrayValue::print(ostream& stream, uint indent)const 29 | { 30 | stream << '{'; 31 | pValues->print(stream, indent); 32 | stream << '}'; 33 | } 34 | 35 | // array_value_desc -> "{" values "}" 36 | bool Parser::reduceArrayValue() 37 | { 38 | #ifdef _DEBUG 39 | TRY_CAST(SyntaxTree_Values*, syntaxTreeStack.top()); 40 | #endif 41 | shifts.pop(); 42 | shifts.pop(); 43 | 44 | SyntaxTree_ArrayValue* pArrayValue = allocator::allocate(); 45 | construct(pArrayValue, dynamic_cast(syntaxTreeStack.top())); 46 | 47 | context.data.insert(pArrayValue); 48 | 49 | syntaxTreeStack.pop(); 50 | syntaxTreeStack.push(pArrayValue); 51 | 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ArrayValue.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 11:27 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ArrayValue.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ArrayValue 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | 13 | #ifndef _QLANGUAGE_SYNTAX_TREE_ARRAYVALUE_H_ 14 | #define _QLANGUAGE_SYNTAX_TREE_ARRAYVALUE_H_ 15 | 16 | #include "SyntaxTree_Values.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_ArrayValue : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_ArrayValue(SyntaxTree_Values* pValues); 26 | virtual ~SyntaxTree_ArrayValue(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_ArrayValue"; } 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_ArrayValue*, &x); 36 | #endif 37 | return *pValues == *dynamic_cast(&x)->pValues; 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_ArrayValue*, &x); 44 | #endif 45 | return *pValues != *dynamic_cast(&x)->pValues; 46 | } 47 | protected: 48 | SyntaxTree_Values* pValues; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Assign.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/13 3 | created: 13:6:2013 15:53 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Assign.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Assign 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ASSIGN_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ASSIGN_H_ 14 | 15 | #include "SyntaxTree_MemberList.h" 16 | #include "SyntaxTree_Base.h" 17 | 18 | namespace QLanguage 19 | { 20 | class SyntaxTree_Assign : public SyntaxTree_Base 21 | { 22 | typedef SyntaxTree_Base parent; 23 | public: 24 | enum Type 25 | { 26 | AddEqual, 27 | SubEqual, 28 | AndEqual, 29 | OrEqual, 30 | XorEqual, 31 | LeftMoveEqual, 32 | RightMoveEqual, 33 | Equal 34 | }; 35 | public: 36 | SyntaxTree_Assign(SyntaxTree_MemberList& memberList, SyntaxTree_Base& exp, Type type); 37 | virtual ~SyntaxTree_Assign(); 38 | 39 | virtual void print(ostream& stream, uint indent)const; 40 | 41 | inline virtual string type()const { return "SyntaxTree_Base"; } 42 | 43 | virtual bool make(Parser* pParser); 44 | 45 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 46 | { 47 | #ifdef _DEBUG 48 | TRY_CAST(const SyntaxTree_Assign*, &x); 49 | #endif 50 | return _type == dynamic_cast(&x)->_type && 51 | memberList == dynamic_cast(&x)->memberList; 52 | } 53 | 54 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 55 | { 56 | #ifdef _DEBUG 57 | TRY_CAST(const SyntaxTree_Assign*, &x); 58 | #endif 59 | return _type != dynamic_cast(&x)->_type || 60 | memberList != dynamic_cast(&x)->memberList; 61 | } 62 | protected: 63 | Type _type; 64 | SyntaxTree_MemberList& memberList; 65 | SyntaxTree_Base& exp; 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Attribute.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/06 3 | created: 6:6:2013 14:22 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Attribute.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Attribute 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Attribute.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_Attribute::SyntaxTree_Attribute(Type type) : parent(sizeof(SyntaxTree_Attribute)), _type(type) 18 | { 19 | } 20 | 21 | SyntaxTree_Attribute::~SyntaxTree_Attribute() 22 | { 23 | } 24 | 25 | void SyntaxTree_Attribute::print(ostream& stream, uint indent)const 26 | { 27 | switch (_type) 28 | { 29 | case Public: 30 | stream << "public"; 31 | break; 32 | case Private: 33 | stream << "private"; 34 | break; 35 | case Protected: 36 | stream << "protected"; 37 | break; 38 | } 39 | } 40 | 41 | const HASH_KEY_TYPE SyntaxTree_Attribute::hash()const 42 | { 43 | return ::hash()(_type == Public ? "public" : _type == Private ? "private" : "protected"); 44 | } 45 | 46 | // attribute -> "public" 47 | // attribute -> "private" 48 | // attribute -> "protected" 49 | bool Parser::reduceAttribute(ushort i) 50 | { 51 | SyntaxTree_Attribute* pAttrivute = allocator::allocate(); 52 | switch (i) 53 | { 54 | case ATTRIBUTE_PUBLIC: 55 | construct(pAttrivute, SyntaxTree_Attribute::Public); 56 | break; 57 | case ATTRIBUTE_PRIVATE: 58 | construct(pAttrivute, SyntaxTree_Attribute::Private); 59 | break; 60 | case ATTRIBUTE_PROTECTED: 61 | construct(pAttrivute, SyntaxTree_Attribute::Protected); 62 | break; 63 | } 64 | 65 | context.data.insert(pAttrivute); 66 | 67 | syntaxTreeStack.push(pAttrivute); 68 | 69 | shifts.pop(); 70 | 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Attribute.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/06 3 | created: 6:6:2013 14:17 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Attribute.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Attribute 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ATTRIBUTE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ATTRIBUTE_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Attribute : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | enum Type 24 | { 25 | Public, 26 | Private, 27 | Protected 28 | }; 29 | public: 30 | SyntaxTree_Attribute(Type type); 31 | virtual ~SyntaxTree_Attribute(); 32 | 33 | virtual void print(ostream& stream, uint indent)const; 34 | 35 | inline virtual string type()const { return "SyntaxTree_Attribute"; } 36 | 37 | virtual const HASH_KEY_TYPE hash()const; 38 | 39 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 40 | { 41 | #ifdef _DEBUG 42 | TRY_CAST(const SyntaxTree_Attribute*, &x); 43 | #endif 44 | return _type == dynamic_cast(&x)->_type; 45 | } 46 | 47 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 48 | { 49 | #ifdef _DEBUG 50 | TRY_CAST(const SyntaxTree_Attribute*, &x); 51 | #endif 52 | return _type != dynamic_cast(&x)->_type; 53 | } 54 | protected: 55 | Type _type; 56 | }; 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Base.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/31 3 | created: 31:5:2013 15:05 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Base.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Base 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "SyntaxTree_Base.h" 13 | 14 | namespace QLanguage 15 | { 16 | SyntaxTree_Base::SyntaxTree_Base(uint size) : _size(size) 17 | { 18 | } 19 | 20 | SyntaxTree_Base::~SyntaxTree_Base() 21 | { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Block.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/01 3 | created: 1:6:2013 20:40 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Block.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Block 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_StmtList.h" 14 | #include "SyntaxTree_Block.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_Block::SyntaxTree_Block() : parent(sizeof(SyntaxTree_Block)), pStmts(NULL) 19 | { 20 | } 21 | 22 | SyntaxTree_Block::SyntaxTree_Block(SyntaxTree_Base* pStmts) : parent(sizeof(SyntaxTree_Block)), pStmts(pStmts) 23 | { 24 | } 25 | 26 | SyntaxTree_Block::~SyntaxTree_Block() 27 | { 28 | } 29 | 30 | void SyntaxTree_Block::print(ostream& stream, uint indent)const 31 | { 32 | //this->printIndent(stream, indent - parent::indent); 33 | stream << '{' << endl; 34 | if (pStmts) pStmts->print(stream, indent); 35 | this->printIndent(stream, indent - parent::indent); 36 | stream << '}'; 37 | } 38 | 39 | // block -> "{" stmt_list "}" 40 | bool Parser::reduceBlockStmts() 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(SyntaxTree_StmtList*, syntaxTreeStack.top()); 44 | #endif 45 | SyntaxTree_Block* pBlock = allocator::allocate(); 46 | construct(pBlock, syntaxTreeStack.top()); 47 | 48 | context.data.insert(pBlock); 49 | 50 | syntaxTreeStack.pop(); 51 | syntaxTreeStack.push(pBlock); 52 | 53 | shifts.pop(); 54 | shifts.pop(); 55 | 56 | return true; 57 | } 58 | 59 | // block -> "{" "}" 60 | bool Parser::reduceBlockEmpty() 61 | { 62 | SyntaxTree_Block* pBlock = allocator::allocate(); 63 | construct(pBlock); 64 | 65 | context.data.insert(pBlock); 66 | 67 | syntaxTreeStack.push(pBlock); 68 | 69 | shifts.pop(); 70 | shifts.pop(); 71 | 72 | return true; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Block.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/01 3 | created: 1:6:2013 20:37 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Block.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Block 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_BLOCK_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_BLOCK_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Block : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Block(); 24 | SyntaxTree_Block(SyntaxTree_Base* pStmts); 25 | virtual ~SyntaxTree_Block(); 26 | 27 | virtual void print(ostream& stream, uint indent)const; 28 | 29 | inline virtual string type()const { return "SyntaxTree_Block"; } 30 | 31 | inline virtual bool make(Parser* pParser) 32 | { 33 | if (pStmts) return pStmts->make(pParser); 34 | return true; 35 | } 36 | 37 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 38 | { 39 | #ifdef _DEBUG 40 | TRY_CAST(const SyntaxTree_Block*, &x); 41 | #endif 42 | return *pStmts == *dynamic_cast(&x)->pStmts; 43 | } 44 | 45 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 46 | { 47 | #ifdef _DEBUG 48 | TRY_CAST(const SyntaxTree_Block*, &x); 49 | #endif 50 | return *pStmts != *dynamic_cast(&x)->pStmts; 51 | } 52 | protected: 53 | SyntaxTree_Base* pStmts; 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Break.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:41 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Break.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Break 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Break.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_Break::SyntaxTree_Break() 18 | : parent(sizeof(SyntaxTree_Break)) 19 | { 20 | } 21 | 22 | SyntaxTree_Break::~SyntaxTree_Break() 23 | { 24 | } 25 | 26 | void SyntaxTree_Break::print(ostream& stream, uint indent)const 27 | { 28 | stream << "break"; 29 | } 30 | 31 | // break_desc -> "break" 32 | bool Parser::reduceBreak() 33 | { 34 | shifts.pop(); 35 | 36 | SyntaxTree_Break* pBreak = allocator::allocate(); 37 | construct(pBreak); 38 | 39 | context.data.insert(pBreak); 40 | 41 | syntaxTreeStack.push(pBreak); 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Break.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:35 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Break.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Break 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_BREAK_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_BREAK_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Break : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Break(); 24 | virtual ~SyntaxTree_Break(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_Break"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_Break*, &x); 34 | #endif 35 | return true; 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_Break*, &x); 42 | #endif 43 | return false; 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Call.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/05 3 | created: 5:6:2013 14:01 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Call.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Call 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CALL_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CALL_H_ 14 | 15 | #include "SyntaxTree_MemberList.h" 16 | #include "SyntaxTree_ValueList.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_Call : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_Call(const SyntaxTree_MemberList& memberList); 26 | SyntaxTree_Call(const SyntaxTree_MemberList& memberList, SyntaxTree_ValueList* pValueList); 27 | virtual ~SyntaxTree_Call(); 28 | 29 | virtual void print(ostream& stream, uint indent)const; 30 | 31 | inline virtual string type()const { return "SyntaxTree_Call"; } 32 | 33 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 34 | { 35 | #ifdef _DEBUG 36 | TRY_CAST(const SyntaxTree_Call*, &x); 37 | #endif 38 | return memberList == dynamic_cast(&x)->memberList && 39 | parent::checkEqual(pValueList, dynamic_cast(&x)->pValueList); 40 | } 41 | 42 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 43 | { 44 | #ifdef _DEBUG 45 | TRY_CAST(const SyntaxTree_Call*, &x); 46 | #endif 47 | return memberList != dynamic_cast(&x)->memberList || 48 | parent::checkNotEqual(pValueList, dynamic_cast(&x)->pValueList); 49 | } 50 | protected: 51 | const SyntaxTree_MemberList& memberList; 52 | SyntaxTree_ValueList* pValueList; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_CallList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/06 3 | created: 6:7:2013 17:24 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_CallList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_CallList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CALL_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CALL_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_CallList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_CallList(); 24 | virtual ~SyntaxTree_CallList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_CallList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | return childs.size() == x.childs.size(); 33 | } 34 | 35 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 36 | { 37 | return childs.size() != x.childs.size(); 38 | } 39 | }; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ClassContentList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 17:03 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ClassContentList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ClassContentList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_ClassContent.h" 14 | #include "SyntaxTree_ClassContentList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_ClassContentList::SyntaxTree_ClassContentList() 19 | : parent(sizeof(SyntaxTree_ClassContentList)) 20 | { 21 | } 22 | 23 | SyntaxTree_ClassContentList::~SyntaxTree_ClassContentList() 24 | { 25 | } 26 | 27 | void SyntaxTree_ClassContentList::print(ostream& stream, uint indent)const 28 | { 29 | for (vector::const_iterator i = childs.begin(), m = childs.end(); i != m; ++i) 30 | { 31 | this->printIndent(stream, indent + parent::indent); 32 | (*i)->print(stream, indent + parent::indent); 33 | stream << endl; 34 | } 35 | } 36 | 37 | // class_content_list -> class_content_list class_content 38 | bool Parser::reduceClassContentList2Size() 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(SyntaxTree_ClassContentList*, syntaxTreeStack[1]); 42 | TRY_CAST(SyntaxTree_ClassContent*, syntaxTreeStack.top()); 43 | #endif 44 | SyntaxTree_ClassContentList* pContentList = dynamic_cast(syntaxTreeStack[1]); 45 | 46 | pContentList->pushChild(syntaxTreeStack.top()); 47 | 48 | syntaxTreeStack.pop(); 49 | 50 | return true; 51 | } 52 | 53 | // class_content_list -> class_content 54 | bool Parser::reduceClassContentList1Size() 55 | { 56 | #ifdef _DEBUG 57 | TRY_CAST(SyntaxTree_ClassContent*, syntaxTreeStack.top()); 58 | #endif 59 | SyntaxTree_ClassContentList* pContentList = allocator::allocate(); 60 | construct(pContentList); 61 | 62 | context.data.insert(pContentList); 63 | 64 | pContentList->pushChild(syntaxTreeStack.top()); 65 | 66 | syntaxTreeStack.pop(); 67 | syntaxTreeStack.push(pContentList); 68 | 69 | return true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ClassContentList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 17:01 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ClassContentList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ClassContentList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CLASS_CONTENT_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CLASS_CONTENT_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ClassContentList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ClassContentList(); 24 | virtual ~SyntaxTree_ClassContentList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ClassContentList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_ClassContentList*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_ClassContentList*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ClassInherit.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 14:36 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ClassInherit.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ClassInherit 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CLASS_INHERIT_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CLASS_INHERIT_H_ 14 | 15 | #include "SyntaxTree_Attribute.h" 16 | #include "SyntaxTree_Base.h" 17 | 18 | namespace QLanguage 19 | { 20 | class SyntaxTree_ClassInherit : public SyntaxTree_Base 21 | { 22 | typedef SyntaxTree_Base parent; 23 | public: 24 | enum Type 25 | { 26 | Implement, 27 | Extend 28 | }; 29 | public: 30 | SyntaxTree_ClassInherit(const SyntaxTree_Attribute& attribute, Type type, const string& name); 31 | virtual ~SyntaxTree_ClassInherit(); 32 | 33 | virtual void print(ostream& stream, uint indent)const; 34 | 35 | inline virtual string type()const { return "SyntaxTree_ClassInherit"; } 36 | 37 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 38 | { 39 | #ifdef _DEBUG 40 | TRY_CAST(const SyntaxTree_ClassInherit*, &x); 41 | #endif 42 | return attribute == dynamic_cast(&x)->attribute && 43 | _type == dynamic_cast(&x)->_type && 44 | name == dynamic_cast(&x)->name; 45 | } 46 | 47 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 48 | { 49 | #ifdef _DEBUG 50 | TRY_CAST(const SyntaxTree_ClassInherit*, &x); 51 | #endif 52 | return attribute != dynamic_cast(&x)->attribute || 53 | _type != dynamic_cast(&x)->_type || 54 | name != dynamic_cast(&x)->name; 55 | } 56 | protected: 57 | const SyntaxTree_Attribute& attribute; 58 | Type _type; 59 | string name; 60 | }; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ClassName.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 13:50 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ClassName.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ClassName 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_ClassName.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_ClassName::SyntaxTree_ClassName(const string& name) : parent(sizeof(SyntaxTree_ClassName)), name(name) 18 | { 19 | } 20 | 21 | SyntaxTree_ClassName::SyntaxTree_ClassName() : parent(sizeof(SyntaxTree_ClassName)) 22 | { 23 | } 24 | 25 | SyntaxTree_ClassName::~SyntaxTree_ClassName() 26 | { 27 | } 28 | 29 | void SyntaxTree_ClassName::print(ostream& stream, uint indent)const 30 | { 31 | stream << "class " << name << ' '; 32 | } 33 | 34 | const HASH_KEY_TYPE SyntaxTree_ClassName::hash()const 35 | { 36 | return ::hash()(name); 37 | } 38 | 39 | // class_desc1 -> "class" "{Letter}" 40 | bool Parser::reduceClassWithName() 41 | { 42 | SyntaxTree_ClassName* pClassName = allocator::allocate(); 43 | construct(pClassName, shifts.top()); 44 | 45 | context.data.insert(pClassName); 46 | 47 | syntaxTreeStack.push(pClassName); 48 | 49 | shifts.pop(); 50 | shifts.pop(); 51 | return true; 52 | } 53 | 54 | // class_desc -> "class" 55 | bool Parser::reduceClassWithoutName() 56 | { 57 | SyntaxTree_ClassName* pClassName = allocator::allocate(); 58 | construct(pClassName); 59 | 60 | context.data.insert(pClassName); 61 | 62 | syntaxTreeStack.push(pClassName); 63 | 64 | shifts.pop(); 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ClassName.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 13:46 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ClassName.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ClassName 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CLASS_NAME_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CLASS_NAME_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ClassName : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ClassName(const string& name); 24 | SyntaxTree_ClassName(); 25 | virtual ~SyntaxTree_ClassName(); 26 | 27 | virtual void print(ostream& stream, uint indent)const; 28 | 29 | inline virtual string type()const { return "SyntaxTree_ClassName"; } 30 | 31 | virtual const HASH_KEY_TYPE hash()const; 32 | 33 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 34 | { 35 | #ifdef _DEBUG 36 | TRY_CAST(const SyntaxTree_ClassName*, &x); 37 | #endif 38 | return name == dynamic_cast(&x)->name; 39 | } 40 | 41 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 42 | { 43 | #ifdef _DEBUG 44 | TRY_CAST(const SyntaxTree_ClassName*, &x); 45 | #endif 46 | return name != dynamic_cast(&x)->name; 47 | } 48 | protected: 49 | string name; 50 | }; 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Continue.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:47 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Continue.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Continue 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Continue.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_Continue::SyntaxTree_Continue() 18 | : parent(sizeof(SyntaxTree_Continue)) 19 | { 20 | } 21 | 22 | SyntaxTree_Continue::~SyntaxTree_Continue() 23 | { 24 | } 25 | 26 | void SyntaxTree_Continue::print(ostream& stream, uint indent)const 27 | { 28 | stream << "continue"; 29 | } 30 | 31 | // continue_desc -> "continue" 32 | bool Parser::reduceContinue() 33 | { 34 | shifts.pop(); 35 | 36 | SyntaxTree_Continue* pContinue = allocator::allocate(); 37 | construct(pContinue); 38 | 39 | context.data.insert(pContinue); 40 | 41 | syntaxTreeStack.push(pContinue); 42 | 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Continue.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:44 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Continue.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Continue 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_CONTINUE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_CONTINUE_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Continue : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Continue(); 24 | virtual ~SyntaxTree_Continue(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_Continue"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_Continue*, &x); 34 | #endif 35 | return true; 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_Continue*, &x); 42 | #endif 43 | return false; 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_DeclareList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/31 3 | created: 31:5:2013 16:22 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_DeclareList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_DeclareName 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_DECLARE_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_DECLARE_LIST_H_ 14 | 15 | #include "SyntaxTree_ArrayLst.h" 16 | #include "SyntaxTree_Type.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_Exp; 22 | 23 | class SyntaxTree_DeclareList : public SyntaxTree_Base 24 | { 25 | typedef SyntaxTree_Base parent; 26 | public: 27 | SyntaxTree_DeclareList(const SyntaxTree_Type& type); 28 | virtual ~SyntaxTree_DeclareList(); 29 | 30 | virtual void print(ostream& stream, uint indent)const; 31 | 32 | inline virtual string type()const { return "SyntaxTree_DeclareList"; } 33 | 34 | virtual bool make(Parser* pParser); 35 | 36 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 37 | { 38 | #ifdef _DEBUG 39 | TRY_CAST(const SyntaxTree_DeclareList*, &x); 40 | #endif 41 | return _type == dynamic_cast(&x)->_type && childs.size() == x.childs.size(); 42 | } 43 | 44 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 45 | { 46 | #ifdef _DEBUG 47 | TRY_CAST(const SyntaxTree_DeclareList*, &x); 48 | #endif 49 | return _type != dynamic_cast(&x)->_type || childs.size() != x.childs.size(); 50 | } 51 | protected: 52 | const SyntaxTree_Type& _type; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_DeclareName.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 14:40 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_DeclareName.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_DeclareName 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Exp.h" 14 | #include "SyntaxTree_DeclareName.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_DeclareName::SyntaxTree_DeclareName(const string& name, SyntaxTree_ArrayLst* pArrayLst, SyntaxTree_Exp* pExp) 19 | : parent(sizeof(SyntaxTree_DeclareName)) 20 | , name(name) 21 | , pArrayLst(pArrayLst) 22 | , pExp(pExp) 23 | { 24 | } 25 | 26 | SyntaxTree_DeclareName::SyntaxTree_DeclareName(const string& name, SyntaxTree_ArrayLst* pArrayLst) 27 | : parent(sizeof(SyntaxTree_DeclareName)) 28 | , name(name) 29 | , pArrayLst(pArrayLst) 30 | , pExp(NULL) 31 | { 32 | } 33 | 34 | SyntaxTree_DeclareName::SyntaxTree_DeclareName(const string& name, SyntaxTree_Exp* pExp) 35 | : parent(sizeof(SyntaxTree_DeclareName)) 36 | , name(name) 37 | , pArrayLst(NULL) 38 | , pExp(pExp) 39 | { 40 | } 41 | 42 | SyntaxTree_DeclareName::SyntaxTree_DeclareName(const string& name) 43 | : parent(sizeof(SyntaxTree_DeclareName)) 44 | , name(name) 45 | , pArrayLst(NULL) 46 | , pExp(NULL) 47 | { 48 | } 49 | 50 | SyntaxTree_DeclareName::~SyntaxTree_DeclareName() 51 | { 52 | } 53 | 54 | void SyntaxTree_DeclareName::print(ostream& stream, uint indent)const 55 | { 56 | stream << name; 57 | if (pArrayLst) pArrayLst->print(stream, indent); 58 | if (pExp) 59 | { 60 | stream << " = "; 61 | pExp->print(stream, indent); 62 | } 63 | } 64 | 65 | const HASH_KEY_TYPE SyntaxTree_DeclareName::hash()const 66 | { 67 | return ::hash()(name); 68 | } 69 | 70 | bool SyntaxTree_DeclareName::make(Parser* pParser) 71 | { 72 | bool bResult = true; 73 | if (pParser->getRegister(name) == -1) throw error("have no register", __FILE__, __LINE__); 74 | if (pExp) bResult = pExp->make(pParser); 75 | return bResult; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Do.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/20 3 | created: 20:6:2013 22:11 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Do.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Do 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_H_ 14 | 15 | #include "SyntaxTree_Block.h" 16 | #include "SyntaxTree_Exp.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_Do : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_Do(SyntaxTree_Block& block, SyntaxTree_Exp& exp); 26 | virtual ~SyntaxTree_Do(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_Do"; } 31 | 32 | virtual bool make(Parser *pParser); 33 | 34 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 35 | { 36 | #ifdef _DEBUG 37 | TRY_CAST(const SyntaxTree_Do*, &x); 38 | #endif 39 | return block == dynamic_cast(&x)->block && 40 | exp == dynamic_cast(&x)->exp; 41 | } 42 | 43 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 44 | { 45 | #ifdef _DEBUG 46 | TRY_CAST(const SyntaxTree_Do*, &x); 47 | #endif 48 | return block != dynamic_cast(&x)->block || 49 | exp != dynamic_cast(&x)->exp; 50 | } 51 | protected: 52 | SyntaxTree_Block& block; 53 | SyntaxTree_Exp& exp; 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Else.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/04 3 | created: 4:7:2013 22:05 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Else.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Else 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Stmt.h" 14 | #include "SyntaxTree_Block.h" 15 | #include "SyntaxTree_Else.h" 16 | 17 | namespace QLanguage 18 | { 19 | SyntaxTree_Else::SyntaxTree_Else(SyntaxTree_Base& content) 20 | : parent(sizeof(SyntaxTree_Else)) 21 | , content(content) 22 | { 23 | } 24 | 25 | SyntaxTree_Else::~SyntaxTree_Else() 26 | { 27 | } 28 | 29 | void SyntaxTree_Else::print(ostream& stream, uint indent)const 30 | { 31 | stream << "else "; 32 | if (content.type() == "SyntaxTree_Stmt") content.print(stream, 0); 33 | else content.print(stream, indent + parent::indent); 34 | } 35 | 36 | template 37 | inline void construct(T1* p, T2& value) 38 | { 39 | new (p) T1(value); 40 | } 41 | 42 | // else_desc -> "else" stmt 43 | // else_desc -> "else" block 44 | bool Parser::reduceElse(ushort i) 45 | { 46 | #ifdef _DEBUG 47 | if (i == ELSE_DESC_ELSE_STMT) TRY_CAST(SyntaxTree_Stmt*, syntaxTreeStack.top()); 48 | else TRY_CAST(SyntaxTree_Block*, syntaxTreeStack.top()); 49 | #endif 50 | shifts.pop(); 51 | 52 | SyntaxTree_Else* pElse = allocator::allocate(); 53 | construct(pElse, *syntaxTreeStack.top()); 54 | 55 | context.data.insert(pElse); 56 | 57 | syntaxTreeStack.pop(); 58 | syntaxTreeStack.push(pElse); 59 | 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Else.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/04 3 | created: 4:7:2013 22:00 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Else.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Else 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ELSE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ELSE_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Else : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Else(SyntaxTree_Base& content); 24 | virtual ~SyntaxTree_Else(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_Else"; } 29 | 30 | inline virtual bool make(Parser* pParser) 31 | { 32 | return content.make(pParser); 33 | } 34 | 35 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 36 | { 37 | #ifdef _DEBUG 38 | TRY_CAST(const SyntaxTree_Else*, &x); 39 | #endif 40 | return content == dynamic_cast(&x)->content; 41 | } 42 | 43 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 44 | { 45 | #ifdef _DEBUG 46 | TRY_CAST(const SyntaxTree_Else*, &x); 47 | #endif 48 | return content != dynamic_cast(&x)->content; 49 | } 50 | protected: 51 | SyntaxTree_Base& content; 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Ext.h: -------------------------------------------------------------------------------- 1 | #ifndef _QLANGUAGE_SYNTAX_TREE_EXT_H_ 2 | #define _QLANGUAGE_SYNTAX_TREE_EXT_H_ 3 | 4 | #include "SyntaxTree_Exp.h" 5 | 6 | namespace QLanguage 7 | { 8 | template 9 | bool make_exp(Parser* pParser, SyntaxTree_Exp& exp, True_Func tf, False_Func ff, NoConst_Func ncf) 10 | { 11 | if (!exp.make(pParser)) return false; 12 | if (exp.isConstValue()) 13 | { 14 | if (exp.toVariant(pParser).toBool()) 15 | { 16 | return tf(pParser); 17 | } 18 | else 19 | { 20 | return ff(pParser); 21 | } 22 | } 23 | else 24 | { 25 | return ncf(pParser); 26 | } 27 | } 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_For.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/20 3 | created: 20:6:2013 22:11 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_For.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_For 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_FOR_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_FOR_H_ 14 | 15 | #include "SyntaxTree_Exp.h" 16 | #include "SyntaxTree_Block.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_For : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_For(SyntaxTree_Base& stmt1, SyntaxTree_Exp& exp, SyntaxTree_Base& stmt2, SyntaxTree_Block& block); 26 | virtual ~SyntaxTree_For(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_For"; } 31 | 32 | virtual bool make(Parser *pParser); 33 | 34 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 35 | { 36 | #ifdef _DEBUG 37 | TRY_CAST(const SyntaxTree_For*, &x); 38 | #endif 39 | return stmt1 == dynamic_cast(&x)->stmt1 && 40 | exp == dynamic_cast(&x)->exp && 41 | stmt2 == dynamic_cast(&x)->stmt2 && 42 | block == dynamic_cast(&x)->block; 43 | } 44 | 45 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 46 | { 47 | #ifdef _DEBUG 48 | TRY_CAST(const SyntaxTree_For*, &x); 49 | #endif 50 | return stmt1 != dynamic_cast(&x)->stmt1 || 51 | exp != dynamic_cast(&x)->exp || 52 | stmt2 != dynamic_cast(&x)->stmt2 || 53 | block != dynamic_cast(&x)->block; 54 | } 55 | protected: 56 | SyntaxTree_Base& stmt1; 57 | SyntaxTree_Exp& exp; 58 | SyntaxTree_Base& stmt2; 59 | SyntaxTree_Block& block; 60 | }; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_If.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/15 3 | created: 15:6:2013 16:32 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_If.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_If 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_IF_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_IF_H_ 14 | 15 | #include "SyntaxTree_Exp.h" 16 | #include "SyntaxTree_Else.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_If : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_If(SyntaxTree_Exp& exp, SyntaxTree_Base& op1, SyntaxTree_Else* pElse); 26 | SyntaxTree_If(SyntaxTree_Exp& exp, SyntaxTree_Base& op1); 27 | virtual ~SyntaxTree_If(); 28 | 29 | virtual void print(ostream& stream, uint indent)const; 30 | 31 | inline virtual string type()const { return "SyntaxTree_If"; } 32 | 33 | virtual bool make(Parser* pParser); 34 | 35 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 36 | { 37 | #ifdef _DEBUG 38 | TRY_CAST(const SyntaxTree_If*, &x); 39 | #endif 40 | return exp == dynamic_cast(&x)->exp && 41 | op1 == dynamic_cast(&x)->op1 && 42 | parent::checkEqual(pElse, dynamic_cast(&x)->pElse); 43 | } 44 | 45 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 46 | { 47 | #ifdef _DEBUG 48 | TRY_CAST(const SyntaxTree_If*, &x); 49 | #endif 50 | return exp != dynamic_cast(&x)->exp || 51 | op1 != dynamic_cast(&x)->op1 || 52 | parent::checkNotEqual(pElse, dynamic_cast(&x)->pElse); 53 | } 54 | protected: 55 | SyntaxTree_Exp& exp; 56 | SyntaxTree_Base& op1; 57 | SyntaxTree_Else* pElse; 58 | }; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 11:15 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Interface.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Interface 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_INTERFACE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_INTERFACE_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_InterfaceContentList; 20 | 21 | class SyntaxTree_Interface : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_Interface(const string& name, SyntaxTree_InterfaceContentList* pContentList); 26 | SyntaxTree_Interface(const string& name); 27 | virtual ~SyntaxTree_Interface(); 28 | 29 | virtual void print(ostream& stream, uint indent)const; 30 | 31 | inline virtual string type()const { return "SyntaxTree_Interface"; } 32 | 33 | virtual const HASH_KEY_TYPE hash()const; 34 | 35 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 36 | { 37 | #ifdef _DEBUG 38 | TRY_CAST(const SyntaxTree_Interface*, &x); 39 | #endif 40 | return name == dynamic_cast(&x)->name; 41 | } 42 | 43 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 44 | { 45 | #ifdef _DEBUG 46 | TRY_CAST(const SyntaxTree_Interface*, &x); 47 | #endif 48 | return name != dynamic_cast(&x)->name; 49 | } 50 | protected: 51 | string name; 52 | SyntaxTree_InterfaceContentList* pContentList; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_InterfaceContentList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 13:12 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_InterfaceContentList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_InterfaceContentList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_FunctionDeclare.h" 14 | #include "SyntaxTree_InterfaceContentList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_InterfaceContentList::SyntaxTree_InterfaceContentList() : parent(sizeof(SyntaxTree_InterfaceContentList)) 19 | { 20 | } 21 | 22 | SyntaxTree_InterfaceContentList::~SyntaxTree_InterfaceContentList() 23 | { 24 | } 25 | 26 | void SyntaxTree_InterfaceContentList::print(ostream& stream, uint indent)const 27 | { 28 | for (vector::const_iterator i = childs.begin(), m = childs.end(); i != m; ++i) 29 | { 30 | this->printIndent(stream, indent + parent::indent); 31 | (*i)->print(stream, indent + parent::indent); 32 | stream << endl; 33 | } 34 | } 35 | 36 | // interface_content -> interface_content function_declare 37 | bool Parser::reduceInterfaceContent2Size() 38 | { 39 | #ifdef _DEBUG 40 | TRY_CAST(SyntaxTree_InterfaceContentList*, syntaxTreeStack[1]); 41 | TRY_CAST(SyntaxTree_FunctionDeclare*, syntaxTreeStack.top()); 42 | #endif 43 | SyntaxTree_InterfaceContentList* pInterfaceContentList = dynamic_cast(syntaxTreeStack[1]); 44 | 45 | pInterfaceContentList->pushChild(syntaxTreeStack.top()); 46 | 47 | syntaxTreeStack.pop(); 48 | return true; 49 | } 50 | 51 | // interface_content -> function_declare 52 | bool Parser::reduceInterfaceContent1Size() 53 | { 54 | #ifdef _DEBUG 55 | TRY_CAST(SyntaxTree_FunctionDeclare*, syntaxTreeStack.top()); 56 | #endif 57 | SyntaxTree_InterfaceContentList* pInterfaceContentList = allocator::allocate(); 58 | construct(pInterfaceContentList); 59 | 60 | context.data.insert(pInterfaceContentList); 61 | 62 | pInterfaceContentList->pushChild(syntaxTreeStack.top()); 63 | 64 | syntaxTreeStack.pop(); 65 | syntaxTreeStack.push(pInterfaceContentList); 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_InterfaceContentList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/07 3 | created: 7:6:2013 11:18 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_InterfaceContentList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_InterfaceContentList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_INTERFACE_CONTENT_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_INTERFACE_CONTENT_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_InterfaceContentList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_InterfaceContentList(); 24 | virtual ~SyntaxTree_InterfaceContentList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_InterfaceContentList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_InterfaceContentList*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_InterfaceContentList*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Item.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/06 3 | created: 6:6:2013 14:47 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Item.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Item 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_GlobalFunction.h" 14 | #include "SyntaxTree_DeclareList.h" 15 | #include "SyntaxTree_Interface.h" 16 | #include "SyntaxTree_Call.h" 17 | #include "SyntaxTree_Item.h" 18 | 19 | namespace QLanguage 20 | { 21 | SyntaxTree_Item::SyntaxTree_Item(SyntaxTree_Base* pItem) : parent(sizeof(SyntaxTree_Item)), pItem(pItem) 22 | { 23 | } 24 | 25 | SyntaxTree_Item::~SyntaxTree_Item() 26 | { 27 | } 28 | 29 | void SyntaxTree_Item::print(ostream& stream, uint indent)const 30 | { 31 | pItem->print(stream, indent); 32 | } 33 | 34 | // item -> global_function_desc 35 | // item -> declare_desc ";" 36 | // item -> interface_desc 37 | // item -> class_desc 38 | bool Parser::reduceItem(ushort i) 39 | { 40 | #ifdef _DEBUG 41 | switch (i) 42 | { 43 | case ITEM_GLOBAL_FUNCTION_DESC: 44 | TRY_CAST(SyntaxTree_GlobalFunction*, syntaxTreeStack.top()); 45 | break; 46 | case ITEM_DECLARE_DESC: 47 | TRY_CAST(SyntaxTree_DeclareList*, syntaxTreeStack.top()); 48 | break; 49 | case ITEM_INTERFACE_DESC: 50 | TRY_CAST(SyntaxTree_Interface*, syntaxTreeStack.top()); 51 | break; 52 | case ITEM_CLASS_DESC: 53 | TRY_CAST(SyntaxTree_Call*, syntaxTreeStack.top()); 54 | break; 55 | } 56 | #endif 57 | SyntaxTree_Item* pItem = allocator::allocate(); 58 | construct(pItem, syntaxTreeStack.top()); 59 | 60 | context.data.insert(pItem); 61 | 62 | syntaxTreeStack.pop(); 63 | syntaxTreeStack.push(pItem); 64 | 65 | if (i == ITEM_DECLARE_DESC) shifts.pop(); 66 | 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Item.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/06 3 | created: 6:6:2013 14:42 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Item.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Item 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ITEM_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ITEM_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Item : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Item(SyntaxTree_Base* pItem); 24 | virtual ~SyntaxTree_Item(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_Item"; } 29 | 30 | inline virtual bool make(Parser* pParser) { return pItem->make(pParser); } 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_Item*, &x); 36 | #endif 37 | return *pItem == *dynamic_cast(&x)->pItem; 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_Item*, &x); 44 | #endif 45 | return *pItem != *dynamic_cast(&x)->pItem; 46 | } 47 | protected: 48 | SyntaxTree_Base* pItem; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ItemList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 10:38 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ItemList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ItemList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Item.h" 14 | #include "SyntaxTree_ItemList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_ItemList::SyntaxTree_ItemList() 19 | : parent(sizeof(SyntaxTree_ItemList)) 20 | { 21 | } 22 | 23 | SyntaxTree_ItemList::~SyntaxTree_ItemList() 24 | { 25 | } 26 | 27 | void SyntaxTree_ItemList::print(ostream& stream, uint indent)const 28 | { 29 | for (vector::const_iterator i = childs.begin(), m = childs.end(); i != m; ++i) 30 | { 31 | (*i)->print(stream, indent); 32 | stream << endl; 33 | } 34 | } 35 | 36 | bool SyntaxTree_ItemList::make(Parser* pParser) 37 | { 38 | for (vector::iterator i = childs.begin(), m = childs.end(); i != m; ++i) 39 | { 40 | if (!(*i)->make(pParser)) return false; 41 | } 42 | return true; 43 | } 44 | 45 | // item_list -> item_list item 46 | bool Parser::reduceItemList2Size() 47 | { 48 | #ifdef _DEBUG 49 | TRY_CAST(SyntaxTree_ItemList*, syntaxTreeStack[1]); 50 | TRY_CAST(SyntaxTree_Item*, syntaxTreeStack.top()); 51 | #endif 52 | SyntaxTree_ItemList* pStmtList = dynamic_cast(syntaxTreeStack[1]); 53 | 54 | pStmtList->pushChild(syntaxTreeStack.top()); 55 | 56 | context.data.insert(pStmtList); 57 | 58 | syntaxTreeStack.pop(); 59 | return true; 60 | } 61 | 62 | // item_list -> item 63 | bool Parser::reduceItemList1Size() 64 | { 65 | #ifdef _DEBUG 66 | TRY_CAST(SyntaxTree_Item*, syntaxTreeStack.top()); 67 | #endif 68 | SyntaxTree_ItemList* pStmtList = allocator::allocate(); 69 | construct(pStmtList); 70 | 71 | pStmtList->pushChild(syntaxTreeStack.top()); 72 | 73 | context.data.insert(pStmtList); 74 | 75 | syntaxTreeStack.pop(); 76 | syntaxTreeStack.push(pStmtList); 77 | return true; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ItemList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 10:36 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ItemList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ItemList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_ITEM_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_ITEM_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ItemList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ItemList(); 24 | virtual ~SyntaxTree_ItemList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ItemList"; } 29 | 30 | virtual bool make(Parser* pParser); 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_ItemList*, &x); 36 | #endif 37 | return childs.size() == x.childs.size(); 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_ItemList*, &x); 44 | #endif 45 | return childs.size() != x.childs.size(); 46 | } 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_MemberList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 11:17 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_MemberList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_MemberList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_MEMBER_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_MEMBER_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_MemberList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_MemberList(); 24 | virtual ~SyntaxTree_MemberList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_MemberList"; } 29 | 30 | virtual const HASH_KEY_TYPE hash()const; 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_MemberList*, &x); 36 | #endif 37 | return childs.size() == x.childs.size(); 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_MemberList*, &x); 44 | #endif 45 | return childs.size() != x.childs.size(); 46 | } 47 | public: 48 | const string name()const; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Name.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 11:27 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Name.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Name 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "SyntaxTree_Name.h" 13 | 14 | namespace QLanguage 15 | { 16 | SyntaxTree_Name::SyntaxTree_Name(const string& name) 17 | : parent(sizeof(SyntaxTree_Name)) 18 | , name(name) 19 | { 20 | } 21 | 22 | SyntaxTree_Name::~SyntaxTree_Name() 23 | { 24 | } 25 | 26 | void SyntaxTree_Name::print(ostream& stream, uint indent)const 27 | { 28 | stream << name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Name.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 11:25 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Name.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Name 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_NAME_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_NAME_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Name : public SyntaxTree_Base 20 | { 21 | friend class SyntaxTree_MemberList; 22 | 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_Name(const string& name); 26 | virtual ~SyntaxTree_Name(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_Name"; } 31 | 32 | inline virtual const HASH_KEY_TYPE hash()const { return ::hash()(name); } 33 | 34 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 35 | { 36 | #ifdef _DEBUG 37 | TRY_CAST(const SyntaxTree_Name*, &x); 38 | #endif 39 | return name == dynamic_cast(&x)->name; 40 | } 41 | 42 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 43 | { 44 | #ifdef _DEBUG 45 | TRY_CAST(const SyntaxTree_Name*, &x); 46 | #endif 47 | return name != dynamic_cast(&x)->name; 48 | } 49 | protected: 50 | string name; 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ParamterList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/05 3 | created: 5:6:2013 15:02 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ParamterList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ParamterList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_PARAMTER_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_PARAMTER_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ParamterList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ParamterList(); 24 | virtual ~SyntaxTree_ParamterList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ParamterList"; } 29 | 30 | // hash = Σhash(childs[i]) << (childs.size() - i) 31 | virtual const HASH_KEY_TYPE hash()const; 32 | 33 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 34 | { 35 | #ifdef _DEBUG 36 | TRY_CAST(const SyntaxTree_ParamterList*, &x); 37 | #endif 38 | if (childs.size() != x.childs.size()) return false; 39 | for (vector::const_iterator i = childs.begin(), m = childs.end(), j = x.childs.begin(); i != m; ++i) 40 | { 41 | if (**i != **j) return false; 42 | } 43 | return true; 44 | } 45 | 46 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 47 | { 48 | #ifdef _DEBUG 49 | TRY_CAST(const SyntaxTree_ParamterList*, &x); 50 | #endif 51 | if (childs.size() != x.childs.size()) return true; 52 | for (vector::const_iterator i = childs.begin(), m = childs.end(), j = x.childs.begin(); i != m; ++i) 53 | { 54 | if (**i != **j) return true; 55 | } 56 | return false; 57 | } 58 | }; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Return.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/01 3 | created: 1:6:2013 20:26 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Return.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Return 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_RETURN_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_RETURN_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Return : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_Return(SyntaxTree_Base* pContent); 24 | virtual ~SyntaxTree_Return(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_Return"; } 29 | 30 | bool virtual make(Parser* pParser); 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_Return*, &x); 36 | #endif 37 | return parent::checkEqual(pContent, dynamic_cast(&x)->pContent); 38 | } 39 | 40 | inline virtual const bool operator !=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_Return*, &x); 44 | #endif 45 | return parent::checkNotEqual(pContent, dynamic_cast(&x)->pContent); 46 | } 47 | protected: 48 | SyntaxTree_Base* pContent; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Stmt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/20 3 | created: 20:6:2013 22:13 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Stmt.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Stmt 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_STMT_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_STMT_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_Stmt : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | enum Type 24 | { 25 | Assign, 26 | Call, 27 | Declare, 28 | Do, 29 | If, 30 | For, 31 | While, 32 | Switch, 33 | Break, 34 | Continue, 35 | Return 36 | }; 37 | public: 38 | SyntaxTree_Stmt(bool bSemicolon, SyntaxTree_Base* pStmt, Type type); 39 | virtual ~SyntaxTree_Stmt(); 40 | 41 | virtual void print(ostream& stream, uint indent)const; 42 | 43 | inline virtual string type()const { return "SyntaxTree_Stmt"; } 44 | 45 | inline virtual bool make(Parser* pParser) { return pStmt->make(pParser); } 46 | 47 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 48 | { 49 | #ifdef _DEBUG 50 | TRY_CAST(const SyntaxTree_Stmt*, &x); 51 | #endif 52 | return *pStmt == *dynamic_cast(&x)->pStmt; 53 | } 54 | 55 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 56 | { 57 | #ifdef _DEBUG 58 | TRY_CAST(const SyntaxTree_Stmt*, &x); 59 | #endif 60 | return *pStmt != *dynamic_cast(&x)->pStmt; 61 | } 62 | protected: 63 | bool bSemicolon; 64 | SyntaxTree_Base* pStmt; 65 | Type _type; 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_StmtList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/01 3 | created: 1:6:2013 21:07 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_StmtList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_StmtList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_STMT_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_STMT_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_StmtList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_StmtList(); 24 | virtual ~SyntaxTree_StmtList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_StmtList"; } 29 | 30 | virtual bool make(Parser* pParser); 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_StmtList*, &x); 36 | #endif 37 | return childs.size() == x.childs.size(); 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_StmtList*, &x); 44 | #endif 45 | return childs.size() != x.childs.size(); 46 | } 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Switch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:13 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Switch.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Switch 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Switch.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_Switch::SyntaxTree_Switch(const SyntaxTree_Exp& exp, const SyntaxTree_SwitchContentList& contentList) 18 | : parent(sizeof(SyntaxTree_Switch)) 19 | , exp(exp) 20 | , contentList(contentList) 21 | { 22 | } 23 | 24 | SyntaxTree_Switch::~SyntaxTree_Switch() 25 | { 26 | } 27 | 28 | void SyntaxTree_Switch::print(ostream& stream, uint indent)const 29 | { 30 | stream << "switch ("; 31 | exp.print(stream, indent); 32 | stream << ") {" << endl; 33 | contentList.print(stream, indent); 34 | this->printIndent(stream, indent); 35 | stream << '}'; 36 | } 37 | 38 | // switch_desc -> "switch" "(" exp ")" "{" switch_content_list "}" 39 | bool Parser::reduceSwitch() 40 | { 41 | #ifdef _DEBUG 42 | TRY_CAST(SyntaxTree_Exp*, syntaxTreeStack[1]); 43 | TRY_CAST(SyntaxTree_SwitchContentList*, syntaxTreeStack.top()); 44 | #endif 45 | shifts.pop(); 46 | shifts.pop(); 47 | shifts.pop(); 48 | shifts.pop(); 49 | shifts.pop(); 50 | 51 | SyntaxTree_Switch* pSwitch = allocator::allocate(); 52 | construct(pSwitch, dynamic_cast(*syntaxTreeStack[1]), dynamic_cast(*syntaxTreeStack.top())); 53 | 54 | context.data.insert(pSwitch); 55 | 56 | syntaxTreeStack.pop(); 57 | syntaxTreeStack.pop(); 58 | syntaxTreeStack.push(pSwitch); 59 | 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Switch.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 15:07 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Switch.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Switch 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_SWITCH_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_SWITCH_H_ 14 | 15 | #include "SyntaxTree_Exp.h" 16 | #include "SyntaxTree_SwitchContentList.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_Switch : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_Switch(const SyntaxTree_Exp& exp, const SyntaxTree_SwitchContentList& contentList); 26 | virtual ~SyntaxTree_Switch(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_Switch"; } 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_Switch*, &x); 36 | #endif 37 | return exp == dynamic_cast(&x)->exp && 38 | contentList == dynamic_cast(&x)->contentList; 39 | } 40 | 41 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 42 | { 43 | #ifdef _DEBUG 44 | TRY_CAST(const SyntaxTree_Switch*, &x); 45 | #endif 46 | return exp != dynamic_cast(&x)->exp || 47 | contentList != dynamic_cast(&x)->contentList; 48 | } 49 | protected: 50 | const SyntaxTree_Exp& exp; 51 | const SyntaxTree_SwitchContentList& contentList; 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_SwitchContent.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 14:24 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_SwitchContent.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_SwitchContent 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_SWITCH_CONTENT_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_SWITCH_CONTENT_H_ 14 | 15 | #include "SyntaxTree_Exp.h" 16 | #include "SyntaxTree_StmtList.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_SwitchContent : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_SwitchContent(SyntaxTree_Exp* pExp, const SyntaxTree_StmtList& stmtList); 26 | SyntaxTree_SwitchContent(const SyntaxTree_StmtList& stmtList); 27 | virtual ~SyntaxTree_SwitchContent(); 28 | 29 | virtual void print(ostream& stream, uint indent)const; 30 | 31 | inline virtual string type()const { return "SyntaxTree_SwitchContent"; } 32 | 33 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 34 | { 35 | #ifdef _DEBUG 36 | TRY_CAST(const SyntaxTree_SwitchContent*, &x); 37 | #endif 38 | return parent::checkEqual(pExp, dynamic_cast(&x)->pExp) && 39 | stmtList == dynamic_cast(&x)->stmtList; 40 | } 41 | 42 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 43 | { 44 | #ifdef _DEBUG 45 | TRY_CAST(const SyntaxTree_SwitchContent*, &x); 46 | #endif 47 | return parent::checkNotEqual(pExp, dynamic_cast(&x)->pExp) || 48 | stmtList != dynamic_cast(&x)->stmtList; 49 | } 50 | protected: 51 | SyntaxTree_Exp* pExp; 52 | const SyntaxTree_StmtList& stmtList; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_SwitchContentList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 14:56 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_SwitchContentList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_SwitchContentList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_SwitchContent.h" 14 | #include "SyntaxTree_SwitchContentList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_SwitchContentList::SyntaxTree_SwitchContentList() 19 | : parent(sizeof(SyntaxTree_SwitchContentList)) 20 | { 21 | } 22 | 23 | SyntaxTree_SwitchContentList::~SyntaxTree_SwitchContentList() 24 | { 25 | } 26 | 27 | void SyntaxTree_SwitchContentList::print(ostream& stream, uint indent)const 28 | { 29 | for (vector::const_iterator i = childs.begin(), m = childs.end(); i != m; ++i) 30 | { 31 | this->printIndent(stream, indent); 32 | (*i)->print(stream, indent); 33 | } 34 | } 35 | 36 | // switch_content_list -> switch_content_list switch_content 37 | bool Parser::reduceSwitchContentList2Size() 38 | { 39 | #ifdef _DEBUG 40 | TRY_CAST(SyntaxTree_SwitchContentList*, syntaxTreeStack[1]); 41 | TRY_CAST(SyntaxTree_SwitchContent*, syntaxTreeStack.top()); 42 | #endif 43 | SyntaxTree_SwitchContentList* pSwitchContentList = dynamic_cast(syntaxTreeStack[1]); 44 | 45 | pSwitchContentList->pushChild(syntaxTreeStack.top()); 46 | 47 | syntaxTreeStack.pop(); 48 | 49 | return true; 50 | } 51 | 52 | // switch_content_list -> switch_content 53 | bool Parser::reduceSwitchContentList1Size() 54 | { 55 | #ifdef _DEBUG 56 | TRY_CAST(SyntaxTree_SwitchContent*, syntaxTreeStack.top()); 57 | #endif 58 | SyntaxTree_SwitchContentList* pSwitchContentList = allocator::allocate(); 59 | construct(pSwitchContentList); 60 | 61 | context.data.insert(pSwitchContentList); 62 | 63 | pSwitchContentList->pushChild(syntaxTreeStack.top()); 64 | 65 | syntaxTreeStack.pop(); 66 | syntaxTreeStack.push(pSwitchContentList); 67 | 68 | return true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_SwitchContentList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/07 3 | created: 7:7:2013 14:52 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_SwitchContentList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_SwitchContentList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_SWITCH_CONTENT_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_SWITCH_CONTENT_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_SwitchContentList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_SwitchContentList(); 24 | virtual ~SyntaxTree_SwitchContentList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_SwitchContentList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_SwitchContentList*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_SwitchContentList*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Template.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/01 3 | created: 1:7:2013 22:06 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Template.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Template 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_TEMPLATE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_TEMPLATE_H_ 14 | 15 | #include "SyntaxTree_TemplateList.h" 16 | #include "SyntaxTree_Base.h" 17 | 18 | namespace QLanguage 19 | { 20 | class SyntaxTree_Template : public SyntaxTree_Base 21 | { 22 | typedef SyntaxTree_Base parent; 23 | public: 24 | SyntaxTree_Template(SyntaxTree_TemplateList* pTemplateList); 25 | SyntaxTree_Template(); 26 | virtual ~SyntaxTree_Template(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_Template"; } 31 | 32 | virtual const HASH_KEY_TYPE hash()const; 33 | 34 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 35 | { 36 | #ifdef _DEBUG 37 | TRY_CAST(const SyntaxTree_Template*, &x); 38 | #endif 39 | return ((pTemplateList && dynamic_cast(&x)->pTemplateList && *pTemplateList == *dynamic_cast(&x)->pTemplateList) || 40 | (pTemplateList == NULL && dynamic_cast(&x)->pTemplateList == NULL)); 41 | } 42 | 43 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 44 | { 45 | #ifdef _DEBUG 46 | TRY_CAST(const SyntaxTree_Template*, &x); 47 | #endif 48 | return ((pTemplateList && (dynamic_cast(&x)->pTemplateList == NULL || *pTemplateList != *dynamic_cast(&x)->pTemplateList)) || 49 | (pTemplateList == NULL && dynamic_cast(&x)->pTemplateList)); 50 | } 51 | protected: 52 | SyntaxTree_TemplateList* pTemplateList; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_TemplateItem.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/01 3 | created: 1:7:2013 21:35 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_TemplateItem.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_TemplateItem 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_TemplateItem.h" 14 | 15 | namespace QLanguage 16 | { 17 | SyntaxTree_TemplateItem::SyntaxTree_TemplateItem(const string& name) 18 | : parent(sizeof(SyntaxTree_TemplateItem)) 19 | , pType(NULL) 20 | , _type(_TypeName) 21 | , name(name) 22 | { 23 | } 24 | 25 | SyntaxTree_TemplateItem::SyntaxTree_TemplateItem(SyntaxTree_Type* pType, const string& name) 26 | : parent(sizeof(SyntaxTree_TemplateItem)) 27 | , pType(pType) 28 | , _type(_Type) 29 | , name(name) 30 | { 31 | } 32 | 33 | SyntaxTree_TemplateItem::~SyntaxTree_TemplateItem() 34 | { 35 | } 36 | 37 | void SyntaxTree_TemplateItem::print(ostream& stream, uint indent)const 38 | { 39 | switch (_type) 40 | { 41 | case _TypeName: 42 | stream << "typename " << name; 43 | break; 44 | case _Type: 45 | pType->print(stream, indent); 46 | stream << ' ' << name; 47 | break; 48 | } 49 | } 50 | 51 | // template_item -> "typename" "{Letter}" 52 | bool Parser::reduceTemplateItemWithTypeName() 53 | { 54 | SyntaxTree_TemplateItem* pTemplateItem = allocator::allocate(); 55 | construct(pTemplateItem, shifts.top()); 56 | 57 | context.data.insert(pTemplateItem); 58 | 59 | syntaxTreeStack.push(pTemplateItem); 60 | 61 | shifts.pop(); 62 | shifts.pop(); 63 | 64 | return true; 65 | } 66 | 67 | // template_item -> type_desc "{Letter}" 68 | bool Parser::reduceTemplateItemWithType() 69 | { 70 | SyntaxTree_TemplateItem* pTemplateItem = allocator::allocate(); 71 | construct(pTemplateItem, dynamic_cast(syntaxTreeStack.top()), shifts.top()); 72 | 73 | context.data.insert(pTemplateItem); 74 | 75 | syntaxTreeStack.pop(); 76 | syntaxTreeStack.push(pTemplateItem); 77 | 78 | shifts.pop(); 79 | 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_TemplateItem.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/01 3 | created: 1:7:2013 21:13 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_TemplateItem.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_TemplateItem 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_TEMPLATE_ITEM_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_TEMPLATE_ITEM_H_ 14 | 15 | #include "SyntaxTree_Type.h" 16 | #include "SyntaxTree_Base.h" 17 | 18 | namespace QLanguage 19 | { 20 | class SyntaxTree_TemplateItem : public SyntaxTree_Base 21 | { 22 | typedef SyntaxTree_Base parent; 23 | public: 24 | enum Type 25 | { 26 | _TypeName, 27 | _Type 28 | }; 29 | public: 30 | SyntaxTree_TemplateItem(const string& name); 31 | SyntaxTree_TemplateItem(SyntaxTree_Type* pType, const string& name); 32 | virtual ~SyntaxTree_TemplateItem(); 33 | 34 | virtual void print(ostream& stream, uint indent)const; 35 | 36 | inline virtual string type()const { return "SyntaxTree_TemplateItem"; } 37 | 38 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_TemplateItem*, &x); 42 | #endif 43 | if (_type != dynamic_cast(&x)->_type) return false; 44 | return ((pType && dynamic_cast(&x)->pType && *pType == *dynamic_cast(&x)->pType) || 45 | (pType == NULL && dynamic_cast(&x)->pType == NULL)); 46 | } 47 | 48 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 49 | { 50 | #ifdef _DEBUG 51 | TRY_CAST(const SyntaxTree_TemplateItem*, &x); 52 | #endif 53 | if (_type != dynamic_cast(&x)->_type) return true; 54 | return ((pType && (dynamic_cast(&x)->pType == NULL || *pType != *dynamic_cast(&x)->pType)) || 55 | (pType == NULL && dynamic_cast(&x)->pType != NULL)); 56 | } 57 | protected: 58 | SyntaxTree_Type* pType; 59 | Type _type; 60 | string name; 61 | }; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_TemplateList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/01 3 | created: 1:7:2013 21:49 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_TemplateList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_TemplateList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_TEMPLATE_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_TEMPLATE_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_TemplateList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_TemplateList(); 24 | virtual ~SyntaxTree_TemplateList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_TemplateList"; } 29 | 30 | virtual const HASH_KEY_TYPE hash()const; 31 | 32 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 33 | { 34 | #ifdef _DEBUG 35 | TRY_CAST(const SyntaxTree_TemplateList*, &x); 36 | #endif 37 | return childs.size() == x.childs.size(); 38 | } 39 | 40 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(const SyntaxTree_TemplateList*, &x); 44 | #endif 45 | return childs.size() != x.childs.size(); 46 | } 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ValueList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 13:45 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ValueList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ValueList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Exp.h" 14 | #include "SyntaxTree_ValueList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_ValueList::SyntaxTree_ValueList() : parent(sizeof(SyntaxTree_ValueList)) 19 | { 20 | } 21 | 22 | SyntaxTree_ValueList::~SyntaxTree_ValueList() 23 | { 24 | } 25 | 26 | void SyntaxTree_ValueList::print(ostream& stream, uint indent)const 27 | { 28 | if (childs.size()) 29 | { 30 | childs[0]->print(stream, indent); 31 | for (size_t i = 1, m = childs.size(); i < m; ++i) 32 | { 33 | stream << ", "; 34 | childs[i]->print(stream, indent); 35 | } 36 | } 37 | } 38 | 39 | // value_list -> value_list "," exp 40 | bool Parser::reduceValueList2Size() 41 | { 42 | #ifdef _DEBUG 43 | TRY_CAST(SyntaxTree_ValueList*, syntaxTreeStack[1]); 44 | TRY_CAST(SyntaxTree_Exp*, syntaxTreeStack.top()); 45 | #endif 46 | SyntaxTree_ValueList* pValueList = dynamic_cast(syntaxTreeStack[1]); 47 | 48 | pValueList->pushChild(syntaxTreeStack.top()); 49 | 50 | syntaxTreeStack.pop(); 51 | 52 | shifts.pop(); 53 | 54 | return true; 55 | } 56 | 57 | // value_list -> exp 58 | bool Parser::reduceValueList1Size() 59 | { 60 | #ifdef _DEBUG 61 | TRY_CAST(SyntaxTree_Exp*, syntaxTreeStack.top()); 62 | #endif 63 | SyntaxTree_ValueList* pValueList = allocator::allocate(); 64 | construct(pValueList); 65 | 66 | context.data.insert(pValueList); 67 | 68 | pValueList->pushChild(syntaxTreeStack.top()); 69 | 70 | syntaxTreeStack.pop(); 71 | syntaxTreeStack.push(pValueList); 72 | 73 | return true; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ValueList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/03 3 | created: 3:6:2013 13:43 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ValueList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ValueList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_VALUE_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_VALUE_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ValueList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ValueList(); 24 | virtual ~SyntaxTree_ValueList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ValueList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_ValueList*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_ValueList*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Values.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 11:28 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Values.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Values 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Value.h" 14 | #include "SyntaxTree_Values.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_Values::SyntaxTree_Values(const SyntaxTree_ValuesList& valuesList) 19 | : parent(sizeof(SyntaxTree_Values)) 20 | , valuesList(valuesList) 21 | { 22 | } 23 | 24 | SyntaxTree_Values::~SyntaxTree_Values() 25 | { 26 | } 27 | 28 | void SyntaxTree_Values::print(ostream& stream, uint indent)const 29 | { 30 | stream << '{'; 31 | valuesList.print(stream, indent); 32 | stream << '}'; 33 | } 34 | 35 | // values -> "{" values_list "}" 36 | bool Parser::reduceValuesTop() 37 | { 38 | #ifdef _DEBUG 39 | TRY_CAST(SyntaxTree_ValuesList*, syntaxTreeStack.top()); 40 | #endif 41 | shifts.pop(); 42 | shifts.pop(); 43 | 44 | SyntaxTree_Values* pValues = allocator::allocate(); 45 | construct(pValues, dynamic_cast(*syntaxTreeStack.top())); 46 | 47 | context.data.insert(pValues); 48 | 49 | syntaxTreeStack.pop(); 50 | syntaxTreeStack.push(pValues); 51 | 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_Values.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/29 3 | created: 29:6:2013 11:28 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_Values.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_Values 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_VALUES_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_VALUES_H_ 14 | 15 | #include "SyntaxTree_ValuesList.h" 16 | #include "SyntaxTree_Base.h" 17 | 18 | namespace QLanguage 19 | { 20 | class SyntaxTree_Values : public SyntaxTree_Base 21 | { 22 | typedef SyntaxTree_Base parent; 23 | public: 24 | SyntaxTree_Values(const SyntaxTree_ValuesList& valuesList); 25 | virtual ~SyntaxTree_Values(); 26 | 27 | virtual void print(ostream& stream, uint indent)const; 28 | 29 | inline virtual string type()const { return "SyntaxTree_Values"; } 30 | 31 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 32 | { 33 | #ifdef _DEBUG 34 | TRY_CAST(const SyntaxTree_Values*, &x); 35 | #endif 36 | return valuesList == dynamic_cast(&x)->valuesList; 37 | } 38 | 39 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 40 | { 41 | #ifdef _DEBUG 42 | TRY_CAST(const SyntaxTree_Values*, &x); 43 | #endif 44 | return valuesList != dynamic_cast(&x)->valuesList; 45 | } 46 | protected: 47 | const SyntaxTree_ValuesList& valuesList; 48 | }; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ValuesList.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/04 3 | created: 4:7:2013 23:38 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ValuesList.cpp 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ValuesList 7 | file ext: cpp 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #include "../Parser.h" 13 | #include "SyntaxTree_Value.h" 14 | #include "SyntaxTree_ValuesList.h" 15 | 16 | namespace QLanguage 17 | { 18 | SyntaxTree_ValuesList::SyntaxTree_ValuesList() 19 | : parent(sizeof(SyntaxTree_ValuesList)) 20 | { 21 | } 22 | 23 | SyntaxTree_ValuesList::~SyntaxTree_ValuesList() 24 | { 25 | } 26 | 27 | void SyntaxTree_ValuesList::print(ostream& stream, uint indent)const 28 | { 29 | if (childs.size()) 30 | { 31 | childs[0]->print(stream, indent); 32 | for (size_t i = 1, m = childs.size(); i < m; ++i) 33 | { 34 | stream << ", "; 35 | childs[i]->print(stream, indent); 36 | } 37 | } 38 | } 39 | 40 | // values_list -> values_list "," value_desc 41 | bool Parser::reduceValuesList2Size() 42 | { 43 | #ifdef _DEBUG 44 | TRY_CAST(SyntaxTree_ValuesList*, syntaxTreeStack[1]); 45 | TRY_CAST(SyntaxTree_Value*, syntaxTreeStack.top()); 46 | #endif 47 | shifts.pop(); 48 | 49 | SyntaxTree_ValuesList* pValues = dynamic_cast(syntaxTreeStack[1]); 50 | 51 | pValues->pushChild(syntaxTreeStack.top()); 52 | 53 | syntaxTreeStack.pop(); 54 | 55 | return true; 56 | } 57 | 58 | // values_list -> value_desc 59 | bool Parser::reduceValuesList1Size() 60 | { 61 | #ifdef _DEBUG 62 | TRY_CAST(SyntaxTree_Value*, syntaxTreeStack.top()); 63 | #endif 64 | SyntaxTree_ValuesList* pValues = allocator::allocate(); 65 | construct(pValues); 66 | 67 | context.data.insert(pValues); 68 | 69 | pValues->pushChild(syntaxTreeStack.top()); 70 | 71 | syntaxTreeStack.pop(); 72 | syntaxTreeStack.push(pValues); 73 | 74 | return true; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_ValuesList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/07/04 3 | created: 4:7:2013 23:29 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_ValuesList.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_ValuesList 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_VALUES_LIST_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_VALUES_LIST_H_ 14 | 15 | #include "SyntaxTree_Base.h" 16 | 17 | namespace QLanguage 18 | { 19 | class SyntaxTree_ValuesList : public SyntaxTree_Base 20 | { 21 | typedef SyntaxTree_Base parent; 22 | public: 23 | SyntaxTree_ValuesList(); 24 | virtual ~SyntaxTree_ValuesList(); 25 | 26 | virtual void print(ostream& stream, uint indent)const; 27 | 28 | inline virtual string type()const { return "SyntaxTree_ValuesList"; } 29 | 30 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 31 | { 32 | #ifdef _DEBUG 33 | TRY_CAST(const SyntaxTree_ValuesList*, &x); 34 | #endif 35 | return childs.size() == x.childs.size(); 36 | } 37 | 38 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 39 | { 40 | #ifdef _DEBUG 41 | TRY_CAST(const SyntaxTree_ValuesList*, &x); 42 | #endif 43 | return childs.size() != x.childs.size(); 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Source/QLanguage/Parser/SyntaxTree/SyntaxTree_While.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/06/20 3 | created: 20:6:2013 22:13 4 | filename: \QLanguage\Parser\SyntaxTree\SyntaxTree_While.h 5 | file path: \QLanguage\Parser\SyntaxTree 6 | file base: SyntaxTree_While 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_SYNTAX_TREE_WHILE_H_ 13 | #define _QLANGUAGE_SYNTAX_TREE_WHILE_H_ 14 | 15 | #include "SyntaxTree_Exp.h" 16 | #include "SyntaxTree_Block.h" 17 | #include "SyntaxTree_Base.h" 18 | 19 | namespace QLanguage 20 | { 21 | class SyntaxTree_While : public SyntaxTree_Base 22 | { 23 | typedef SyntaxTree_Base parent; 24 | public: 25 | SyntaxTree_While(SyntaxTree_Exp& exp, SyntaxTree_Block& block); 26 | virtual ~SyntaxTree_While(); 27 | 28 | virtual void print(ostream& stream, uint indent)const; 29 | 30 | inline virtual string type()const { return "SyntaxTree_While"; } 31 | 32 | virtual bool make(Parser *pParser); 33 | 34 | inline virtual const bool operator==(const SyntaxTree_Base& x)const 35 | { 36 | #ifdef _DEBUG 37 | TRY_CAST(const SyntaxTree_While*, &x); 38 | #endif 39 | return exp == dynamic_cast(&x)->exp || 40 | block == dynamic_cast(&x)->block; 41 | } 42 | 43 | inline virtual const bool operator!=(const SyntaxTree_Base& x)const 44 | { 45 | #ifdef _DEBUG 46 | TRY_CAST(const SyntaxTree_While*, &x); 47 | #endif 48 | return exp != dynamic_cast(&x)->exp || 49 | block != dynamic_cast(&x)->block; 50 | } 51 | protected: 52 | SyntaxTree_Exp& exp; 53 | SyntaxTree_Block& block; 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Source/QLanguage/QLanguage.x64.ParserTable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/QLanguage/QLanguage.x64.ParserTable -------------------------------------------------------------------------------- /Source/QLanguage/QLanguage.x86.ParserTable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/QLanguage/QLanguage.x86.ParserTable -------------------------------------------------------------------------------- /Source/QLanguage/VirtualMachine/opcodes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Source/QLanguage/VirtualMachine/opcodes.cpp -------------------------------------------------------------------------------- /Source/QParserGenerator/Parser/Parser.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2013/05/05 3 | created: 5:5:2013 21:03 4 | filename: \QParserGenerator\Parser\Parser.h 5 | file path: \QParserGenerator\Parser 6 | file base: Parser 7 | file ext: h 8 | author: lwch 9 | 10 | purpose: 11 | *********************************************************************/ 12 | #ifndef _QLANGUAGE_GENERATOR_PARSER_H_ 13 | #define _QLANGUAGE_GENERATOR_PARSER_H_ 14 | 15 | #include "../../QLanguage/Parser/BasicParser.h" 16 | #include "../../QLanguage/Parser/LALR1.h" 17 | 18 | namespace QLanguage 19 | { 20 | class Parser : public BasicParser 21 | { 22 | public: 23 | Parser(const vector& productions, const string& parserTablePath); 24 | virtual ~Parser(); 25 | 26 | virtual bool shift(const string& s); 27 | virtual bool reduce(ushort i); 28 | protected: 29 | bool reduceAll(); 30 | bool reduceStrings1(); 31 | bool reduceStrings2(); 32 | bool reduceVs1(); 33 | bool reduceVs2(); 34 | bool reduceVs3(); 35 | bool reduceVs4(); 36 | bool reduceOption(); 37 | bool reduceRight1(); 38 | bool reduceRight2(); 39 | bool reduceRight3(); 40 | bool reduceRight4(); 41 | bool reduceSomeRight1(); 42 | bool reduceSomeRight2(); 43 | bool reduceProduction(); 44 | bool reduceToken(); 45 | 46 | long indexOfVN(const string& s); 47 | long indexOfVT(const string& s); 48 | protected: 49 | LALR1 lalr1; 50 | vector productions; 51 | vector shifts; 52 | vector vs; 53 | vector > oneProductionRights; 54 | vector > rights; 55 | regex::Rule::Context context; 56 | vector > vns; 57 | vector > vts; 58 | Production::Item itemString; 59 | Production::Item itemLetter; 60 | string parserTablePath; 61 | #ifdef _DEBUG 62 | fstream stream; 63 | #endif 64 | }; 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /Source/WordSegmentation/Common/LexicographicTreeNode.h: -------------------------------------------------------------------------------- 1 | #ifndef _WORDSEGMENTATION_NODE_H_ 2 | #define _WORDSEGMENTATION_NODE_H_ 3 | 4 | #include "../../QCore/Library/allocator.h" 5 | #include "../../QCore/Library/map.h" 6 | 7 | namespace QLanguage 8 | { 9 | using namespace Library; 10 | 11 | namespace WordSegmentation 12 | { 13 | template 14 | struct LexicographicTreeNode 15 | { 16 | public: 17 | typedef allocator> Alloc; 18 | public: 19 | LexicographicTreeNode(LexicographicTreeNode* parent, const T& v) : mpParent(parent), value(v), mbEnd(false) 20 | { 21 | } 22 | 23 | virtual ~LexicographicTreeNode() 24 | { 25 | } 26 | public: 27 | T value; 28 | bool mbEnd; 29 | LexicographicTreeNode* mpParent; 30 | map*> mChilds; 31 | }; 32 | } 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /Source/check_bits.cmake: -------------------------------------------------------------------------------- 1 | IF(CMAKE_SIZEOF_VOID_P EQUAL 8) 2 | ADD_DEFINITIONS(-DX64) 3 | SET(X64 TRUE) 4 | ELSE() 5 | ADD_DEFINITIONS(-DX86) 6 | SET(X86 TRUE) 7 | ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) -------------------------------------------------------------------------------- /Source/warning2error.cmake: -------------------------------------------------------------------------------- 1 | IF(NOT MSVC) 2 | SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") 3 | IF(MINGW AND WIN32) 4 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static") 5 | ADD_DEFINITIONS(-DWIN32) 6 | ELSE() 7 | ADD_DEFINITIONS(-Dunix) 8 | ENDIF() 9 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -std=c++0x") 10 | ADD_DEFINITIONS(-DGNUC) 11 | ELSE() 12 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") 13 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) 14 | ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS) 15 | ADD_DEFINITIONS(-DMSVC) 16 | ENDIF(NOT MSVC) 17 | -------------------------------------------------------------------------------- /Tools/QLanguage/DEB/control: -------------------------------------------------------------------------------- 1 | Package: QLanguage 2 | Version: 1.0 3 | Section: Development/Tools 4 | Priority: optional 5 | Architecture: os 6 | Maintainer: lwch 7 | Description: QLanguge Compiler 8 | -------------------------------------------------------------------------------- /Tools/QLanguage/DEB/makeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./../../makebinary.sh 3 | ./makedeb.sh $1 4 | -------------------------------------------------------------------------------- /Tools/QLanguage/DEB/makedeb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ x$1 != x ]; then 4 | if [ $1 = "i386" ] || [ $1 = "amd64" ]; then 5 | DEB_PATH=~/QLanguage_Deb_$1/ 6 | BINARY_PATH=~/QLanguage/Source/QLanguage/QLanguage 7 | 8 | # make debian path 9 | if [ -d "$DEB_PATH" ]; then 10 | rm -fr $DEB_PATH 11 | fi 12 | mkdir -p $DEB_PATH/./DEBIAN/ 13 | mkdir -p $DEB_PATH/./usr/local/bin/ 14 | #cp control $DEB_PATH/./DEBIAN/ 15 | cp $BINARY_PATH $DEB_PATH/./usr/local/bin/ 16 | 17 | # change archiecture 18 | sed "s/os/$1/" control > $DEB_PATH/./DEBIAN/control 19 | 20 | dpkg -b $DEB_PATH 21 | else 22 | echo "Unknow archiecture type(i386 or amd64)" 23 | fi 24 | else 25 | echo "Please input architecture(i386 or amd64)" 26 | fi 27 | -------------------------------------------------------------------------------- /Tools/QLanguage/RPM/QLanguage.spec: -------------------------------------------------------------------------------- 1 | Name: QLanguage 2 | Version: 1.0 3 | Release: 1%{?dist} 4 | Summary: QLanguage Compiler 5 | 6 | Group: Development/Tools 7 | License: GPL 8 | URL: http://code.google.com/p/qlanguage 9 | Source: QLanguage.tar.gz 10 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 11 | 12 | BuildRequires: gcc-c++ cmake make 13 | 14 | %description 15 | QLanguage Compiler 16 | 17 | %prep 18 | %setup -q -n %{name} 19 | 20 | %build 21 | cd Source/ 22 | cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release 23 | make 24 | 25 | 26 | %install 27 | rm -rf %{buildroot} 28 | cd Source/ 29 | make install DESTDIR=%{buildroot} 30 | 31 | 32 | %clean 33 | rm -rf %{buildroot} 34 | 35 | 36 | %files 37 | %defattr(-,root,root,-) 38 | /usr/local/bin/QLanguage 39 | /usr/local/bin/QLanguage.os.ParserTable 40 | 41 | %changelog 42 | 43 | -------------------------------------------------------------------------------- /Tools/QLanguage/RPM/rpm_package.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | if [ x$1 != x ]; then 4 | if [ $1 = "i386" ] || [ $1 = "amd64" ]; then 5 | if [ $1 = "i386" ]; then 6 | PLATFORM=x86 7 | else 8 | PLATFORM=x64 9 | fi 10 | CURRENT_PATH=~/rpmbuild/SPECS/ 11 | SOURCE_PATH=~/QLanguage_GitHub/ 12 | DEST_PATH=QLanguage/ 13 | COMPRESS_PATH=$CURRENT_PATH/QLanguage.tar.gz # always change .spec 14 | RPMBUILD_COMPRESS_PATH=~/rpmbuild/SOURCES/QLanguage.tar.gz 15 | SPEC_PATH=$CURRENT_PATH/QLanguage.$PLATFORM.spec 16 | 17 | cd $CURRENT_PATH 18 | if [ -d "$DEST_PATH" ]; then 19 | rm -fr $DEST_PATH 20 | fi 21 | 22 | if [ -f "$SPEC_PATH" ]; then 23 | rm -f $SPEC_PATH 24 | fi 25 | 26 | cd $SOURCE_PATH 27 | git svn rebase 28 | cd $CURRENT_PATH 29 | cp -R $SOURCE_PATH $DEST_PATH 30 | rm -fr $DEST_PATH/.git/ # for git 31 | tar -zcf $COMPRESS_PATH $DEST_PATH 32 | mv -f $COMPRESS_PATH $RPMBUILD_COMPRESS_PATH 33 | sed "s/os/$PLATFORM/" QLanguage.spec > $SPEC_PATH 34 | rpmbuild -bb $SPEC_PATH 35 | else 36 | echo "Unknow archiecture type(i386 or amd64)" 37 | fi 38 | else 39 | echo "Please input architecture(i386 or amd64)" 40 | fi 41 | -------------------------------------------------------------------------------- /Tools/QLanguage/RPM/x86_64/QLanguage-1.0-1.el6.x86_64.rpm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Tools/QLanguage/RPM/x86_64/QLanguage-1.0-1.el6.x86_64.rpm -------------------------------------------------------------------------------- /Tools/QParserGenerator/DEB/QParserGenerator_Deb_AMD64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Tools/QParserGenerator/DEB/QParserGenerator_Deb_AMD64.deb -------------------------------------------------------------------------------- /Tools/QParserGenerator/DEB/control: -------------------------------------------------------------------------------- 1 | Package: QParserGenerator 2 | Version: 1.0 3 | Section: Development/Tools 4 | Priority: optional 5 | Architecture: os 6 | Maintainer: lwch 7 | Description: QParserGenerator is a LALR(1) ParserGenerator 8 | -------------------------------------------------------------------------------- /Tools/QParserGenerator/DEB/makeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./../../makebinary.sh 3 | ./makedeb.sh $1 4 | -------------------------------------------------------------------------------- /Tools/QParserGenerator/DEB/makedeb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ x$1 != x ]; then 4 | if [ $1 = "i386" ] || [ $1 = "amd64" ]; then 5 | DEB_PATH=~/QParserGenerator_Deb_$1/ 6 | BINARY_PATH=~/QLanguage/QLanguage/trunk/Source/QParserGenerator/QParserGenerator 7 | 8 | # make debian path 9 | if [ -d "$DEB_PATH" ]; then 10 | rm -fr $DEB_PATH 11 | fi 12 | mkdir -p $DEB_PATH/./DEBIAN/ 13 | mkdir -p $DEB_PATH/./usr/local/bin/ 14 | #cp control $DEB_PATH/./DEBIAN/ 15 | cp $BINARY_PATH $DEB_PATH/./usr/local/bin/ 16 | 17 | # change archiecture 18 | sed "s/os/$1/" control > $DEB_PATH/./DEBIAN/control 19 | 20 | dpkg -b $DEB_PATH 21 | else 22 | echo "Unknow archiecture type(i386 or amd64)" 23 | fi 24 | else 25 | echo "Please input architecture(i386 or amd64)" 26 | fi 27 | -------------------------------------------------------------------------------- /Tools/QParserGenerator/WIN/QParserGenerator.x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Tools/QParserGenerator/WIN/QParserGenerator.x64.exe -------------------------------------------------------------------------------- /Tools/QParserGenerator/WIN/QParserGenerator.x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwch/QLanguage/310b3b97ad87945cb456c6e0dbc5963793fcefb2/Tools/QParserGenerator/WIN/QParserGenerator.x86.exe -------------------------------------------------------------------------------- /Tools/input.txt: -------------------------------------------------------------------------------- 1 | 100 2 | -------------------------------------------------------------------------------- /Tools/makebinary.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | EXPORT_PATH=~/QLanguage/QLanguage 4 | SOURCE_PATH="http://qlanguage.googlecode.com/svn/" 5 | CMAKE_PATH=$EXPORT_PATH/./trunk/Source 6 | 7 | if [ -d "$EXPORT_PATH" ]; then 8 | rm -fr $EXPORT_PATH 9 | fi 10 | 11 | svn export $SOURCE_PATH $EXPORT_PATH 12 | cd $CMAKE_PATH && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release 13 | cd $CMAKE_PATH && make 14 | -------------------------------------------------------------------------------- /Tools/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DATE=`date '+%Y-%m-%d %H:%M:%S'` 4 | MAILADDR="lwch748@gmail.com" 5 | CURRENT_PATH=/opt/service 6 | SOURCE_PATH="http://qlanguage.googlecode.com/svn/trunk/" 7 | EXPORT_PATH=~/QLanguage/ 8 | CMAKE_PATH=$EXPORT_PATH/./Source 9 | CMAKE_ARGS="" #"-DCMAKE_BUILD_TYPE=Release" 10 | UNITTEST_PATH=$CMAKE_PATH/./QCoreUnitTest 11 | UNITTEST_EXEC=QCoreUnitTest 12 | GITHUB_PATH=~/QLanguage_GitHub/ 13 | GITHUB_URL=git@github.com:lwch/QLanguage.git 14 | 15 | # GITHUB 16 | # first run git "svn clone" and "git remote add" 17 | #git svn clone $SOURCE_PATH $GITHUB_PATH 18 | cd $GITHUB_PATH 19 | #git remote add origin $GITHUB_URL 20 | git svn rebase > $CURRENT_PATH/git_push.txt 21 | git push -f >> $CURRENT_PATH/git_push.txt 22 | mail -s "GitHub push on time $DATE" $MAILADDR < $CURRENT_PATH/git_push.txt 23 | 24 | if [ -d "$EXPORT_PATH" ]; then 25 | rm -fr $EXPORT_PATH 26 | fi 27 | # 有时候会少文件,应此废除 28 | #svn export $SOURCE_PATH $EXPORT_PATH 29 | mkdir $EXPORT_PATH 30 | cp -R $GITHUB_PATH/* $EXPORT_PATH 31 | cd $CMAKE_PATH && cmake -G "Unix Makefiles" -DENABLE_SPEED_TEST=OFF > $CURRENT_PATH/cmake.txt $CMAKE_ARGS 32 | cd $CMAKE_PATH && make 2> $CURRENT_PATH/make.txt 33 | $UNITTEST_PATH/$UNITTEST_EXEC < $CURRENT_PATH/input.txt > $CURRENT_PATH/unittest.txt 34 | mail -s "QLanguageUpdate on time $DATE(CMake Report)" $MAILADDR < $CURRENT_PATH/cmake.txt 35 | mail -s "QLanguageUpdate on time $DATE(Make Report)" $MAILADDR < $CURRENT_PATH/make.txt 36 | mail -s "QLanguageUpdate on time $DATE(UnitTest Report)" $MAILADDR < $CURRENT_PATH/unittest.txt 37 | 38 | 39 | --------------------------------------------------------------------------------