예제 #1
0
        private void SetupArrayVariable(Statement statement, string variableName, bool isPublic)
        {
            List <dynamic> arr = new List <dynamic>();

            var bList = new[] { "{", "}", ",", "+" };

            for (int i = isPublic ? 4 : 3; i < statement.tokens.Count; i++)
            {
                var cur = statement.tokens[i];
                if (!bList.Contains(cur))
                {
                    if (IsArray(cur))
                    {
                        arr.AddRange((List <object>)valueHanlder.GetValue(cur));
                    }
                    else
                    {
                        arr.Add(valueHanlder.GetValue(cur));
                    }
                }
            }

            Array a = new Array(new Value(arr, VariableHandler.ProcessedValue(Convert.ToString(arr[0])).type));

            if (isPublic)
            {
                GlobalVariables.AddVariable(variableName, a);
            }
            else if (OuterVariables != null && OuterVariables.IsVariable(variableName))
            {
                OuterVariables.AddVariable(variableName, a);
            }
            else
            {
                InnerVariables.AddVariable(variableName, a);
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            //args = new[] { @"C:\Users\osina\source\repos\Gnosis\Example Scripts\XnO.gno" };

            if (args.Length == 0)
            {
                return;                                         //exit program if no arguments
            }
            Lexer lexer = new Lexer(File.ReadAllText(args[0])); // Get tokens from code file

            Methods = lexer.Methods;

            globalVariableHandler = new VariableHandler(true); // variable handler for "main"

            Method mainMethod = lexer.MainMethod();            // Main method (entry point "main")

            // Create intepreter instance
            MethodHandler methodHandler = new MethodHandler(null, mainMethod);

            if (mainMethod != null)
            {
                methodHandler.DoFunction(mainMethod);  // Inteprete commands in Main
            }
        }