summaryrefslogtreecommitdiffstats
path: root/sencha
diff options
context:
space:
mode:
Diffstat (limited to 'sencha')
-rw-r--r--sencha/Lexer.cpp8
-rw-r--r--sencha/Parser.cpp25
-rwxr-xr-xsencha/bin/Debug/senchabin301486 -> 321710 bytes
-rw-r--r--sencha/main.cpp11
-rw-r--r--sencha/obj/Debug/Lexer.obin367920 -> 367920 bytes
-rw-r--r--sencha/obj/Debug/Parser.obin221664 -> 220816 bytes
-rw-r--r--sencha/obj/Debug/main.obin172656 -> 265376 bytes
-rw-r--r--sencha/sencha.depend6
8 files changed, 31 insertions, 19 deletions
diff --git a/sencha/Lexer.cpp b/sencha/Lexer.cpp
index 820c556..2221cd3 100644
--- a/sencha/Lexer.cpp
+++ b/sencha/Lexer.cpp
@@ -8,7 +8,7 @@ Lexer::Lexer()
char punct[] = {'.', ',', ';', '{', '}', '[', ']', '(', ')'};
punctuation.assign(punct, punct+9);
- string oper[] = {"<", ">", "+", "-", "/", "*", "%", "&", "|", "=", ":", "==", "+=", "-=", "<=", ">=", "!", "&&", "||"};
+ string oper[] = {"<", ">", "+", "-", "/", "*", "%", "&", "|", "=", ":", "==", "+=", "-=", "<=", ">=", "!=", "&&", "||"};
operators.assign(oper, oper +19);
}
@@ -79,7 +79,11 @@ pair<string, Token> Lexer::parse_token(string line)
if(i<line.size())
{
if(line[i] == '=')
- token_value+=line[i];
+ {
+ token_value+=line[i];
+ i++;
+ }
+
}
}
break;
diff --git a/sencha/Parser.cpp b/sencha/Parser.cpp
index d19d8e3..9fab40d 100644
--- a/sencha/Parser.cpp
+++ b/sencha/Parser.cpp
@@ -18,12 +18,12 @@ Parser::~Parser()
void Parser::report(string s)
{
- report_message += s + "\n";
+ report_message += s ;
}
void Parser::error(string s)
{
- error_message += s + "\n";
+ error_message += s ;
}
bool Parser::read_next()
@@ -55,7 +55,7 @@ void Parser::interpret()
if(accept("="))
{
expr();
- report(" := ");
+ report(" :=\n");
}
if(accept(";"))
{
@@ -140,6 +140,7 @@ void Parser::statement()
{
if(accept("{"))
{
+ report("GO Deeper\n");
while(!accept("}"))
{
statement();
@@ -152,7 +153,7 @@ void Parser::statement()
if(accept("="))
{
expr();
- report(" := ");
+ report(" :=\n");
}
expect(";");
}
@@ -165,8 +166,9 @@ void Parser::statement()
{
//similar stuff
}
- else if(tok_value == "return")
+ else if(accept("return"))
{
+
if(!peek(";"))
{
expr();
@@ -178,7 +180,8 @@ void Parser::statement()
else
{
expr();
- expect(";");
+ while(!expect(";")) read_next();
+
}
}
@@ -244,11 +247,11 @@ void Parser::add_expr()
if(accept("+"))
{
postfix_expr();
- report(" + ");
+ report(" +\n");
} else if(accept("-"))
{
postfix_expr();
- report(" - ");
+ report(" -\n");
}
}
}
@@ -260,7 +263,7 @@ void Parser::rel_expr()
{
accept("<");
add_expr();
- report(" < ");
+ report(" <\n");
}
}
@@ -272,12 +275,12 @@ void Parser::eq_expr()
if(accept("=="))
{
rel_expr();
- report("==");
+ report("==\n");
}
else if(accept("!="))
{
rel_expr();
- report("!=");
+ report("!=\n");
}
}
}
diff --git a/sencha/bin/Debug/sencha b/sencha/bin/Debug/sencha
index 80e6bde..cab152f 100755
--- a/sencha/bin/Debug/sencha
+++ b/sencha/bin/Debug/sencha
Binary files differ
diff --git a/sencha/main.cpp b/sencha/main.cpp
index 4be25f9..8ecabdc 100644
--- a/sencha/main.cpp
+++ b/sencha/main.cpp
@@ -9,7 +9,7 @@ using namespace std;
void test_lexer()
{
string test_line = "def i; bulb; i + 3; string banan; banan = \"banan\"; string kaboom(num how_many_times) { def z; }";
- string test_line2 = "i like \"lol\" ,function: bananananananas, lol, ==555% % % += 1sas /> \n";
+ 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<Token> tokens = lexer.parse_line(test_line);
@@ -32,15 +32,20 @@ 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;}");
Lexer lexer;
vector<Token> tokens;
- for(i=0; i<lines.size(); i++)
+ for(int i=0; i<lines.size(); i++)
{
tokens = lexer.parse_line(lines[i]);
Parser parser = Parser(tokens);
parser.interpret();
+ cout << "<<<Parsing number: " << i << " >>>" << endl;
+ cout << "Instructions: " << endl ;
+ cout << lines[i] << endl << endl;
cout << parser.report_message;
- cout << parser.error_message;
+ cout << parser.error_message << endl;
}
}
diff --git a/sencha/obj/Debug/Lexer.o b/sencha/obj/Debug/Lexer.o
index 3b22649..29d46b8 100644
--- a/sencha/obj/Debug/Lexer.o
+++ b/sencha/obj/Debug/Lexer.o
Binary files differ
diff --git a/sencha/obj/Debug/Parser.o b/sencha/obj/Debug/Parser.o
index e90665e..7099ed1 100644
--- a/sencha/obj/Debug/Parser.o
+++ b/sencha/obj/Debug/Parser.o
Binary files differ
diff --git a/sencha/obj/Debug/main.o b/sencha/obj/Debug/main.o
index 1d3aa1e..8ea2fa8 100644
--- a/sencha/obj/Debug/main.o
+++ b/sencha/obj/Debug/main.o
Binary files differ
diff --git a/sencha/sencha.depend b/sencha/sencha.depend
index 0f0e6ce..615b0fa 100644
--- a/sencha/sencha.depend
+++ b/sencha/sencha.depend
@@ -5,7 +5,7 @@
1351424620 /home/attero/development/sencha-lang/sencha/Token.h
<string>
-1351425805 source:/home/attero/development/sencha-lang/sencha/Lexer.cpp
+1351428918 source:/home/attero/development/sencha-lang/sencha/Lexer.cpp
"Lexer.h"
1351413156 /home/attero/development/sencha-lang/sencha/Lexer.h
@@ -16,14 +16,14 @@
<iostream>
"Token.h"
-1351426109 source:/home/attero/development/sencha-lang/sencha/main.cpp
+1351429258 source:/home/attero/development/sencha-lang/sencha/main.cpp
<iostream>
<string>
"Token.h"
"Lexer.h"
"Parser.h"
-1351426069 source:/home/attero/development/sencha-lang/sencha/Parser.cpp
+1351429380 source:/home/attero/development/sencha-lang/sencha/Parser.cpp
"Parser.h"
"iostream"