#include #include #include "Token.h" #include "Lexer.h" #include "Parser.h" #include "Tests/TestLexer.h" using namespace std; void test_lexer() { string test_line = "def i; bulb; i + 3; string banan; banan = \"banan and other stuff\"; string kaboom(num how_many_times) { def z; }"; string test_line2 = "def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree( num how_many) {return how_many -1; != <=}"; Lexer lexer; vector tokens = lexer.parse_line(test_line); for(int i=0; i< tokens.size(); i++) { cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl; } tokens = lexer.parse_line(test_line2); } void test_parser() { vector lines; lines.push_back("def i; bulb; i + 3; string banan = \"kartofel\"; banan = \"banan\"; string kaboom(num how_many_times) { def z; }"); lines.push_back("num pun"); lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1}"); Lexer lexer; vector tokens; for(int i=0; i>>" << endl; cout << "Instructions: " << endl ; cout << lines[i] << endl << endl; cout << parser.report_message; cout << parser.error_message << endl; } } int how_depth_change(vector tokens) { int change = 0; for (int i = 0; i < tokens.size(); i++) { if(tokens[i].value == "{") change++; else if(tokens[i].value == "}") change--; } return change; } string compute_indentation(int depth_level) { string indent = ""; for(int i=0; i< depth_level; i++) { indent += " "; } return indent; } void interactive() { Lexer lexer; Parser parser; vector tokens; string input; int level_of_depth = 0; string indentation = ""; while(true) { cout << ">> " + indentation; getline(cin, input); if(input == "quit()") break; tokens = lexer.parse_line(input); level_of_depth += how_depth_change(tokens); indentation = compute_indentation(level_of_depth); parser.add_tokens(tokens); if(level_of_depth == 0) { parser.interpret(); cout << parser.report_message << endl; cout << parser.error_message << endl; cout << parser.show_tokens() << endl; } } } int main() { cout << "Sencha-lang interpreter, version 0.02" << endl; TestLexer test_l; //test_l.run_tests(); //test_parser(); //test_lexer(); interactive(); return 0; }