diff --git a/src/ast/AllAST.h b/src/ast/AllAST.h new file mode 100644 index 0000000000000000000000000000000000000000..fd5e3a29a5b6ffe3225eae85dc1e8046af522aab --- /dev/null +++ b/src/ast/AllAST.h @@ -0,0 +1,23 @@ +/* + * AllAST.h + * + * Created on: Feb 14, 2021 + * Author: tomdang + * + * Wrapper header for all AST headers + */ + +#ifndef _ALLAST_H_ +#define _ALLAST_H_ + +#include "BaseAST.h" +#include "CallExprAST.h" +#include "CodeBlockAST.h" +#include "ExprAST.h" +#include "ExternAST.h" +#include "FunctionAST.h" +#include "IntExprAST.h" +#include "PrototypeAST.h" +#include "VariableExprAST.h" + +#endif \ No newline at end of file diff --git a/src/yacc_stuff/Token.cpp b/src/yacc_stuff/Token.cpp deleted file mode 100644 index 25d61e04a0b7efeeccff3939463dfcbf7b363936..0000000000000000000000000000000000000000 --- a/src/yacc_stuff/Token.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Token.cpp - * - * Created on: Dec 16, 2020 - * Author: zbc - */ - -#include "Token.h" -#include - -Token::Token() { - tokenValue = ""; -} - -Token::~Token() { - // TODO Auto-generated destructor stub -} - -std::string Token::dump() { - //TODO 先这样写着吧,反正是调试用 - std::string typeStr; - std::stringstream ss; - switch (type) { - case tok_err: - typeStr = "tok_err"; - break; - case tok_eof: - typeStr = "tok_eof"; - break; - case tok_fun: - typeStr = "tok_fun"; - break; - case tok_extern: - typeStr = "tok_extern"; - break; - case tok_identifier: - typeStr = "tok_identifier"; - break; - case tok_number: - typeStr = "tok_number"; - break; - case tok_type: - typeStr = "tok_type"; - break; - case tok_return: - typeStr = "tok_return"; - break; - case tok_return_type: - typeStr = "tok_return_type"; - break; - case tok_syntax: - typeStr = "tok_syntax"; - break; - default: - typeStr = "未定义"; - } - ss << "type:" << typeStr << ",data:" << tokenValue; - return ss.str(); -} diff --git a/src/yacc_stuff/Token.h b/src/yacc_stuff/Token.h deleted file mode 100644 index aee23f914f83f910eb0b9823578c5976e60276f2..0000000000000000000000000000000000000000 --- a/src/yacc_stuff/Token.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Token.h - * - * Created on: Dec 16, 2020 - * Author: zbc - */ - -#ifndef COMPILER_TOKEN_H_ -#define COMPILER_TOKEN_H_ - -#include - -enum TokenType { - tok_err, - tok_eof, - tok_fun, - tok_extern, - tok_identifier, - tok_number, - tok_type, - tok_return, - tok_return_type, - tok_syntax -}; - -class Token { -public: - Token(); - virtual ~Token(); - std::string dump(); - TokenType type; - std::string tokenValue; -}; - -#endif /* COMPILER_TOKEN_H_ */ diff --git a/src/yacc_stuff/tokenizer.l b/src/yacc_stuff/tokenizer.l index 4d6ff222c921ab20f51b9afe69bcabe0827b3b5b..f0d5cd2ab5ca0c6be2041de5c52f373c3654eb0b 100644 --- a/src/yacc_stuff/tokenizer.l +++ b/src/yacc_stuff/tokenizer.l @@ -1,5 +1,5 @@ %{ -#include "Token.h" +#include "../Token.h" #include #include int token; @@ -7,51 +7,51 @@ int token; %} %option yylineno %% -[ \t]+ {/*Skip spaces and tabs*/} -\/\*[.\n]*?\*\/|\/\/.* {/*Skip comments*/} +[ \t]+ {/*Skip spaces and tabs*/}; +\/\*[.\n]*?\*\/|\/\/.* {/*Skip comments*/}; --> token = tok_return_type; return token; -fun token = tok_fun; return token; -func token = tok_fun; return token; -extern token = tok_extern; return token; -return token = tok_extern; return token; -[a-zA-Z][a-zA-Z0-9]* token = tok_identifier; return token; -0b[01]* token = tok_number; return token; -0x[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; -0B[01]* token = tok_number; return token; -0X[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; -0[1-7][0-7]* token = tok_number; return token; -[1-9][0-9.]* token = tok_number; return token; -0 token = tok_number; return token; +-> token = tok_return_type; return token; +fun token = tok_fun; return token; +func token = tok_fun; return token; +extern token = tok_extern; return token; +return token = tok_extern; return token; +[a-zA-Z][a-zA-Z0-9]* token = tok_identifier; return token; +0b[01]* token = tok_number; return token; +0x[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0B[01]* token = tok_number; return token; +0X[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0[1-7][0-7]* token = tok_number; return token; +[1-9][0-9.]* token = tok_number; return token; +0 token = tok_number; return token; -! token = tok_syntax; return token; -% token = tok_syntax; return token; -\^ token = tok_syntax; return token; -& token = tok_syntax; return token; -\* token = tok_syntax; return token; -\( token = tok_syntax; return token; -\) token = tok_syntax; return token; -\+ token = tok_syntax; return token; -= token = tok_syntax; return token; -\{ token = tok_syntax; return token; -\} token = tok_syntax; return token; -\| token = tok_syntax; return token; -~ token = tok_syntax; return token; -\[ token = tok_syntax; return token; -\] token = tok_syntax; return token; -\\ token = tok_syntax; return token; -; token = tok_syntax; return token; -' token = tok_syntax; return token; -: token = tok_syntax; return token; -\" token = tok_syntax; return token; -, token = tok_syntax; return token; -\< token = tok_syntax; return token; -\> token = tok_syntax; return token; -\? token = tok_syntax; return token; -\. token = tok_syntax; return token; -\/ token = tok_syntax; return token; -# token = tok_syntax; return token; -<> {token = tok_eof; return token;} +! token = tok_syntax; return token; +% token = tok_syntax; return token; +\^ token = tok_syntax; return token; +& token = tok_syntax; return token; +\* token = tok_syntax; return token; +\( token = tok_syntax; return token; +\) token = tok_syntax; return token; +\+ token = tok_syntax; return token; += token = tok_syntax; return token; +\{ token = tok_syntax; return token; +\} token = tok_syntax; return token; +\| token = tok_syntax; return token; +~ token = tok_syntax; return token; +\[ token = tok_syntax; return token; +\] token = tok_syntax; return token; +\\ token = tok_syntax; return token; +; token = tok_syntax; return token; +' token = tok_syntax; return token; +: token = tok_syntax; return token; +\" token = tok_syntax; return token; +, token = tok_syntax; return token; +\< token = tok_syntax; return token; +\> token = tok_syntax; return token; +\? token = tok_syntax; return token; +\. token = tok_syntax; return token; +\/ token = tok_syntax; return token; +# token = tok_syntax; return token; +<> {token = tok_eof; return token;} %% int yyFlexLexer::yywrap(){return 1;} diff --git a/src/yacc_stuff/utils.cpp b/src/yacc_stuff/utils.cpp deleted file mode 100644 index e5e39a857feb97207ef670a1fca4ccc9a0888fc6..0000000000000000000000000000000000000000 --- a/src/yacc_stuff/utils.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * utils.cpp - * - * Created on: May 2, 2020 - * Author: zbc - */ -#include -#include -#include -#include "CompileError.hpp" - -char syntax[] = { '!', '%', '^', '&', '*', '(', ')', '+', '=', '{', '}', '|', - '~', '[', ']', '\\', ';', '\'', ':', '"', ',', '<', '>', '?', '.', '/', - '#', ' ' }; - - -std::string demangle(const std::string &fnName, - const std::vector &argTypes) { - std::stringstream ss; - ss << "_alolang_"; - ss << fnName.length() << fnName; - for (std::string word : argTypes) { - ss << word.length() << word; //得到类型 - } - return ss.str(); -} - -bool isSyntax(char c) { - for (char tmp : syntax) { - if (c == tmp) { - return true; - } - } - return false; -} - -//从pos查找到下一个非空格字段 -void skipSpace(const std::vector &words, long unsigned int &i) { - while (true) { - i++; - if (i >= words.size()) { - //TODO:异常处理(未期待的结尾) - CompileError e("Unexpected EOF"); - throw e; - } - if (words[i] != " ") { - break; - } - } -} - -void skipSpace(std::istream &in) { - while (in.good() && isspace(in.peek())) { - // Read and discard the space character - in.ignore(); - //in.get(); - } -} diff --git a/src/yacc_stuff/utils.h b/src/yacc_stuff/utils.h deleted file mode 100644 index 5e8dec2768a197053e9d32127341a9ed6e26f01b..0000000000000000000000000000000000000000 --- a/src/yacc_stuff/utils.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * utils.h - * - * Created on: May 2, 2020 - * Author: zbc - */ - -#ifndef COMPILER_UTILS_H_ -#define COMPILER_UTILS_H_ - -#include - -std::string demangle(const std::string &fnName, - const std::vector &argTypes); - -bool isSyntax(char c); -void skipSpace(const std::vector &words, long unsigned int &i); -void skipSpace(std::istream &in); - -#endif /* COMPILER_UTILS_H_ */