summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-04 16:21:51 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-04 16:21:51 +0100
commit8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b (patch)
tree1fed9cdbd0c0b80e09cab8dc0293c28c3ec36838
parente1241201219befee36f01e88ebbbace4000befaf (diff)
downloadsencha-lang-8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b.tar.gz
sencha-lang-8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b.tar.bz2
sencha-lang-8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b.tar.xz
sencha-lang-8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b.zip
Interactive mode, bug with looping while parsing some incorrect input corrected.`
-rw-r--r--Sencha-lang/ASTNode.cpp18
-rw-r--r--Sencha-lang/ASTNode.h17
-rw-r--r--Sencha-lang/Debug/Parser.obin317200 -> 317912 bytes
-rwxr-xr-xSencha-lang/Debug/Sencha-langbin444432 -> 446381 bytes
-rw-r--r--Sencha-lang/Debug/Tests/TestLexer.obin176224 -> 175376 bytes
-rw-r--r--Sencha-lang/Debug/main.d5
-rw-r--r--Sencha-lang/Debug/main.obin363008 -> 369464 bytes
-rw-r--r--Sencha-lang/Parser.cpp47
-rw-r--r--Sencha-lang/main.cpp37
9 files changed, 93 insertions, 31 deletions
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
--- a/Sencha-lang/Debug/Parser.o
+++ b/Sencha-lang/Debug/Parser.o
Binary files differ
diff --git a/Sencha-lang/Debug/Sencha-lang b/Sencha-lang/Debug/Sencha-lang
index f3fd0e1..9617346 100755
--- a/Sencha-lang/Debug/Sencha-lang
+++ b/Sencha-lang/Debug/Sencha-lang
Binary files differ
diff --git a/Sencha-lang/Debug/Tests/TestLexer.o b/Sencha-lang/Debug/Tests/TestLexer.o
index af6e622..740dd61 100644
--- a/Sencha-lang/Debug/Tests/TestLexer.o
+++ b/Sencha-lang/Debug/Tests/TestLexer.o
Binary files 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
--- a/Sencha-lang/Debug/main.o
+++ b/Sencha-lang/Debug/main.o
Binary files 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<string> 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<Token> tokens;
for(int i=0; i<lines.size(); i++)
@@ -49,15 +45,38 @@ void test_parser()
cout << parser.error_message << endl;
}
-}
+}
+
+void interactive()
+{
+ Lexer lexer;
+
+ vector<Token> 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;
}