diff --git a/Sencha-lang/.cproject b/Sencha-lang/.cproject new file mode 100644 index 0000000..789856b --- /dev/null +++ b/Sencha-lang/.cproject @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sencha-lang/.project b/Sencha-lang/.project new file mode 100644 index 0000000..bf8cb98 --- /dev/null +++ b/Sencha-lang/.project @@ -0,0 +1,27 @@ + + + Sencha-lang + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Sencha-lang/Debug/Lexer.d b/Sencha-lang/Debug/Lexer.d new file mode 100644 index 0000000..b18b56a --- /dev/null +++ b/Sencha-lang/Debug/Lexer.d @@ -0,0 +1,5 @@ +Lexer.d: ../Lexer.cpp ../Lexer.h ../Token.h + +../Lexer.h: + +../Token.h: diff --git a/Sencha-lang/Debug/Lexer.o b/Sencha-lang/Debug/Lexer.o new file mode 100644 index 0000000..5669ddb Binary files /dev/null and b/Sencha-lang/Debug/Lexer.o differ diff --git a/Sencha-lang/Debug/Object.d b/Sencha-lang/Debug/Object.d new file mode 100644 index 0000000..686a90d --- /dev/null +++ b/Sencha-lang/Debug/Object.d @@ -0,0 +1,3 @@ +Object.d: ../Object.cpp ../Object.h + +../Object.h: diff --git a/Sencha-lang/Debug/Object.o b/Sencha-lang/Debug/Object.o new file mode 100644 index 0000000..27258de Binary files /dev/null and b/Sencha-lang/Debug/Object.o differ diff --git a/Sencha-lang/Debug/Parser.d b/Sencha-lang/Debug/Parser.d new file mode 100644 index 0000000..764149f --- /dev/null +++ b/Sencha-lang/Debug/Parser.d @@ -0,0 +1,5 @@ +Parser.d: ../Parser.cpp ../Parser.h ../Token.h + +../Parser.h: + +../Token.h: diff --git a/Sencha-lang/Debug/Parser.o b/Sencha-lang/Debug/Parser.o new file mode 100644 index 0000000..fe289e9 Binary files /dev/null and b/Sencha-lang/Debug/Parser.o differ diff --git a/Sencha-lang/Debug/Sencha-lang b/Sencha-lang/Debug/Sencha-lang new file mode 100755 index 0000000..0af2ca9 Binary files /dev/null and b/Sencha-lang/Debug/Sencha-lang differ diff --git a/Sencha-lang/Debug/Token.d b/Sencha-lang/Debug/Token.d new file mode 100644 index 0000000..36ba899 --- /dev/null +++ b/Sencha-lang/Debug/Token.d @@ -0,0 +1,3 @@ +Token.d: ../Token.cpp ../Token.h + +../Token.h: diff --git a/Sencha-lang/Debug/Token.o b/Sencha-lang/Debug/Token.o new file mode 100644 index 0000000..f39c463 Binary files /dev/null and b/Sencha-lang/Debug/Token.o differ diff --git a/Sencha-lang/Debug/lexer_tests.d b/Sencha-lang/Debug/lexer_tests.d new file mode 100644 index 0000000..3a73bf9 --- /dev/null +++ b/Sencha-lang/Debug/lexer_tests.d @@ -0,0 +1,3 @@ +lexer_tests.d: ../lexer_tests.cpp ../minunit.h + +../minunit.h: diff --git a/Sencha-lang/Debug/lexer_tests.o b/Sencha-lang/Debug/lexer_tests.o new file mode 100644 index 0000000..4d75f09 Binary files /dev/null and b/Sencha-lang/Debug/lexer_tests.o differ diff --git a/Sencha-lang/Debug/main.d b/Sencha-lang/Debug/main.d new file mode 100644 index 0000000..c96f175 --- /dev/null +++ b/Sencha-lang/Debug/main.d @@ -0,0 +1,7 @@ +main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h + +../Token.h: + +../Lexer.h: + +../Parser.h: diff --git a/Sencha-lang/Debug/main.o b/Sencha-lang/Debug/main.o new file mode 100644 index 0000000..8f998ca Binary files /dev/null and b/Sencha-lang/Debug/main.o differ diff --git a/Sencha-lang/Debug/makefile b/Sencha-lang/Debug/makefile new file mode 100644 index 0000000..1e20382 --- /dev/null +++ b/Sencha-lang/Debug/makefile @@ -0,0 +1,58 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +-include ../makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include subdir.mk +-include objects.mk + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(C++_DEPS)),) +-include $(C++_DEPS) +endif +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +ifneq ($(strip $(CC_DEPS)),) +-include $(CC_DEPS) +endif +ifneq ($(strip $(CPP_DEPS)),) +-include $(CPP_DEPS) +endif +ifneq ($(strip $(CXX_DEPS)),) +-include $(CXX_DEPS) +endif +ifneq ($(strip $(C_UPPER_DEPS)),) +-include $(C_UPPER_DEPS) +endif +endif + +-include ../makefile.defs + +# Add inputs and outputs from these tool invocations to the build variables + +# All Target +all: Sencha-lang + +# Tool invocations +Sencha-lang: $(OBJS) $(USER_OBJS) + @echo 'Building target: $@' + @echo 'Invoking: Cross G++ Linker' + g++ -o "Sencha-lang" $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building target: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(C++_DEPS)$(OBJS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) Sencha-lang + -@echo ' ' + +.PHONY: all clean dependents +.SECONDARY: + +-include ../makefile.targets diff --git a/Sencha-lang/Debug/objects.mk b/Sencha-lang/Debug/objects.mk new file mode 100644 index 0000000..742c2da --- /dev/null +++ b/Sencha-lang/Debug/objects.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := + diff --git a/Sencha-lang/Debug/sources.mk b/Sencha-lang/Debug/sources.mk new file mode 100644 index 0000000..c1514fd --- /dev/null +++ b/Sencha-lang/Debug/sources.mk @@ -0,0 +1,27 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +O_SRCS := +CPP_SRCS := +C_UPPER_SRCS := +C_SRCS := +S_UPPER_SRCS := +OBJ_SRCS := +ASM_SRCS := +CXX_SRCS := +C++_SRCS := +CC_SRCS := +C++_DEPS := +OBJS := +C_DEPS := +CC_DEPS := +CPP_DEPS := +EXECUTABLES := +CXX_DEPS := +C_UPPER_DEPS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/Sencha-lang/Debug/subdir.mk b/Sencha-lang/Debug/subdir.mk new file mode 100644 index 0000000..e26a52c --- /dev/null +++ b/Sencha-lang/Debug/subdir.mk @@ -0,0 +1,39 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../Lexer.cpp \ +../Object.cpp \ +../Parser.cpp \ +../Token.cpp \ +../lexer_tests.cpp \ +../main.cpp + +OBJS += \ +./Lexer.o \ +./Object.o \ +./Parser.o \ +./Token.o \ +./lexer_tests.o \ +./main.o + +CPP_DEPS += \ +./Lexer.d \ +./Object.d \ +./Parser.d \ +./Token.d \ +./lexer_tests.d \ +./main.d + + +# Each subdirectory must supply rules for building sources it contributes +%.o: ../%.cpp + @echo 'Building file: $<' + @echo 'Invoking: Cross G++ Compiler' + g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Sencha-lang/Lexer.cpp b/Sencha-lang/Lexer.cpp new file mode 100644 index 0000000..830066d --- /dev/null +++ b/Sencha-lang/Lexer.cpp @@ -0,0 +1,189 @@ +#include "Lexer.h" + +Lexer::Lexer() +{ + string keys[] = {"function", "class", "for", "while", "if", "else"}; + keywords.assign(keys, keys+6); + + char punct[] = {'.', ',', ';', '{', '}', '[', ']', '(', ')'}; + punctuation.assign(punct, punct+9); + + string oper[] = {"<", ">", "+", "-", "/", "*", "%", "&", "|", "=", ":", "==", "+=", "-=", "<=", ">=", "!=", "&&", "||"}; + operators.assign(oper, oper +19); +} + +Lexer::~Lexer() +{ + //dtor +} + +void Lexer::add_keyword(string word) +{ + if(!is_keyword(word)) + { + keywords.push_back(word); + } +} +void Lexer::add_punctuation_char(char c) +{ + if(!is_punctuation(c)) + { + punctuation.push_back(c); + } +} + +void Lexer::add_operator(string oper) +{ + if(!is_operator(oper)) + { + operators.push_back(oper); + } +} + + +vector Lexer::parse_line(string line) +{ + vector tokens; + while(line != "") + { + pair result_of_parsing = parse_token(line); + line = result_of_parsing.first; + Token token = result_of_parsing.second; + if(token.get_value() != "") + { + tokens.push_back(token); + } + } + return tokens; + +} + +pair Lexer::parse_token(string line) +{ + string token_value = ""; + unsigned int i; + bool in_char_literal = false; + for(i=0; i< line.size(); i++) + { + if(token_value == "" && isspace(line[i])) continue; + + if(isalnum(line[i]) || line[i] == '\"' || line[i]== '_') + { + token_value += line[i]; + if(line[i] == '\"') + { + if(in_char_literal) + { + in_char_literal = false; + } + else in_char_literal = true; + } + } + else if(ispunct(line[i])) + { + if(token_value=="") + { + token_value=line[i]; + i++; + if(i +#include +#include +#include +#include +#include "Token.h" + +using namespace std; +class Lexer +{ + public: + Lexer(); + virtual ~Lexer(); + + + + void add_keyword(string word); + void add_punctuation_char(char c); + void add_operator(string oper); + + vector parse_line(string line); + pair parse_token(string line); + type_of_token guess_type(string value); + + protected: + private: + + bool is_keyword(string value); + bool is_punctuation(char c); + bool is_operator(string value ); + + vector keywords; + vector punctuation; + vector operators; +}; + +#endif // LEXER_H diff --git a/Sencha-lang/Object.cpp b/Sencha-lang/Object.cpp new file mode 100644 index 0000000..0badd08 --- /dev/null +++ b/Sencha-lang/Object.cpp @@ -0,0 +1,12 @@ +#include "Object.h" + +Object::Object() +{ + number_value = 0; + //ctor +} + +Object::~Object() +{ + //dtor +} diff --git a/Sencha-lang/Object.h b/Sencha-lang/Object.h new file mode 100644 index 0000000..563cf7d --- /dev/null +++ b/Sencha-lang/Object.h @@ -0,0 +1,21 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include +//I don't know how should it look like! +class Object +{ + public: + Object(); + virtual ~Object(); + //Representation of the object + std::string str(); + //Type + std::string type(); + //Possible values + double number_value; + std::string characters; + protected: + private: +}; + +#endif // OBJECT_H diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp new file mode 100644 index 0000000..f0ef0dd --- /dev/null +++ b/Sencha-lang/Parser.cpp @@ -0,0 +1,295 @@ +#include "Parser.h" +#include "iostream" + +Parser::Parser(vector tokens) +{ + error_message = "***ERRORS DURING PARSING***\n"; + report_message = "***PARSER REPORT***\n"; + token_stream = tokens; + position_in_stream = 0; + read_next(); +} + +Parser::~Parser() +{ + //dtor +} + +void Parser::report(string s) +{ + report_message += s ; +} + +void Parser::error(string s) +{ + error_message += s ; +} + +bool Parser::read_next() +{ + if(position_in_stream < token_stream.size()) + { + current_token = token_stream[position_in_stream]; + tok_value = current_token.get_value(); + position_in_stream++; + return true; + } + else + { + current_token = Token(t_invalid_token, ""); + tok_value = current_token.get_value(); + return false; + } +} + +void Parser::interpret() +{ + while(tok_value!= "") + { + if(is_type()) + { + report("Identifier: " + tok_value + "\n"); + read_next(); + + if(accept("=")) + { + 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(","); + } + expect(")"); + + if(!accept(";")) + { + report("function body:\n"); + statement(); + } + } + + else { + report("Regular statement:\n"); + statement(); + } + } +} + +bool Parser::peek(string s) +{ + return tok_value == s; +} + +bool Parser::accept(string s) +{ + if(peek(s)) + { + read_next(); + return true; + } + else return false; +} + +bool Parser::expect(string s) +{ + if(!accept(s)) + { + string error_message = "Error: expected "; + error_message += s; + error_message += " but received: " + tok_value + "\n"; + + error(error_message); + return false; + } + else return true; +} + +bool Parser::is_type() +{ + if(current_token.get_type() == t_symbol || current_token.get_type() == t_keyword) + { + if(tok_value == "def" || tok_value == "string" || tok_value == "num") + { + read_next(); + return true; + } + else return false; + + } + else return false; +} + +void Parser::statement() +{ + if(accept("{")) + { + while(!accept("}")) + { + statement(); + } + } + else if(is_type()) + { + report("Local variable: " + tok_value + "\n"); + read_next(); + if(accept("=")) + { + expr(); + report(" :=\n"); + } + expect(";"); + } + else if(accept("if")) + { + //stuff + //TODO implement that + } + else if(accept("while")) + { + //similar stuff + } + else if(accept("return")) + { + + if(!peek(";")) + { + expr(); + } + expect(";"); + report("RETURN\n"); + + } + else + { + expr(); + while(!expect(";")) read_next(); + + } +} + +void Parser::prim_expr() +{ + if(current_token.get_type() == t_integer) + { + report("Number: " + tok_value + "\n"); + } + else if(current_token.get_type() == t_symbol) + { + report("Variable: " + tok_value + "\n"); + } + else if(current_token.get_type() == t_literal) + { + report("Character literal: " + tok_value + "\n"); + } + else if(accept("(")) + { + expr(); + expect(")"); + } + else + { + error("ERROR: unexpected primary expression" + tok_value + "\n"); + + } + read_next(); +} + +void Parser::postfix_expr() +{ + prim_expr(); + if(accept("[")) + { + expr(); + expect("]"); + report(" [] "); + + } + else if(accept("(")) + { + if(!accept(")")) + { + expr(); + report("function argument\n"); + while(accept(",")) + { + expr(); + report("function argument\n"); + } + expect(")"); + } + report("FUNC_CALL\n"); + } +} + +void Parser::add_expr() +{ + postfix_expr(); + while(peek("+") || peek("-")) + { + if(accept("+")) + { + postfix_expr(); + report(" +\n"); + } else if(accept("-")) + { + postfix_expr(); + report(" -\n"); + } + } +} + +void Parser::rel_expr() +{ + add_expr(); + while(peek("<")) + { + accept("<"); + add_expr(); + report(" <\n"); + } +} + +void Parser::eq_expr() +{ + rel_expr(); + while(peek("==") || peek("!=")) + { + if(accept("==")) + { + rel_expr(); + report("==\n"); + } + else if(accept("!=")) + { + rel_expr(); + report("!=\n"); + } + } +} + +void Parser::expr() +{ + eq_expr(); + if(accept("=")) + { + expr(); + report(" := "); + } +} diff --git a/Sencha-lang/Parser.h b/Sencha-lang/Parser.h new file mode 100644 index 0000000..a60d7b1 --- /dev/null +++ b/Sencha-lang/Parser.h @@ -0,0 +1,45 @@ +#ifndef PARSER_H +#define PARSER_H +#include +#include +#include "Token.h" + + +using namespace std; +class Parser +{ + public: + Parser(vector tokens); + virtual ~Parser(); + void interpret(); + string report_message; + string error_message; + + + protected: + private: + Token current_token; + string tok_value; + vector token_stream; + int position_in_stream; + + bool read_next(); + bool peek(string s); + bool accept(string s); + bool expect(string s); + bool is_type(); + + void error(string s); + void report(string s); + + void statement(); + + void add_expr(); + void prim_expr(); + void postfix_expr(); + void rel_expr(); + void eq_expr(); + void expr(); +}; + +#endif // PARSER_H diff --git a/Sencha-lang/Token.cpp b/Sencha-lang/Token.cpp new file mode 100644 index 0000000..873f4e7 --- /dev/null +++ b/Sencha-lang/Token.cpp @@ -0,0 +1,2 @@ +#include "Token.h" + diff --git a/Sencha-lang/Token.h b/Sencha-lang/Token.h new file mode 100644 index 0000000..7c3552f --- /dev/null +++ b/Sencha-lang/Token.h @@ -0,0 +1,25 @@ +#ifndef TOKEN_H +#define TOKEN_H +#include + + +using namespace std; + +typedef enum { t_invalid_token=0, t_symbol, t_integer, t_literal, + t_punctuation, t_keyword, t_operator, t_float } type_of_token; //t_float not implemented + //TODO implement t_float in lexer + + +class Token +{ + public: + type_of_token type; + string value; + Token() : type(t_invalid_token), value("") {}; + Token(type_of_token type, string value) : type(type), value(value) { }; + type_of_token get_type() { return type; }; + string get_value() { return value; }; + +}; + +#endif // TOKEN_H diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp new file mode 100644 index 0000000..a0fea6d --- /dev/null +++ b/Sencha-lang/main.cpp @@ -0,0 +1,58 @@ +#include +#include +#include "Token.h" +#include "Lexer.h" +#include "Parser.h" + +using namespace std; + +void test_lexer() +{ + string test_line = "def i; bulb; i + 3; string banan; banan = \"banan and other stuff\"; string kaboom(num how_many_times) { def z; }"; + 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 tokens = lexer.parse_line(test_line); + + + for(int i=0; i< tokens.size(); i++) + { + cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl; + } + + + 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 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 tokens; + for(int i=0; i>>" << endl; + cout << "Instructions: " << endl ; + cout << lines[i] << endl << endl; + cout << parser.report_message; + cout << parser.error_message << endl; + } + +} +int main() +{ + cout << "Hello world!" << endl; + test_parser(); + //test_lexer(); + return 0; +} diff --git a/Sencha-lang/minunit.h b/Sencha-lang/minunit.h new file mode 100644 index 0000000..948933e --- /dev/null +++ b/Sencha-lang/minunit.h @@ -0,0 +1,17 @@ +/* + * minunit.h + * + * Created on: Nov 2, 2012 + * Author: attero + */ + +#ifndef MINUNIT_H_ +#define MINUNIT_H_ + +#define mu_assert(message, test) do { if (!(test)) return message; } while (0) +#define mu_run_test(test) do { char *message = test(); tests_run++; \ + if (message) return message; } while (0) +extern int tests_run; + + +#endif /* MINUNIT_H_ */ diff --git a/sencha/.cproject b/sencha/.cproject new file mode 100644 index 0000000..9b14996 --- /dev/null +++ b/sencha/.cproject @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + + sencha + true + true + true + + + + diff --git a/sencha/.project b/sencha/.project new file mode 100644 index 0000000..c28b133 --- /dev/null +++ b/sencha/.project @@ -0,0 +1,27 @@ + + + sencha + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/sencha/Object.cpp b/sencha/Object.cpp new file mode 100644 index 0000000..0badd08 --- /dev/null +++ b/sencha/Object.cpp @@ -0,0 +1,12 @@ +#include "Object.h" + +Object::Object() +{ + number_value = 0; + //ctor +} + +Object::~Object() +{ + //dtor +} diff --git a/sencha/Object.h b/sencha/Object.h new file mode 100644 index 0000000..563cf7d --- /dev/null +++ b/sencha/Object.h @@ -0,0 +1,21 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include +//I don't know how should it look like! +class Object +{ + public: + Object(); + virtual ~Object(); + //Representation of the object + std::string str(); + //Type + std::string type(); + //Possible values + double number_value; + std::string characters; + protected: + private: +}; + +#endif // OBJECT_H diff --git a/sencha/Parser.cpp b/sencha/Parser.cpp index 8819368..f0ef0dd 100644 --- a/sencha/Parser.cpp +++ b/sencha/Parser.cpp @@ -90,7 +90,8 @@ void Parser::interpret() statement(); } } -} +} + bool Parser::peek(string s) { return tok_value == s; diff --git a/sencha/Parser.h b/sencha/Parser.h index 67c2a8a..a60d7b1 100644 --- a/sencha/Parser.h +++ b/sencha/Parser.h @@ -4,6 +4,7 @@ #include #include "Token.h" + using namespace std; class Parser { @@ -13,6 +14,7 @@ class Parser void interpret(); string report_message; string error_message; + protected: private: diff --git a/sencha/bin/Debug/sencha b/sencha/bin/Debug/sencha index 01afe6b..3a9a346 100755 Binary files a/sencha/bin/Debug/sencha and b/sencha/bin/Debug/sencha differ diff --git a/sencha/lexer_tests.cpp b/sencha/lexer_tests.cpp new file mode 100644 index 0000000..0e60145 --- /dev/null +++ b/sencha/lexer_tests.cpp @@ -0,0 +1,33 @@ +/* + * lexer_tests.cpp + * + * Created on: Nov 2, 2012 + * Author: attero + */ + +#include + #include "minunit.h" + + int tests_run = 0; + + int foo = 7; + int bar = 4; + + static char * test_foo() { + mu_assert("error, foo != 7", foo == 7); + return 0; + } + + static char * test_bar() { + mu_assert("error, bar != 5", bar == 5); + return 0; + } + + static char * all_tests() { + mu_run_test(test_foo); + mu_run_test(test_bar); + return 0; + } + + + diff --git a/sencha/main.cpp b/sencha/main.cpp index ffac51e..a16febd 100644 --- a/sencha/main.cpp +++ b/sencha/main.cpp @@ -53,6 +53,6 @@ int main() { cout << "Hello world!" << endl; //test_parser(); - test_lexer(); + //test_lexer(); return 0; } diff --git a/sencha/minunit.h b/sencha/minunit.h new file mode 100644 index 0000000..948933e --- /dev/null +++ b/sencha/minunit.h @@ -0,0 +1,17 @@ +/* + * minunit.h + * + * Created on: Nov 2, 2012 + * Author: attero + */ + +#ifndef MINUNIT_H_ +#define MINUNIT_H_ + +#define mu_assert(message, test) do { if (!(test)) return message; } while (0) +#define mu_run_test(test) do { char *message = test(); tests_run++; \ + if (message) return message; } while (0) +extern int tests_run; + + +#endif /* MINUNIT_H_ */ diff --git a/sencha/obj/Debug/AppleTree.o b/sencha/obj/Debug/AppleTree.o new file mode 100644 index 0000000..09f8c83 Binary files /dev/null and b/sencha/obj/Debug/AppleTree.o differ diff --git a/sencha/obj/Debug/Fruit.o b/sencha/obj/Debug/Fruit.o new file mode 100644 index 0000000..06e5613 Binary files /dev/null and b/sencha/obj/Debug/Fruit.o differ diff --git a/sencha/obj/Debug/FruitBasket.o b/sencha/obj/Debug/FruitBasket.o new file mode 100644 index 0000000..3d30ad4 Binary files /dev/null and b/sencha/obj/Debug/FruitBasket.o differ diff --git a/sencha/obj/Debug/Parser.o b/sencha/obj/Debug/Parser.o index bc1546e..d66f6f1 100644 Binary files a/sencha/obj/Debug/Parser.o and b/sencha/obj/Debug/Parser.o differ diff --git a/sencha/obj/Debug/main.o b/sencha/obj/Debug/main.o index 6b14372..9283049 100644 Binary files a/sencha/obj/Debug/main.o and b/sencha/obj/Debug/main.o differ diff --git a/sencha/sencha.cbp b/sencha/sencha.cbp index 74f90a5..0fca531 100644 --- a/sencha/sencha.cbp +++ b/sencha/sencha.cbp @@ -32,6 +32,12 @@ + + + + + + diff --git a/sencha/sencha.depend b/sencha/sencha.depend index 15329e2..2c7fa6d 100644 --- a/sencha/sencha.depend +++ b/sencha/sencha.depend @@ -5,7 +5,7 @@ 1351424620 /home/attero/development/sencha-lang/sencha/Token.h -1351540082 source:/home/attero/development/sencha-lang/sencha/Lexer.cpp +1351540959 source:/home/attero/development/sencha-lang/sencha/Lexer.cpp "Lexer.h" 1351539503 /home/attero/development/sencha-lang/sencha/Lexer.h @@ -16,7 +16,7 @@ "Token.h" -1351539590 source:/home/attero/development/sencha-lang/sencha/main.cpp +1351541355 source:/home/attero/development/sencha-lang/sencha/main.cpp "Token.h" @@ -27,13 +27,28 @@ "Parser.h" "iostream" -1351539525 /home/attero/development/sencha-lang/sencha/Parser.h +1351543306 /home/attero/development/sencha-lang/sencha/Parser.h "Token.h" + "Fruit.h" + "FruitBasket.h" 1351512311 source:/home/attero/development/sencha-lang/sencha/AppleTree.cpp "AppleTree.h" 1351512311 /home/attero/development/sencha-lang/sencha/AppleTree.h +1351543287 /home/attero/development/sencha-lang/sencha/Fruit.h + + +1351543266 source:/home/attero/development/sencha-lang/sencha/Fruit.cpp + "Fruit.h" + +1351542956 source:/home/attero/development/sencha-lang/sencha/FruitBasket.cpp + "FruitBasket.h" + +1351543037 /home/attero/development/sencha-lang/sencha/FruitBasket.h + + "Fruit.h" + diff --git a/sencha/sencha.layout b/sencha/sencha.layout index cd2740c..3c31c4a 100644 --- a/sencha/sencha.layout +++ b/sencha/sencha.layout @@ -1,14 +1,20 @@ + + + - + - + - - + + + + + @@ -16,7 +22,7 @@ - - + +