From 00fedcbc8839be26b6738613d88b9d6883eaa7a0 Mon Sep 17 00:00:00 2001 From: martin dobrev Date: Wed, 5 Sep 2018 09:30:12 +0300 Subject: Create solution for sample vm implementation. Implement basic Lexer. --- JSImpl/src/main.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 JSImpl/src/main.cpp (limited to 'JSImpl/src/main.cpp') diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp new file mode 100644 index 0000000..8452e72 --- /dev/null +++ b/JSImpl/src/main.cpp @@ -0,0 +1,63 @@ +#include "Lexer.h" +#include +#define LOG(msg) std::cout << msg << std::endl +void TestLess() +{ + auto tokens = Tokenize("<"); + if (tokens.size() == 2 && tokens[0].Type == TokenType::Less) + { + LOG("PASS"); + } + else + { + LOG("FAIL"); + } +} + +void TestNumber() +{ + auto tokens = Tokenize("213434.24"); + if (tokens.size() == 2 && tokens[0].Type == TokenType::Number && tokens[0].Number == 213434.24) + { + LOG("PASS"); + } + else + { + LOG("FAIL"); + } +} + +void TestString() +{ + auto tokens = Tokenize("\"alabala\""); + if (tokens.size() == 2 && tokens[0].Type == TokenType::String && tokens[0].Lexeme == "\"alabala\"") + { + LOG("PASS"); + } + else + { + LOG("FAIL"); + } +} + +void TestKeyWord() +{ + auto tokens = Tokenize("for"); + if (tokens.size() == 2 && tokens[0].Type == TokenType::For) + { + LOG("PASS"); + } + else + { + LOG("FAIL"); + } +} + +int main() +{ + TestLess(); + TestNumber(); + TestString(); + TestKeyWord(); + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d