예제 #1
0
        static Scope()
        {
            globalVariables = new Dictionary<string, SLValue>();
            for(int i=0; i<200; i++)
            {
                globalVariables["R" + i] = new SLValue(default(double));
            }

        }
예제 #2
0
 public void assign(String var, SLValue value)
 {
     if (resolve(var) != null)
     {
         // There is already such a variable, re-assign it
         this.reAssign(var, value);
     }
     else
     {
         // A newly declared variable
         variables[var] = value;
     }
 }
예제 #3
0
 private void reAssign(String identifier, SLValue value)
 {
     if (variables.ContainsKey(identifier))
     {
         // The variable is declared in this scope
         variables[identifier] = value;
     }
     else if (_parent != null)
     {
         // The variable was not declared in this scope, so let
         // the parent scope re-assign it
         _parent.reAssign(identifier, value);
     }
 }
예제 #4
0
        public SLValue Invoke(String functionName, List <ExpressionContext> param, int countArgs, Dictionary <String, Function> functions, Scope scope, StringBuilder gcodeBuffer)
        {
            if (countArgs != this._param.Count)
            {
                throw new Exception("Illegal Function call");
            }
            Scope scopeNext = new Scope(null); // create function scope

            EvalVisitor evalVisitor = new EvalVisitor(scope, functions, null);

            for (int i = 0; i < param.Count; i++)
            {
                if (param[i].ChildCount > 0)
                {
                    SLValue value = evalVisitor.Visit(param[i]);
                    scopeNext.assignParam(this._param[i].GetText(), value);
                }
                else
                {
                    SLValue value = scopeNext.GetDefaultValue(this._paramType[i].GetText());
                    scopeNext.assignParam(this._param[i].GetText(), value);
                }
            }
            EvalVisitor evalVistorNext = new EvalVisitor(scopeNext, functions, gcodeBuffer);

            SLValue ret = SLValue.VOID;

            try
            {
                evalVistorNext.Visit(this.block);
            }
            catch (ReturnValue returnValue)
            {
                ret = returnValue.value;
            }
            catch (Exception ex)
            {
                throw new Exception($"Illegal Function {functionName} call");
            }

            return(ret);
        }
예제 #5
0
        public SLValue InvokeWithoutArgs(String functionName, Dictionary <String, Function> functions, Scope scope, StringBuilder gcodeBuffer)
        {
            Scope       scopeNext      = new Scope(scope);
            EvalVisitor evalVistorNext = new EvalVisitor(scopeNext, functions, gcodeBuffer);

            SLValue ret = SLValue.VOID;

            try
            {
                evalVistorNext.Visit(this.block);
            }
            catch (ReturnValue returnValue)
            {
                ret = returnValue.value;
            }
            catch (Exception ex)
            {
                throw new Exception($"Illegal Function {functionName} call");
            }

            return(ret);
        }
예제 #6
0
 public void GlobalAssign(String var, SLValue value)
 {
     globalVariables[var] = value;
 }
예제 #7
0
 public void assignParam(String var, SLValue value)
 {
     variables[var] = value;
 }