summaryrefslogtreecommitdiffstats
path: root/Sencha-lang
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-30 14:59:30 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-30 14:59:30 +0100
commit39794ea7111f2508e8dc7504de4396bc570da03e (patch)
tree45e28bf95007405037f3d0d464787f574e30a6de /Sencha-lang
parent93a63d43e950c53230c1658e86111ee962faf7f9 (diff)
downloadsencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.gz
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.bz2
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.xz
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.zip
I began implementing function functionality and I apply some changes to
whole design.
Diffstat (limited to 'Sencha-lang')
-rw-r--r--Sencha-lang/.cproject139
-rw-r--r--Sencha-lang/AST/ASTNode.h2
-rw-r--r--Sencha-lang/AST/Assignment.cpp2
-rw-r--r--Sencha-lang/AST/Assignment.h6
-rw-r--r--Sencha-lang/AST/ConstantExpression.h2
-rw-r--r--Sencha-lang/AST/DeclarationStatement.cpp2
-rw-r--r--Sencha-lang/AST/DeclarationStatement.h6
-rw-r--r--Sencha-lang/AST/PostfixExpression.cpp2
-rw-r--r--Sencha-lang/AST/PostfixExpression.h6
-rw-r--r--Sencha-lang/AST/VariableExpression.cpp2
-rw-r--r--Sencha-lang/AST/VariableExpression.h6
-rw-r--r--Sencha-lang/ContextManager.cpp (renamed from Sencha-lang/Context.cpp)22
-rw-r--r--Sencha-lang/ContextManager.h (renamed from Sencha-lang/Context.h)8
-rw-r--r--Sencha-lang/Elements/Element.cpp20
-rw-r--r--Sencha-lang/Elements/Element.h18
-rw-r--r--Sencha-lang/Elements/SenchaFunction.cpp19
-rw-r--r--Sencha-lang/Elements/SenchaFunction.h32
-rw-r--r--Sencha-lang/Elements/SenchaObject.cpp (renamed from Sencha-lang/AST/SenchaObject.cpp)42
-rw-r--r--Sencha-lang/Elements/SenchaObject.h (renamed from Sencha-lang/AST/SenchaObject.h)58
-rw-r--r--Sencha-lang/Parser.cpp3
-rw-r--r--Sencha-lang/Parser.h6
-rw-r--r--Sencha-lang/Tests/TestParser.cpp14
-rw-r--r--Sencha-lang/Tests/TestParser.h2
-rw-r--r--Sencha-lang/Utils/to_string.h (renamed from Sencha-lang/AST/to_string.h)0
-rw-r--r--Sencha-lang/main.cpp11
25 files changed, 199 insertions, 231 deletions
diff --git a/Sencha-lang/.cproject b/Sencha-lang/.cproject
deleted file mode 100644
index 7335ba0..0000000
--- a/Sencha-lang/.cproject
+++ /dev/null
@@ -1,139 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
- <storageModule moduleId="org.eclipse.cdt.core.settings">
- <cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496">
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496" moduleId="org.eclipse.cdt.core.settings" name="Debug">
- <externalSettings/>
- <extensions>
- <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
- <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- </extensions>
- </storageModule>
- <storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496" name="Debug" parent="cdt.managedbuild.config.gnu.cross.exe.debug">
- <folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496." name="/" resourcePath="">
- <toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.2045041315" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
- <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1733237476" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
- <builder buildPath="${workspace_loc:/Sencha-lang/Debug}" id="cdt.managedbuild.builder.gnu.cross.2091580062" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.builder.gnu.cross"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1055356392" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
- <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.758256537" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
- <option id="gnu.c.compiler.option.debugging.level.1319397326" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
- <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.809384772" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.495732557" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
- <option id="gnu.cpp.compiler.option.optimization.level.793014755" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
- <option id="gnu.cpp.compiler.option.debugging.level.1513381051" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
- <option id="gnu.cpp.compiler.option.other.other.335578218" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -std=gnu++0x " valueType="string"/>
- <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.859439950" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.linker.693029150" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1545256246" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
- <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1240442083" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
- <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
- <additionalInput kind="additionalinput" paths="$(LIBS)"/>
- </inputType>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.archiver.973026492" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.assembler.1898223694" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
- <inputType id="cdt.managedbuild.tool.gnu.assembler.input.415327363" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
- </tool>
- </toolChain>
- </folderInfo>
- <sourceEntries>
- <entry excluding="AST|Tests" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
- <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="AST"/>
- <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Tests"/>
- </sourceEntries>
- </configuration>
- </storageModule>
- <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
- </cconfiguration>
- <cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.release.1985450505">
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.1985450505" moduleId="org.eclipse.cdt.core.settings" name="Release">
- <externalSettings/>
- <extensions>
- <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
- <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- </extensions>
- </storageModule>
- <storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.1985450505" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release">
- <folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.1985450505." name="/" resourcePath="">
- <toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1226114014" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
- <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.676474921" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
- <builder buildPath="${workspace_loc:/Sencha-lang/Release}" id="cdt.managedbuild.builder.gnu.cross.23375219" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.671993191" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
- <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1104799874" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
- <option id="gnu.c.compiler.option.debugging.level.1423670337" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
- <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1507898701" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.938543294" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
- <option id="gnu.cpp.compiler.option.optimization.level.491096180" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
- <option id="gnu.cpp.compiler.option.debugging.level.1816198684" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
- <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.599623873" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1203418436" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.860949532" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
- <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.124143498" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
- <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
- <additionalInput kind="additionalinput" paths="$(LIBS)"/>
- </inputType>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.archiver.1698336651" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.assembler.1350015407" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
- <inputType id="cdt.managedbuild.tool.gnu.assembler.input.949134942" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
- </tool>
- </toolChain>
- </folderInfo>
- </configuration>
- </storageModule>
- <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
- </cconfiguration>
- </storageModule>
- <storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <project id="Sencha-lang.cdt.managedbuild.target.gnu.cross.exe.1970449863" name="Executable" projectType="cdt.managedbuild.target.gnu.cross.exe"/>
- </storageModule>
- <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
- <storageModule moduleId="refreshScope" versionNumber="2">
- <configuration configurationName="Release">
- <resource resourceType="PROJECT" workspacePath="/Sencha-lang"/>
- </configuration>
- <configuration configurationName="Debug">
- <resource resourceType="PROJECT" workspacePath="/Sencha-lang"/>
- </configuration>
- </storageModule>
- <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
- <storageModule moduleId="scannerConfiguration">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
- <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.1985450505;cdt.managedbuild.config.gnu.cross.exe.release.1985450505.;cdt.managedbuild.tool.gnu.cross.c.compiler.671993191;cdt.managedbuild.tool.gnu.c.compiler.input.1507898701">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
- </scannerConfigBuildInfo>
- <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.1985450505;cdt.managedbuild.config.gnu.cross.exe.release.1985450505.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.938543294;cdt.managedbuild.tool.gnu.cpp.compiler.input.599623873">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
- </scannerConfigBuildInfo>
- <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496;cdt.managedbuild.config.gnu.cross.exe.debug.1544392496.;cdt.managedbuild.tool.gnu.cross.c.compiler.1055356392;cdt.managedbuild.tool.gnu.c.compiler.input.809384772">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
- </scannerConfigBuildInfo>
- <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.1544392496;cdt.managedbuild.config.gnu.cross.exe.debug.1544392496.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.495732557;cdt.managedbuild.tool.gnu.cpp.compiler.input.859439950">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
- <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
- <buildOutputProvider>
- <openAction enabled="true" filePath=""/>
- <parser enabled="true"/>
- </buildOutputProvider>
- <scannerInfoProvider id="specsFile">
- <runAction arguments="-E -P -g -v -dD &quot;${plugin_state_location}/specs.cpp&quot;" command="g++" useDefault="true"/>
- <parser enabled="true"/>
- </scannerInfoProvider>
- </profile>
- </scannerConfigBuildInfo>
- </storageModule>
-</cproject>
diff --git a/Sencha-lang/AST/ASTNode.h b/Sencha-lang/AST/ASTNode.h
index 7c27b26..45666a4 100644
--- a/Sencha-lang/AST/ASTNode.h
+++ b/Sencha-lang/AST/ASTNode.h
@@ -9,7 +9,7 @@
#define ASTNODE_H_
#include <vector>
#include <string>
-#include "SenchaObject.h"
+#include "../Elements/SenchaObject.h"
#include "../Visitor.h"
diff --git a/Sencha-lang/AST/Assignment.cpp b/Sencha-lang/AST/Assignment.cpp
index a74d166..e8eaf18 100644
--- a/Sencha-lang/AST/Assignment.cpp
+++ b/Sencha-lang/AST/Assignment.cpp
@@ -36,7 +36,7 @@ void Assignment::execute_quietly()
}
}
-Assignment::Assignment(Context * context, std::string name, ASTExpression * left, ASTExpression * right)
+Assignment::Assignment(ContextManager * context, std::string name, ASTExpression * left, ASTExpression * right)
{
this->context = context;
this->type = "Assignment";
diff --git a/Sencha-lang/AST/Assignment.h b/Sencha-lang/AST/Assignment.h
index 55a79c3..d3f1cae 100644
--- a/Sencha-lang/AST/Assignment.h
+++ b/Sencha-lang/AST/Assignment.h
@@ -9,7 +9,7 @@
#define ASSIGNMENT_H_
#include <string>
#include "ASTExpression.h"
-#include "../Context.h"
+#include "../ContextManager.h"
/**
* Assignment is an abstraction of assignment.
* It is different from i.e BasicExpression so that it change value of the lvalue
@@ -22,14 +22,14 @@
*/
class Assignment : public ASTExpression {
public:
- Context * context;
+ ContextManager * context;
std::string name;
SenchaObject evaluate();
void execute();
void execute_quietly();
- Assignment(Context * context, std::string name, ASTExpression * left, ASTExpression * right);
+ Assignment(ContextManager * context, std::string name, ASTExpression * left, ASTExpression * right);
virtual ~Assignment();
};
diff --git a/Sencha-lang/AST/ConstantExpression.h b/Sencha-lang/AST/ConstantExpression.h
index e55660b..72cf8d2 100644
--- a/Sencha-lang/AST/ConstantExpression.h
+++ b/Sencha-lang/AST/ConstantExpression.h
@@ -9,7 +9,7 @@
#define CONSTANTEXPRESSION_H_
#include "ASTExpression.h"
#include <iostream>
-#include "../Context.h"
+
/**
* ConstantExpression class is used to store complex expression, which are actually
diff --git a/Sencha-lang/AST/DeclarationStatement.cpp b/Sencha-lang/AST/DeclarationStatement.cpp
index 406e5bf..eb92407 100644
--- a/Sencha-lang/AST/DeclarationStatement.cpp
+++ b/Sencha-lang/AST/DeclarationStatement.cpp
@@ -27,7 +27,7 @@ void DeclarationStatement::add_right_value(ASTExpression * right)
children[0] = right;
}
-DeclarationStatement::DeclarationStatement(Context * context)
+DeclarationStatement::DeclarationStatement(ContextManager * context)
{
this->context = context;
is_function = false;
diff --git a/Sencha-lang/AST/DeclarationStatement.h b/Sencha-lang/AST/DeclarationStatement.h
index 0fdb51b..021c6a9 100644
--- a/Sencha-lang/AST/DeclarationStatement.h
+++ b/Sencha-lang/AST/DeclarationStatement.h
@@ -11,7 +11,7 @@
#include "ASTStatement.h"
#include "ASTExpression.h"
#include "ConstantExpression.h"
-#include "../Context.h"
+#include "../ContextManager.h"
/**
* DeclarationStatement is abstraction of declaration/definition
@@ -21,14 +21,14 @@
class DeclarationStatement: public ASTStatement {
public:
std::string name;
- Context * context;
+ ContextManager * context;
SenchaObject right_value;
ASTStatement * body;
std::vector<std::string> arguments;
bool is_function;
void add_right_value(ASTExpression * right);
- DeclarationStatement(Context * context);
+ DeclarationStatement(ContextManager * context);
void add_name(std::string);
diff --git a/Sencha-lang/AST/PostfixExpression.cpp b/Sencha-lang/AST/PostfixExpression.cpp
index 7ca535f..337e87c 100644
--- a/Sencha-lang/AST/PostfixExpression.cpp
+++ b/Sencha-lang/AST/PostfixExpression.cpp
@@ -7,7 +7,7 @@
#include "PostfixExpression.h"
-PostfixExpression::PostfixExpression(std::string name, Context * context):
+PostfixExpression::PostfixExpression(std::string name, ContextManager * context):
name(name), context(context), native(false)
{
type= "PostfixExpression";
diff --git a/Sencha-lang/AST/PostfixExpression.h b/Sencha-lang/AST/PostfixExpression.h
index 42b8fbe..73b6764 100644
--- a/Sencha-lang/AST/PostfixExpression.h
+++ b/Sencha-lang/AST/PostfixExpression.h
@@ -9,7 +9,7 @@
#define POSTFIXEXPRESSION_H_
#include "ASTExpression.h"
#include "ASTStatement.h"
-#include "../Context.h"
+#include "../ContextManager.h"
/**
* PostfixExpression is in current implementation an abstraction
@@ -18,7 +18,7 @@
class PostfixExpression : public ASTExpression {
public:
std::string name;
- Context * context;
+ ContextManager * context;
bool native;
std::vector<ASTExpression *> arguments;
void add_argument(ASTExpression * expression);
@@ -27,7 +27,7 @@ public:
virtual void execute();
virtual void execute_quietly(){ execute();};
- PostfixExpression( std::string name, Context * context);
+ PostfixExpression( std::string name, ContextManager * context);
virtual ~PostfixExpression();
};
diff --git a/Sencha-lang/AST/VariableExpression.cpp b/Sencha-lang/AST/VariableExpression.cpp
index fafec2e..5ab8951 100644
--- a/Sencha-lang/AST/VariableExpression.cpp
+++ b/Sencha-lang/AST/VariableExpression.cpp
@@ -7,7 +7,7 @@
#include "VariableExpression.h"
-VariableExpression::VariableExpression(std::string name, Context * context) {
+VariableExpression::VariableExpression(std::string name, ContextManager * context) {
this->name = name;
this->context = context;
this->type = "VariableExpression";
diff --git a/Sencha-lang/AST/VariableExpression.h b/Sencha-lang/AST/VariableExpression.h
index add5190..af664e9 100644
--- a/Sencha-lang/AST/VariableExpression.h
+++ b/Sencha-lang/AST/VariableExpression.h
@@ -9,7 +9,7 @@
#define VARIABLEEXPRESSION_H_
#include <iostream>
#include <string>
-#include "../Context.h"
+#include "../ContextManager.h"
#include "ASTExpression.h"
/**
@@ -19,9 +19,9 @@
class VariableExpression: public ASTExpression {
public:
VariableExpression();
- VariableExpression(std::string name, Context * context);
+ VariableExpression(std::string name, ContextManager * context);
- Context * context;
+ ContextManager * context;
std::string name;
void execute();
diff --git a/Sencha-lang/Context.cpp b/Sencha-lang/ContextManager.cpp
index 6d9face..3a753d9 100644
--- a/Sencha-lang/Context.cpp
+++ b/Sencha-lang/ContextManager.cpp
@@ -5,21 +5,21 @@
* Author: attero
*/
-#include "Context.h"
+#include "ContextManager.h"
-Context::Context() {
+ContextManager::ContextManager() {
index = 0;
}
-Context::~Context() {
+ContextManager::~ContextManager() {
}
-void Context::register_function(std::string name, PointerToNativeFunction f)
+void ContextManager::register_function(std::string name, PointerToNativeFunction f)
{
registered_functions[name] = f;
}
-SenchaObject Context::execute_native_function(std::string name, std::vector<ASTExpression *> arguments)
+SenchaObject ContextManager::execute_native_function(std::string name, std::vector<ASTExpression *> arguments)
{
SenchaObject result;
if(registered_functions.count(name) == 1)
@@ -27,7 +27,7 @@ SenchaObject Context::execute_native_function(std::string name, std::vector<ASTE
return result;
}
-ObjectIndex Context::add_to_store(SenchaObject & object)
+ObjectIndex ContextManager::add_to_store(SenchaObject & object)
{
index++;
object_store[index] = object;
@@ -35,17 +35,17 @@ ObjectIndex Context::add_to_store(SenchaObject & object)
return index;
}
-SenchaObject Context::get_from_store(ObjectIndex index)
+SenchaObject ContextManager::get_from_store(ObjectIndex index)
{
return object_store[index];
}
-void Context::add(std::string name, SenchaObject object)
+void ContextManager::add(std::string name, SenchaObject object)
{
interpreter_context[name] = add_to_store(object);
}
-void Context::set(std::string name, SenchaObject object)
+void ContextManager::set(std::string name, SenchaObject object)
{
if(interpreter_context[name] != 0)
{
@@ -58,12 +58,12 @@ void Context::set(std::string name, SenchaObject object)
}
}
-SenchaObject Context::get(std::string name)
+SenchaObject ContextManager::get(std::string name)
{
return get_from_store(interpreter_context[name]);
}
-std::string Context::debug() {
+std::string ContextManager::debug() {
std::string debug_note = "";
for( auto iter = this->interpreter_context.begin(); iter != this->interpreter_context.end(); iter++)
diff --git a/Sencha-lang/Context.h b/Sencha-lang/ContextManager.h
index 873de02..81bcba2 100644
--- a/Sencha-lang/Context.h
+++ b/Sencha-lang/ContextManager.h
@@ -11,16 +11,16 @@
#include <vector>
#include <string>
#include <iostream>
-#include "AST/SenchaObject.h"
+#include "Elements/SenchaObject.h"
#include "AST/ASTExpression.h"
typedef unsigned long ObjectIndex;
typedef unsigned long FunctionIndex;
-class Context {
+class ContextManager {
public:
- Context();
+ ContextManager();
typedef unsigned long ObjectIndex;
ObjectIndex index;
@@ -49,7 +49,7 @@ public:
ExecutionContext global_context;
std::map<FunctionIndex , ExecutionContext *> function_contexts;
- virtual ~Context();
+ virtual ~ContextManager();
};
#endif /* CONTEXT_H_ */
diff --git a/Sencha-lang/Elements/Element.cpp b/Sencha-lang/Elements/Element.cpp
new file mode 100644
index 0000000..05241f3
--- /dev/null
+++ b/Sencha-lang/Elements/Element.cpp
@@ -0,0 +1,20 @@
+/*
+ * Element.cpp
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#include "Element.h"
+
+Element::Element()
+{
+ // TODO Auto-generated constructor stub
+
+}
+
+Element::~Element()
+{
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/Sencha-lang/Elements/Element.h b/Sencha-lang/Elements/Element.h
new file mode 100644
index 0000000..3377c9a
--- /dev/null
+++ b/Sencha-lang/Elements/Element.h
@@ -0,0 +1,18 @@
+/*
+ * Element.h
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#ifndef ELEMENT_H_
+#define ELEMENT_H_
+
+class Element
+{
+public:
+ Element();
+ virtual ~Element();
+};
+
+#endif /* ELEMENT_H_ */
diff --git a/Sencha-lang/Elements/SenchaFunction.cpp b/Sencha-lang/Elements/SenchaFunction.cpp
new file mode 100644
index 0000000..dfbf428
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaFunction.cpp
@@ -0,0 +1,19 @@
+/*
+ * SenchaFunction.cpp
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#include "SenchaFunction.h"
+
+SenchaFunction::SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body, Context * context)
+ : name(name), names_of_arguments(names_of_arguments), body(body), context(context)
+{
+
+}
+
+SenchaFunction::~SenchaFunction() {
+
+}
+
diff --git a/Sencha-lang/Elements/SenchaFunction.h b/Sencha-lang/Elements/SenchaFunction.h
new file mode 100644
index 0000000..7185ebb
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaFunction.h
@@ -0,0 +1,32 @@
+/*
+ * SenchaFunction.h
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#ifndef SENCHAFUNCTION_H_
+#define SENCHAFUNCTION_H_
+#include <string>
+#include <iostream>
+#include <vector>
+#include <SenchaObject.h>
+#include "Element.h"
+#include "../Utils/to_string.h"
+#include "../Context.h"
+#include "../AST/ASTNode.h"
+
+
+class SenchaFunction : public Element
+{
+public:
+ std::string name;
+ std::vector<std::string> names_of_arguments;
+ ASTNode * body;
+ Context * context;
+
+ SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body, Context * context);
+ virtual ~SenchaFunction();
+};
+
+#endif /* SENCHAFUNCTION_H_ */
diff --git a/Sencha-lang/AST/SenchaObject.cpp b/Sencha-lang/Elements/SenchaObject.cpp
index 61930dc..56af04c 100644
--- a/Sencha-lang/AST/SenchaObject.cpp
+++ b/Sencha-lang/Elements/SenchaObject.cpp
@@ -25,6 +25,48 @@ bool SenchaObject::is_true()
else return true;
}
+
+void SenchaObject::set_value(std::string text)
+{
+ if(text[0] == '\"' && text[text.size()-1] == '\"')
+ {
+ this->text = text.substr(1, text.size()-2);
+ type = string_literal;
+ }
+}
+
+void SenchaObject::set_new_string(std::string text)
+{
+ this->text = text;
+ type = string_literal;
+}
+
+void SenchaObject::set_null_value()
+{
+ this->type = null;
+ this->integer = 0;
+ this->number = 0;
+ this->text = "";
+}
+
+void SenchaObject::set_value(int integer)
+{
+ this->integer = integer;
+ type = integer_number;
+}
+
+void SenchaObject::set_value(double number)
+{
+ this->number = number;
+ type = float_number;
+}
+
+void SenchaObject::set_value(bool logic)
+{
+ this->truthy = logic;
+ type = boolean;
+}
+
std::string SenchaObject::repr()
{
std::string representation = "";
diff --git a/Sencha-lang/AST/SenchaObject.h b/Sencha-lang/Elements/SenchaObject.h
index 96cef58..58f7cf6 100644
--- a/Sencha-lang/AST/SenchaObject.h
+++ b/Sencha-lang/Elements/SenchaObject.h
@@ -9,8 +9,10 @@
#define SENCHAOBJECT_H_
#include <string>
#include <iostream>
-#include "to_string.h"
-class SenchaObject {
+#include "../Utils/to_string.h"
+#include "Element.h"
+
+class SenchaObject : public Element {
public:
typedef enum {
@@ -35,46 +37,12 @@ public:
int integer;
double number;
- void set_value(std::string text)
- {
- if(text[0] == '\"' && text[text.size()-1] == '\"')
- {
- this->text = text.substr(1, text.size()-2);
- type = string_literal;
- }
- }
-
- void set_new_string(std::string text)
- {
- this->text = text;
- type = string_literal;
- }
-
- void set_null_value()
- {
- this->type = null;
- this->integer = 0;
- this->number = 0;
- this->text = "";
- }
-
- void set_value(int integer)
- {
- this->integer = integer;
- type = integer_number;
- }
-
- void set_value(double number)
- {
- this->number = number;
- type = float_number;
- }
-
- void set_value(bool logic)
- {
- this->truthy = logic;
- type = boolean;
- }
+ void set_value(std::string text);
+ void set_new_string(std::string text);
+ void set_null_value();
+ void set_value(int integer);
+ void set_value(double number);
+ void set_value(bool logic);
SenchaObject();
SenchaObject(int integer) { set_value(integer); }
@@ -84,9 +52,9 @@ public:
virtual SenchaObject operator< (const SenchaObject& right)const;
- virtual SenchaObject operator> (const SenchaObject& right)const;
- virtual SenchaObject operator<= (const SenchaObject& right)const;
- virtual SenchaObject operator>= (const SenchaObject& right)const;
+ virtual SenchaObject operator> (const SenchaObject& right)const;
+ virtual SenchaObject operator<= (const SenchaObject& right)const;
+ virtual SenchaObject operator>= (const SenchaObject& right)const;
virtual SenchaObject operator+(const SenchaObject& right)const;
virtual SenchaObject operator-(const SenchaObject& right)const;
virtual SenchaObject operator*(const SenchaObject& right)const;
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index 9a862fe..76f1b5e 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -1,7 +1,7 @@
#include "Parser.h"
#include "iostream"
-Parser::Parser(Context * context)
+Parser::Parser(ContextManager * context)
{
this->context = context;
error_message = "***ERRORS DURING PARSING***\n";
@@ -25,6 +25,7 @@ void Parser::erase_all()
delete program;
program = new ProgramNode();
}
+
string Parser::show_tokens()
{
string tokens = "";
diff --git a/Sencha-lang/Parser.h b/Sencha-lang/Parser.h
index 018095c..2b67130 100644
--- a/Sencha-lang/Parser.h
+++ b/Sencha-lang/Parser.h
@@ -4,7 +4,7 @@
#include <vector>
#include <cstdlib>
#include "Token.h"
-#include "Context.h"
+#include "ContextManager.h"
#include "AST/AllTypesOfASTNodes.h"
#include "AST/AST.h"
@@ -13,8 +13,8 @@ using namespace std;
class Parser
{
public:
- Parser(Context * context);
- Context * context;
+ Parser(ContextManager * context);
+ ContextManager * context;
virtual ~Parser();
void interpret();
diff --git a/Sencha-lang/Tests/TestParser.cpp b/Sencha-lang/Tests/TestParser.cpp
index 9b40de8..6d9d66a 100644
--- a/Sencha-lang/Tests/TestParser.cpp
+++ b/Sencha-lang/Tests/TestParser.cpp
@@ -21,7 +21,7 @@ std::string TestParser::test_parsing_and_evaluating_logical_expressions()
std::string test_report = "";
std::vector<InputOutputPair> logical_inputs = prepare_logical_input();
Lexer lexer;
- Context context;
+ ContextManager context;
Parser parser(&context);
for(auto logical_case : logical_inputs)
{
@@ -35,6 +35,17 @@ std::string TestParser::test_parsing_and_evaluating_logical_expressions()
return test_report;
}
+std::string TestParser::test_adding_new_function()
+{
+ std::string test_report = "";
+ std::string function_declaration =+ "def print_hello(how_many_times) {";
+ function_declaration =+ " repeat(how_many_times) { print(\"Hello\");}";
+
+
+ return test_report;
+}
+
+
std::vector<TestParser::InputOutputPair> TestParser::prepare_logical_input()
{
std::vector<InputOutputPair> logical_inputs;
@@ -52,6 +63,7 @@ std::vector<TestParser::InputOutputPair> TestParser::prepare_logical_input()
return logical_inputs;
}
+
std::string TestParser::all_tests()
{
std::string test_report = "";
diff --git a/Sencha-lang/Tests/TestParser.h b/Sencha-lang/Tests/TestParser.h
index faae1a9..37e9d87 100644
--- a/Sencha-lang/Tests/TestParser.h
+++ b/Sencha-lang/Tests/TestParser.h
@@ -24,7 +24,7 @@ public:
typedef std::pair<std::string, bool> InputOutputPair;
private:
std::string test_parsing_and_evaluating_logical_expressions();
-
+ std::string test_adding_new_function();
std::vector<InputOutputPair> prepare_logical_input();
virtual std::string all_tests();
diff --git a/Sencha-lang/AST/to_string.h b/Sencha-lang/Utils/to_string.h
index 62f0639..62f0639 100644
--- a/Sencha-lang/AST/to_string.h
+++ b/Sencha-lang/Utils/to_string.h
diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp
index e903992..07fd038 100644
--- a/Sencha-lang/main.cpp
+++ b/Sencha-lang/main.cpp
@@ -6,7 +6,7 @@
#include "Lexer.h"
#include "Parser.h"
#include "Tests/TestLexer.h"
-#include "Context.h"
+#include "ContextManager.h"
#include "ASTInspector.h"
#include "Tests/tests.h"
#include <unistd.h>
@@ -145,7 +145,7 @@ void interactive()
{
Lexer lexer;
- Context context;
+ ContextManager context;
context.register_function("print", print);
context.register_function("sin", s_sin);
context.register_function("cos", s_cos);
@@ -174,16 +174,11 @@ void interactive()
if(level_of_depth == 0) {
parser.interpret();
parser.program->execute_last();
- //cout << parser.error_message << endl;
- //cout << parser.show_tokens() << endl;
inspector.visit(parser.program);
-
- //cout << parser.context->debug();
cout << inspector.get_report();
inspector.forget_everything();
}
}
-
}
int main(int argc, char *argv[])
@@ -204,7 +199,7 @@ int main(int argc, char *argv[])
else {
auto name = argument1;
Lexer lexer;
- Context context;
+ ContextManager context;
context.register_function("print", print);
context.register_function("sin", s_sin);
context.register_function("cos", s_cos);