diff --git a/.gitignore b/.gitignore index 007475c..378eac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ -[Bb]uild/ -[Oo]ut/ -.vs/ - -*.json +build diff --git a/README.md b/README.md deleted file mode 100644 index 4a7d9dd..0000000 --- a/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# The Bisquit Programming Language - -Bisquit is a first attempt at designing and implementing a simple, interpreted language; Drawing inspiration from typical assembly languages and BASIC. -For a quick tour of the language, check the PDF in the /doc/ directory, and check out the the supplied example programs. - -To build the interpreter, go to the root of the project directory and do: - - mkdir build && cd build - cmake .. - make - -The bisquit_interpreter executable will then be built. diff --git a/examples/test.bisq b/examples/test.bisq index e7a83d5..73e3abc 100644 --- a/examples/test.bisq +++ b/examples/test.bisq @@ -1,5 +1,5 @@ PRINT "Hello World, this is a number: " 15 -ASSIGN 15 number +ASSIGN number 15 PRINT "Let's double it's value, shall we?" ADD number number number PRINT "There we go: " number diff --git a/src/common.hpp b/src/common.hpp index 5b2fe2d..1862394 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -3,7 +3,7 @@ #include -enum class TokenType +enum TokenType { KEYWORD, IDENTIFIER, @@ -11,7 +11,7 @@ enum class TokenType ID_OR_LIT }; -enum class ValueType +enum ValueType { STRING, NUMBER, @@ -20,12 +20,12 @@ enum class ValueType // some prototypes struct Token; -struct Instruction; +class Instruction; struct Keyword; -struct Runtime; +class Runtime; -std::string resolve_TokenType_str(TokenType); -std::string resolve_ValueType_str(ValueType); +const std::string resolve_TokenType_str(enum TokenType); +const std::string resolve_ValueType_str(enum ValueType); #endif //BISCUIT_INTERPRETER_COMMON_HPP diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 8ac5dba..48d806c 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -29,9 +29,9 @@ struct WrongArgumentCountExcept : public std::exception struct WrongTokenExcept : public std::exception { - TokenType expected, got; + enum TokenType expected, got; std::string keyword_name, token_str; - inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, TokenType _expected, TokenType _got) + inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, const enum TokenType& _expected, const enum TokenType& _got) : expected(_expected), got(_got), keyword_name(_keyword_name), token_str(_token_str) {} }; @@ -39,9 +39,9 @@ struct WrongTokenExcept : public std::exception // Runtime errors struct TypeErrorExcept : public std::exception { - ValueType expected, got; + enum ValueType expected, got; std::string token_str; - inline TypeErrorExcept(const std::string& _token_str, ValueType _expected, ValueType _got) + inline TypeErrorExcept(const std::string& _token_str, const enum ValueType& _expected, const enum ValueType& _got) : expected(_expected), got(_got), token_str(_token_str) {} }; diff --git a/src/keywords.cpp b/src/keywords.cpp index 69943d3..65429f3 100644 --- a/src/keywords.cpp +++ b/src/keywords.cpp @@ -169,9 +169,9 @@ const std::vector keywords = float condition; if(tokens[0].type == TokenType::LITERAL) - dest = static_cast(std::floor(tokens[0].val_number)); + dest = std::floor(tokens[0].val_number); else - dest = static_cast(std::floor(rt.resolve_var_num(tokens[0].val_string))); + dest = std::floor(rt.resolve_var_num(tokens[0].val_string)); if(tokens[1].type == TokenType::LITERAL) condition = std::floor(tokens[1].val_number); @@ -193,16 +193,16 @@ const std::vector keywords = float condition; if(tokens[0].type == TokenType::LITERAL) - offset = static_cast(std::floor(tokens[0].val_number)); + offset = std::floor(tokens[0].val_number); else - offset = static_cast(std::floor(rt.resolve_var_num(tokens[0].val_string))); + offset = std::floor(rt.resolve_var_num(tokens[0].val_string)); if(tokens[1].type == TokenType::LITERAL) condition = std::floor(tokens[1].val_number); else condition = std::floor(rt.resolve_var_num(tokens[1].val_string)); - dest = rt.instruction_counter + offset; + dest = rt.instruction_counter + dest; if(condition > 0.0f) rt.jump_instructions(dest); @@ -253,13 +253,13 @@ const std::vector keywords = { int limit; if(tokens[0].type == TokenType::LITERAL) - limit = static_cast(tokens[0].val_number); + limit = tokens[0].val_number; else - limit = static_cast(rt.resolve_var_num(tokens[0].val_string)); + limit = rt.resolve_var_num(tokens[0].val_string); int number = rand() % limit; - rt.assign_var_num(tokens[1].val_string, static_cast(number)); + rt.assign_var_num(tokens[1].val_string, number); } }, { diff --git a/src/main.cpp b/src/main.cpp index 06974f7..b12b8cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,7 @@ +#if defined(WIN32) || defined(WIN32) || defined(__WIN32) +#include +#endif + #include #include #include @@ -9,6 +13,21 @@ #include "parse.hpp" #include "runtime.hpp" +bool request_console(); + +// Must request console on Windows +#if defined(WIN32) || defined(WIN32) || defined(__WIN32) +bool request_console() +{ + return AllocConsole(); +} +#else +bool request_console() +{ + return true; +} +#endif + std::ifstream get_infile(int argc, char ** argv) { if(argc != 2) @@ -35,6 +54,13 @@ int main(int argc, char * argv[]) std::stringstream buffer; buffer << infile.rdbuf(); + // On Windows, we have to explicitly request a console + /*if(!request_console()) + { + std::cerr << "Failed to get console!" << std::endl; + exit(EXIT_FAILURE); + }*/ + std::vector instructions = parse_instructions(buffer.str()); Runtime rt(instructions); diff --git a/src/parse.cpp b/src/parse.cpp index ada62fc..7bfdf1f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -50,7 +50,7 @@ std::vector tokenize_line(const std::string& line) } } - return tokens; + return std::move(tokens); } // Main parsing function @@ -115,7 +115,7 @@ std::vector parse_instructions(const std::string& code_arg) } - return instructions; + return std::move(instructions); } bool is_keyword(std::string str) @@ -279,7 +279,7 @@ Instruction::Instruction(std::vector& _token_list) // Make sure the keyword gets the number of arguments it needs if(keyword_ptr->expected_num_args != -1 && (keyword_ptr->expected_num_args != tokens.size() - 1)) - throw WrongArgumentCountExcept(keyword_ptr->name, keyword_ptr->expected_num_args, static_cast(tokens.size() - 1)); + throw WrongArgumentCountExcept(keyword_ptr->name, keyword_ptr->expected_num_args, tokens.size() - 1); // Check the arguments supplied are the right kind of tokens for(int i = 0; i < keyword_ptr->expected_num_args; i++) diff --git a/src/runtime.cpp b/src/runtime.cpp index 2980047..afa1024 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "runtime.hpp" #include "exceptions.hpp" diff --git a/src/util.cpp b/src/util.cpp index 69c13f6..24d4106 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,7 +1,7 @@ #include "common.hpp" #include -std::string resolve_TokenType_str(TokenType ttype) +const std::string resolve_TokenType_str(enum TokenType ttype) { switch(ttype) { @@ -22,7 +22,7 @@ std::string resolve_TokenType_str(TokenType ttype) return "UNKNOW TOKENTYPE"; } -std::string resolve_ValueType_str(ValueType vtype) +const std::string resolve_ValueType_str(enum ValueType vtype) { switch(vtype) {