Example #1
0
        public void Visit(FunctionCall node)
        {
            if (DEBUG)
            {
                Console.WriteLine($"Visiting {node.GetType()}");
            }
            if (DEBUG)
            {
                Console.WriteLine($"AT {node.AnchorToken.Lexeme}");
            }
            if (DEBUG)
            {
                Console.WriteLine($"Children {node.children.Count}");
            }
            var name  = node.AnchorToken.Lexeme;
            var arity = node.children.Count;

            if (globalFunctions.ContainsKey(name))
            {
                if (!(arity == globalFunctions[name].arity))
                {
                    throw new SemanticError($"The function {name} should have arity of {globalFunctions[name].arity} not of {arity}", node.AnchorToken);
                }
                VisitChildren(node);
            }
            else
            {
                throw new SemanticError($"Function {name} isn't defined. Are you sure this name is correct?", node.AnchorToken);
            }
        }
Example #2
0
        public string Visit(FunctionCall node)
        {
            string st = $"// Start {node.GetType()} \n";

            st += VisitChildren(node);
            if (globalFunctions[node.AnchorToken.Lexeme].isPredefinedFunction)
            {
                st += tab(2) + "call int32 class ['deeplingolib']'DeepLingo'."
                      + "'Utils'::'" + Capitalize(node.AnchorToken.Lexeme) + "'";
            }
            else
            {
                st += tab(2) + "call int32 class DeepLingoProgram::" + node.AnchorToken.Lexeme;
            }
            st += "(";
            // Console.WriteLine($"The count is {node.children.Count}");
            for (int i = 0; i < node.children.Count; i++)
            {
                if (i != node.children.Count - 1)
                {
                    st += "int32,";
                }
                else
                {
                    st += "int32";
                }
            }
            st += ")\n";
            if (node.AnchorToken.Lexeme.Contains("print"))
            {
                st += tab(2) + "pop\n";
            }
            return(st);
        }