Skip to content

Commit

Permalink
Removed StackBasedScope in order to simplify scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler C committed May 8, 2011
1 parent 182f18a commit fb950c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 150 deletions.
14 changes: 4 additions & 10 deletions src/somelanguage/Interpreter/Function.java
Expand Up @@ -7,6 +7,7 @@
import somelanguage.Interpreter.Processor;
import somelanguage.Parser.Token.Token;
import somelanguage.Value.Value;
import somelanguage.Variables.Scope;

/**
* Creates and environment and processes tokens inside of it
Expand All @@ -15,12 +16,12 @@
public class Function {
private final ArrayList<Token> tokens;
private final Processor runner;
private final ArrayList<Variable> localScope;
private final Scope localScope;

public Function (Processor runner, ArrayList<Token> tokens, ComplexScope scope){

// Save a copy of the current scope
this.localScope = scope.local.getVariables();
this.localScope = scope.local;

this.tokens = tokens;
this.runner = runner;
Expand All @@ -31,7 +32,6 @@ public Value run(ComplexScope parentScope) throws Exception{
// Set up environment
ComplexScope funcScope = createScope(parentScope);


// Run Script
Value value = this.runner.run(this.tokens, funcScope);

Expand All @@ -43,13 +43,7 @@ public Value run(ComplexScope parentScope) throws Exception{
private ComplexScope createScope(ComplexScope parentScope){

// Make new scope
ComplexScope funcScope = new ComplexScope(parentScope.global, new StackBasedScope());

// Add the localScope
funcScope.local.addStack(localScope);

// Add function scope
funcScope.local.addStack();
ComplexScope funcScope = new ComplexScope(parentScope.global, this.localScope);

return funcScope;
}
Expand Down
17 changes: 1 addition & 16 deletions src/somelanguage/Interpreter/Processor.java
@@ -1,6 +1,6 @@
package somelanguage.Interpreter;

import somelanguage.Interpreter.Math.ExpressionProcessor;
import somelanguage.Interpreter.Expressions.ExpressionProcessor;
import java.util.ArrayList;
import somelanguage.Variables.ComplexScope;
import somelanguage.Parser.Token.Token;
Expand Down Expand Up @@ -51,21 +51,6 @@ private Value parseLine(TokenScanner statement, ComplexScope fullScope) throws E

Token token = statement.next(false);

// First Resolve Scope
if(token.getTokenType() == TokenType.CLOSEBRACES
|| token.getTokenType() == TokenType.OPENBRACES){

if(token.getTokenType() == TokenType.CLOSEBRACES)
fullScope.local.removeStack("Anonymous Scope");
else
fullScope.local.addStack("Anonymous Scope");

// Scan past the bracket
statement.next();
token = statement.next(false);
statement = statement.getTokenToEndStatement();
}

// Local Declaration
if(token.getTokenType() == TokenType.LOCAL_DECLARE
|| token.getTokenType() == TokenType.GLOBAL_DECLARE){
Expand Down
3 changes: 1 addition & 2 deletions src/somelanguage/Main.java
Expand Up @@ -44,8 +44,7 @@ public static void main(String[] args) throws Exception {
globalScope.addVariable("echo", new Echo());
globalScope.addVariable("print", new Print());

StackBasedScope localScope = new StackBasedScope();
localScope.addStack();
Scope localScope = new Scope();

// Combines the two scopes
Main.scope = new ComplexScope(globalScope, localScope);
Expand Down
11 changes: 4 additions & 7 deletions src/somelanguage/Variables/ComplexScope.java
@@ -1,21 +1,18 @@
package somelanguage.Variables;

import somelanguage.Variables.StackBasedScope;
import somelanguage.Variables.Variable;
import java.util.ArrayList;
import java.util.Collection;
import somelanguage.Value.Value;
import somelanguage.Value.ValueType;

/**
*
* @author Tyler(Chacha) chacha@chacha102.com
*/
public class ComplexScope extends Scope {
public Scope global;
public StackBasedScope local;
public Scope local;

public ComplexScope(Scope global, StackBasedScope local){
public ComplexScope(Scope global, Scope local){
this.global = global;
this.local = local;
}
Expand Down Expand Up @@ -94,14 +91,14 @@ public void setGlobal(Scope global) {
/**
* @return the local
*/
public StackBasedScope getLocal() {
public Scope getLocal() {
return local;
}

/**
* @param local the local to set
*/
public void setLocal(StackBasedScope local) {
public void setLocal(Scope local) {
this.local = local;
}

Expand Down
115 changes: 0 additions & 115 deletions src/somelanguage/Variables/StackBasedScope.java

This file was deleted.

0 comments on commit fb950c8

Please sign in to comment.