diff --git a/Sencha-lang/ASTNode.cpp b/Sencha-lang/ASTNode.cpp new file mode 100644 index 0000000..305cdb7 --- /dev/null +++ b/Sencha-lang/ASTNode.cpp @@ -0,0 +1,18 @@ +/* + * ASTNode.cpp + * + * Created on: Nov 4, 2012 + * Author: attero + */ + +#include "ASTNode.h" + +ASTNode::ASTNode() { + // TODO Auto-generated constructor stub + +} + +ASTNode::~ASTNode() { + // TODO Auto-generated destructor stub +} + diff --git a/Sencha-lang/ASTNode.h b/Sencha-lang/ASTNode.h new file mode 100644 index 0000000..5176a8a --- /dev/null +++ b/Sencha-lang/ASTNode.h @@ -0,0 +1,17 @@ +/* + * ASTNode.h + * + * Created on: Nov 4, 2012 + * Author: attero + */ + +#ifndef ASTNODE_H_ +#define ASTNODE_H_ + +class ASTNode { +public: + ASTNode(); + virtual ~ASTNode(); +}; + +#endif /* ASTNODE_H_ */ diff --git a/Sencha-lang/Debug/Parser.o b/Sencha-lang/Debug/Parser.o index ab49874..e49040d 100644 Binary files a/Sencha-lang/Debug/Parser.o and b/Sencha-lang/Debug/Parser.o differ diff --git a/Sencha-lang/Debug/Sencha-lang b/Sencha-lang/Debug/Sencha-lang index f3fd0e1..9617346 100755 Binary files a/Sencha-lang/Debug/Sencha-lang and b/Sencha-lang/Debug/Sencha-lang differ diff --git a/Sencha-lang/Debug/Tests/TestLexer.o b/Sencha-lang/Debug/Tests/TestLexer.o index af6e622..740dd61 100644 Binary files a/Sencha-lang/Debug/Tests/TestLexer.o and b/Sencha-lang/Debug/Tests/TestLexer.o differ diff --git a/Sencha-lang/Debug/main.d b/Sencha-lang/Debug/main.d index b762b62..cf1d5e1 100644 --- a/Sencha-lang/Debug/main.d +++ b/Sencha-lang/Debug/main.d @@ -1,5 +1,6 @@ main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \ - ../Tests/TestLexer.h ../Tests/TestSuite.h ../Tests/minunit.h + ../Tests/TestLexer.h ../Tests/TestSuite.h ../Tests/minunit.h \ + ../Tests/../Lexer.h ../Token.h: @@ -12,3 +13,5 @@ main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \ ../Tests/TestSuite.h: ../Tests/minunit.h: + +../Tests/../Lexer.h: diff --git a/Sencha-lang/Debug/main.o b/Sencha-lang/Debug/main.o index eb38f33..335951e 100644 Binary files a/Sencha-lang/Debug/main.o and b/Sencha-lang/Debug/main.o differ diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp index f0ef0dd..28bb26c 100644 --- a/Sencha-lang/Parser.cpp +++ b/Sencha-lang/Parser.cpp @@ -55,34 +55,39 @@ void Parser::interpret() { expr(); report(" :=\n"); - } + } + if(accept(";")) { report("Variable definition\n"); continue; } - expect("("); - int argc = 0; - while(true) - { - argc++; - is_type(); - report("function argument: " + tok_value + "\n"); - read_next(); - if(peek(")")) - { - break; - } - expect(","); + if(expect("(")) + { + int argc = 0; + while(tok_value!= ")") + { + argc++; + is_type(); + report("function argument: " + tok_value + "\n"); + read_next(); + if(peek(")")) + { + break; + } + expect(","); + } + expect(")"); + + if(!accept(";")) + { + report("function body:\n"); + statement(); + } } - expect(")"); + else expect(";"); - if(!accept(";")) - { - report("function body:\n"); - statement(); - } } else { @@ -179,7 +184,7 @@ void Parser::statement() else { expr(); - while(!expect(";")) read_next(); + while(!expect(";") && tok_value != "") read_next(); } } diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp index 2c4bc3d..a1b9346 100644 --- a/Sencha-lang/main.cpp +++ b/Sencha-lang/main.cpp @@ -23,18 +23,14 @@ void test_lexer() tokens = lexer.parse_line(test_line2); - /*for(int i=0; i< tokens.size(); i++) - { - cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl; - }*/ } 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("{ i like bananas; string hello = \"hello\"; hello(); }"); - lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1;}"); + 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 tokens; + + string input = "start"; + while(input != "end\n") + { + cout << "I'm waiting for your input, Master!\n"; + getline(cin, input); + tokens = lexer.parse_line(input); + Parser parser(tokens); + parser.interpret(); + cout << parser.report_message; + cout << parser.error_message << endl; + } + + +} + int main() { cout << "Hello world!" << endl; TestLexer test_l; - test_l.run_tests(); + //test_l.run_tests(); //test_parser(); - //test_lexer(); + //test_lexer(); + interactive(); return 0; }