Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / main.cpp
diff options
context:
space:
mode:
Commit4fb889400b4f4e478bea030d1484becc89a1025c (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 12:13:57 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 12:13:57 +0300
Files05a8277a02035fbe4afa346b04971360baa501af /JSImpl/src/main.cpp
IPL-4fb889400b4f4e478bea030d1484becc89a1025c.tar
IPL-4fb889400b4f4e478bea030d1484becc89a1025c.tar.gz
IPL-4fb889400b4f4e478bea030d1484becc89a1025c.zip
Parent00fedcbc8839be26b6738613d88b9d6883eaa7a0 (diff)
Implement identifier tokenization.
1 files changed, 24 insertions, 4 deletions
-rw-r--r--JSImpl/src/main.cpp28
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 <iostream>
#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