Esempio n. 1
0
        public void Visit(VariableList node)
        {
            if (DEBUG)
            {
                Console.WriteLine($"Visiting {node.GetType()}");
            }
            if (globalFunctions[currentFunction].localVariables == null)
            {
                globalFunctions[currentFunction].localVariables = new Dictionary <string, LocalFunctionFields> ();
            }
            int i = 0;

            foreach (var child in node.children)
            {
                if (globalFunctions[currentFunction].localVariables.ContainsKey(child.AnchorToken.Lexeme))
                {
                    throw new SemanticError("You can't have two variables of the same name inside your function", node.AnchorToken);
                }
                globalFunctions[currentFunction].localVariables.Add(child.AnchorToken.Lexeme, new LocalFunctionFields());
            }
            if (DEBUG)
            {
                Console.WriteLine($"Child node type {node.children[0].GetType()}");

                Console.WriteLine("Local Variable Table");
                Console.WriteLine("============");
                foreach (var entry in globalFunctions[currentFunction].localVariables)
                {
                    Console.WriteLine(entry.Key + "\t => " + entry.Value.isParameter.ToString());
                }
            }
        }
Esempio n. 2
0
        public string Visit(VariableList node)
        {
            var stringo = $"// Start {node.GetType()} \n";

            stringo += "\t\t.locals init (\n";
            for (int i = 0; i < node.children.Count; i++)
            {
                stringo += $"\t\t\t[{i}] int32 {node.children[i].AnchorToken.Lexeme}";
                stringo += i == node.children.Count - 1 ? "\n" : ",\n";
            }
            stringo += "\t\t)\n\n";
            return(stringo);
        }