From 4fb889400b4f4e478bea030d1484becc89a1025c Mon Sep 17 00:00:00 2001 From: martin dobrev Date: Fri, 7 Sep 2018 12:13:57 +0300 Subject: Implement identifier tokenization. --- JSImpl/src/main.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'JSImpl/src/main.cpp') diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp index 8452e72..1b345c3 100644 --- a/JSImpl/src/main.cpp +++ b/JSImpl/src/main.cpp @@ -1,6 +1,7 @@ #include "Lexer.h" #include #define LOG(msg) std::cout << msg << std::endl +#define EXECUTE_TEST(test) std::cout << #test << " "; test(); void TestLess() { auto tokens = Tokenize("<"); @@ -53,11 +54,30 @@ void TestKeyWord() } } +void TestVariableDeclaration() +{ + auto tokens = Tokenize("var pesho = 10"); + if (tokens.size() == 5 && tokens[0].Type == TokenType::Var + && tokens[1].Type == TokenType::Identifier + && tokens[2].Type == TokenType::Equal + && tokens[3].Type == TokenType::Number + && tokens[4].Type == TokenType::Eof) + { + LOG("PASS"); + } + else + { + LOG("FAIL"); + } +} + int main() { - TestLess(); - TestNumber(); - TestString(); - TestKeyWord(); + EXECUTE_TEST(TestLess); + EXECUTE_TEST(TestNumber); + EXECUTE_TEST(TestString); + EXECUTE_TEST(TestKeyWord); + EXECUTE_TEST(TestVariableDeclaration); + std::system("pause"); return 0; } \ No newline at end of file -- cgit v1.3.1-23-gd82d