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 class ASTNode { public: ASTNode(); + ASTNode * parent; + std::vector 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 Binary files /dev/null and b/Sencha-lang/Debug/ASTNode.o 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 Binary files /dev/null and b/Sencha-lang/Debug/ASTPrimary.o differ diff --git a/Sencha-lang/Debug/Parser.o b/Sencha-lang/Debug/Parser.o index e49040d..da49d5a 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 9617346..332a07c 100755 Binary files a/Sencha-lang/Debug/Sencha-lang and b/Sencha-lang/Debug/Sencha-lang 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();