Esempio n. 1
0
        static void Main(string[] args)
        {
            String directory = String.Empty;

            Console.WriteLine("Enter directory to compile or leave blank to target this directory: ");
            directory = Console.ReadLine();

            var context = Script.ParsePDXScript.ParseFile(directory).Context;

            Console.WriteLine(context.Root.PrintString());

            foreach (var kcn in context.Root.Children.OfType <Script.KeyCollectionNode>())
            {
                if (kcn.Key.ToLower() == "function")
                {
                    Function.PDXFunction function = Function.ParseFunction.ParseNode(kcn);
                    function.DumpInfo(); Console.WriteLine("");
                    Console.WriteLine(function.GenerateFunctionEffect());
                }
            }


            if (directory == String.Empty)
            {
                // This Directory
                Console.WriteLine("Directory: " + Environment.CurrentDirectory);
            }
            else
            {
                Console.WriteLine("Directory: " + directory);
            }

            Console.ReadLine();
        }
Esempio n. 2
0
        /************************************************************
        * function = {
        *      name = cube_root
        *      arguments = { cr_arg_number }
        *      return = cr_ret_number
        *      effect = {
        *          ...
        *          return = mid
        *      }
        * }
        ************************************************************/


        public static PDXFunction ParseNode(Script.KeyCollectionNode head)
        {
            PDXFunction      construct      = new PDXFunction();
            HashSet <String> foundArguments = new HashSet <string>();

            if (head.Key.Trim().ToLower() != "function")
            {
                // Log this.
                return(null);
            }

            Script.KeyCollectionNode argNode    = null;
            Script.KeyCollectionNode effectNode = null;


            foreach (Script.Node child in head.Children)
            {
                switch (child)
                {
                case Script.KeyCollectionNode kcn:
                    String kcn_key = kcn.Key.ToLower();
                    switch (kcn_key)
                    {
                    case "arguments":
                        argNode = kcn;
                        break;

                    case "effect":
                        effectNode = kcn;
                        break;
                    }

                    break;

                case Script.CommentNode cn:
                    break;

                case Script.KeyValueNode kvn:
                    String kvn_key = kvn.Key.ToLower();
                    switch (kvn_key)
                    {
                    case "name":
                        if (construct.Name == String.Empty)
                        {
                            construct.Name = kvn.Value;
                        }
                        else
                        {
                            // Log.
                        }
                        break;

                    case "return":
                        if (construct.ReturnVariable == String.Empty)
                        {
                            construct.ReturnVariable = kvn.Value;
                        }
                        else
                        {
                            // Log
                        }
                        break;

                    case "arguments":
                        // Maybe log this.
                        break;
                    }
                    break;

                case Script.SingleValueNode svn:
                    break;
                }
            }

            if (argNode != null)
            {
                foreach (Script.SingleValueNode singleValueNode in argNode.Children.OfType <Script.SingleValueNode>())
                {
                    String svn_value_lower = singleValueNode.Value.Trim().ToLower();
                    if (foundArguments.Contains(svn_value_lower))
                    {
                        continue;
                    }
                    else
                    {
                        foundArguments.Add(svn_value_lower); construct.Arguments.Add(svn_value_lower);
                    }
                }

                for (int i = 0; i < construct.Arguments.Count; i++)
                {
                    construct.ArgumentIndex[construct.Arguments[i]] = i;
                }
            }

            if (effectNode != null)
            {
                construct.EffectsNode    = effectNode;
                construct.LocalVariables = FindLocals(effectNode);
                for (int i = 0; i < construct.LocalVariables.Count; i++)
                {
                    construct.LocalVariableIndex[construct.LocalVariables[i]] = i;
                }
            }

            return(construct);
        }