Exemplo n.º 1
0
    // Run a command string
    public static (Dictionary <string, object>, object) Run(Dictionary <string, Method> methods,
                                                            Dictionary <string, object> memory, string command)
    {
        // if entirely in brackets, strip away and look inside
        if (ScriptParser.AllInBrackets(command))
        {
            return(Run(methods, memory, command.Substring(1, command.Length - 2)));
        }

        // Base case, evaluates to literal
        if (ScriptParser.IsNumber(command))
        {
            return(memory, float.Parse(command));
        }
        if (ScriptParser.IsStringLiteral(command))
        {
            return(memory, command.Substring(1, command.Length - 2));
        }

        // Assign right hand side to memory space...
        if (ScriptParser.IsAssignment(command,
                                      out string name, out string value))
        {
            (memory, memory[name]) = Run(methods, memory, value);