Bug with brackets in parsing resolved.

devel
Justyna Att Ilczuk 2012-11-04 17:16:02 +01:00
parent 8dc5802c2b
commit 4cec642234
13 changed files with 100 additions and 15 deletions

View File

@ -9,7 +9,7 @@
ASTNode::ASTNode() {
// TODO Auto-generated constructor stub
parent = 0;
}
ASTNode::~ASTNode() {

View File

@ -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();
};

View File

@ -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
}
*/

20
Sencha-lang/ASTPrimary.h Normal file
View File

@ -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_ */

View File

@ -0,0 +1,3 @@
ASTNode.d: ../ASTNode.cpp ../ASTNode.h
../ASTNode.h:

BIN
Sencha-lang/Debug/ASTNode.o Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
ASTPrimary.d: ../ASTPrimary.cpp ../ASTPrimary.h ../ASTNode.h
../ASTPrimary.h:
../ASTNode.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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 \

View File

@ -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");
}
}

View File

@ -33,7 +33,8 @@ class Parser
void report(string s);
void statement();
void mul_expr();
void add_expr();
void prim_expr();
void postfix_expr();