summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-04 17:16:02 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-04 17:16:02 +0100
commit4cec6422345e16b31f8b9c2800c9b82c4c79afa9 (patch)
treed97b98ecb2bf94877ccea6710d22b1afb99e59cb
parent8dc5802c2b19a18ef212c77ec8cbdb9617c8f46b (diff)
downloadsencha-lang-4cec6422345e16b31f8b9c2800c9b82c4c79afa9.tar.gz
sencha-lang-4cec6422345e16b31f8b9c2800c9b82c4c79afa9.tar.bz2
sencha-lang-4cec6422345e16b31f8b9c2800c9b82c4c79afa9.tar.xz
sencha-lang-4cec6422345e16b31f8b9c2800c9b82c4c79afa9.zip
Bug with brackets in parsing resolved.
-rw-r--r--Sencha-lang/ASTNode.cpp2
-rw-r--r--Sencha-lang/ASTNode.h7
-rw-r--r--Sencha-lang/ASTPrimary.cpp19
-rw-r--r--Sencha-lang/ASTPrimary.h20
-rw-r--r--Sencha-lang/Debug/ASTNode.d3
-rw-r--r--Sencha-lang/Debug/ASTNode.obin0 -> 91256 bytes
-rw-r--r--Sencha-lang/Debug/ASTPrimary.d5
-rw-r--r--Sencha-lang/Debug/ASTPrimary.obin0 -> 52616 bytes
-rw-r--r--Sencha-lang/Debug/Parser.obin317912 -> 322240 bytes
-rwxr-xr-xSencha-lang/Debug/Sencha-langbin446381 -> 470096 bytes
-rw-r--r--Sencha-lang/Debug/subdir.mk6
-rw-r--r--Sencha-lang/Parser.cpp50
-rw-r--r--Sencha-lang/Parser.h3
13 files changed, 100 insertions, 15 deletions
diff --git a/Sencha-lang/ASTNode.cpp b/Sencha-lang/ASTNode.cpp
index 305cdb7..80429c2 100644
--- a/Sencha-lang/ASTNode.cpp
+++ b/Sencha-lang/ASTNode.cpp
@@ -9,7 +9,7 @@
ASTNode::ASTNode() {
// TODO Auto-generated constructor stub
-
+ parent = 0;
}
ASTNode::~ASTNode() {
diff --git a/Sencha-lang/ASTNode.h b/Sencha-lang/ASTNode.h
index 5176a8a..b0145a3 100644
--- a/Sencha-lang/ASTNode.h
+++ b/Sencha-lang/ASTNode.h
@@ -7,10 +7,17 @@
#ifndef ASTNODE_H_
#define ASTNODE_H_
+#include <vector>
class ASTNode {
public:
ASTNode();
+ ASTNode * parent;
+ std::vector<ASTNode *> children;
+ void add_children(ASTNode *);
+ void remove_most_right_children();
+ void set_parent(ASTNode *);
+ virtual void execute() = 0;
virtual ~ASTNode();
};
diff --git a/Sencha-lang/ASTPrimary.cpp b/Sencha-lang/ASTPrimary.cpp
new file mode 100644
index 0000000..f4a35de
--- /dev/null
+++ b/Sencha-lang/ASTPrimary.cpp
@@ -0,0 +1,19 @@
+/*
+ * ASTPrimary.cpp
+ *
+ * Created on: Nov 4, 2012
+ * Author: attero
+ */
+
+#include "ASTPrimary.h"
+/*
+ASTPrimary::ASTPrimary() {
+ // TODO Auto-generated constructor stub
+
+}
+
+ASTPrimary::~ASTPrimary() {
+ // TODO Auto-generated destructor stub
+}
+
+*/
diff --git a/Sencha-lang/ASTPrimary.h b/Sencha-lang/ASTPrimary.h
new file mode 100644
index 0000000..dbd3f8e
--- /dev/null
+++ b/Sencha-lang/ASTPrimary.h
@@ -0,0 +1,20 @@
+/*
+ * ASTPrimary.h
+ *
+ * Created on: Nov 4, 2012
+ * Author: attero
+ */
+
+#ifndef ASTPRIMARY_H_
+#define ASTPRIMARY_H_
+#include "ASTNode.h"
+/*
+class ASTPrimary : public ASTNode {
+public:
+ ASTPrimary();
+ virtual ~ASTPrimary();
+ virtual void execute() {};
+
+};
+*/
+#endif /* ASTPRIMARY_H_ */
diff --git a/Sencha-lang/Debug/ASTNode.d b/Sencha-lang/Debug/ASTNode.d
new file mode 100644
index 0000000..67f81f1
--- /dev/null
+++ b/Sencha-lang/Debug/ASTNode.d
@@ -0,0 +1,3 @@
+ASTNode.d: ../ASTNode.cpp ../ASTNode.h
+
+../ASTNode.h:
diff --git a/Sencha-lang/Debug/ASTNode.o b/Sencha-lang/Debug/ASTNode.o
new file mode 100644
index 0000000..1126727
--- /dev/null
+++ b/Sencha-lang/Debug/ASTNode.o
Binary files differ
diff --git a/Sencha-lang/Debug/ASTPrimary.d b/Sencha-lang/Debug/ASTPrimary.d
new file mode 100644
index 0000000..896ae18
--- /dev/null
+++ b/Sencha-lang/Debug/ASTPrimary.d
@@ -0,0 +1,5 @@
+ASTPrimary.d: ../ASTPrimary.cpp ../ASTPrimary.h ../ASTNode.h
+
+../ASTPrimary.h:
+
+../ASTNode.h:
diff --git a/Sencha-lang/Debug/ASTPrimary.o b/Sencha-lang/Debug/ASTPrimary.o
new file mode 100644
index 0000000..9a095fe
--- /dev/null
+++ b/Sencha-lang/Debug/ASTPrimary.o
Binary files differ
diff --git a/Sencha-lang/Debug/Parser.o b/Sencha-lang/Debug/Parser.o
index e49040d..da49d5a 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 9617346..332a07c 100755
--- a/Sencha-lang/Debug/Sencha-lang
+++ b/Sencha-lang/Debug/Sencha-lang
Binary files differ
diff --git a/Sencha-lang/Debug/subdir.mk b/Sencha-lang/Debug/subdir.mk
index bd71042..e802321 100644
--- a/Sencha-lang/Debug/subdir.mk
+++ b/Sencha-lang/Debug/subdir.mk
@@ -4,6 +4,8 @@
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../ASTNode.cpp \
+../ASTPrimary.cpp \
../Lexer.cpp \
../Object.cpp \
../Parser.cpp \
@@ -11,6 +13,8 @@ CPP_SRCS += \
../main.cpp
OBJS += \
+./ASTNode.o \
+./ASTPrimary.o \
./Lexer.o \
./Object.o \
./Parser.o \
@@ -18,6 +22,8 @@ OBJS += \
./main.o
CPP_DEPS += \
+./ASTNode.d \
+./ASTPrimary.d \
./Lexer.d \
./Object.d \
./Parser.d \
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index 28bb26c..a268c8a 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -193,27 +193,33 @@ void Parser::prim_expr()
{
if(current_token.get_type() == t_integer)
{
- report("Number: " + tok_value + "\n");
+ report("Number: " + tok_value + "\n");
+ read_next();
}
else if(current_token.get_type() == t_symbol)
{
- report("Variable: " + tok_value + "\n");
+ report("Variable: " + tok_value + "\n");
+ read_next();
}
else if(current_token.get_type() == t_literal)
{
- report("Character literal: " + tok_value + "\n");
+ report("Character literal: " + tok_value + "\n");
+ read_next();
}
else if(accept("("))
- {
- expr();
- expect(")");
+ {
+ report("( ");
+ expr();
+ report(" ) ");
+ expect(")");
+
}
else
{
error("ERROR: unexpected primary expression" + tok_value + "\n");
-
+ read_next();
}
- read_next();
+
}
void Parser::postfix_expr()
@@ -236,25 +242,43 @@ void Parser::postfix_expr()
{
expr();
report("function argument\n");
- }
+ }
+
expect(")");
}
report("FUNC_CALL\n");
}
-}
+}
+
+void Parser::mul_expr()
+{
+ postfix_expr();
+ while(peek("*") || peek("/"))
+ {
+ if(accept("*"))
+ {
+ postfix_expr();
+ report(" *\n");
+ } else if(accept("/"))
+ {
+ postfix_expr();
+ report(" /\n");
+ }
+ }
+}
void Parser::add_expr()
{
- postfix_expr();
+ mul_expr();
while(peek("+") || peek("-"))
{
if(accept("+"))
{
- postfix_expr();
+ mul_expr();
report(" +\n");
} else if(accept("-"))
{
- postfix_expr();
+ mul_expr();
report(" -\n");
}
}
diff --git a/Sencha-lang/Parser.h b/Sencha-lang/Parser.h
index a60d7b1..4b9f484 100644
--- a/Sencha-lang/Parser.h
+++ b/Sencha-lang/Parser.h
@@ -33,7 +33,8 @@ class Parser
void report(string s);
void statement();
-
+
+ void mul_expr();
void add_expr();
void prim_expr();
void postfix_expr();