Exemplo n.º 1
0
        // Parse the declaration and returns index of parts after declaration
        public int Parse(string[] parts, int start)
        {
            // If doesn't start with keyword
            if (parts[start] != "desig")
            {
                throw new Exception("Desig starts with '" + parts[start] + "' not 'desig'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            // Declaration doesn't end with ;
            else if (parts[start + 3] != ";")
            {
                throw new Exception("Desig declaration doesn't end in ';'!");
            }
            else
            {
                // Save desig name
                desigName = parts[start + 1];
                criteria  = parts[start + 2];
                Reserved.dEx.Add(this);

                // Return index after desig
                return(start + 4);
            }
        }
Exemplo n.º 2
0
        // Parse the declaration and returns index of parts after declaration
        public int Parse(string[] parts, int start)
        {
            // If doesn't start with keyword
            if (parts[start] != "var")
            {
                throw new Exception("Var starts with '" + parts[start] + "' not 'var'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            // Declaration doesn't end with ;
            else if (parts[start + 2] != ";")
            {
                throw new Exception("Var declaration doesn't end in ';'!");
            }
            else
            {
                // Save var name
                varName = parts[start + 1];
                Reserved.vEx.Add(this);

                // Return index after var
                return(start + 3);
            }
        }
Exemplo n.º 3
0
        // Parse into function
        public int Parse(string[] parts, int start)
        {
            // Set compilation time context
            string currContext = context;

            // If doesn't start with keyword func
            if (parts[start] != "func")
            {
                throw new Exception("Func starts with '" + parts[start] + "' not 'func'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            else if (parts[start + 2] != "{")
            {
                throw new Exception("Expected { not " + parts[start + 2]);
            }
            else
            {
                // Save function name
                funcName = parts[start + 1];
                Reserved.fEx.Add(this);

                // Skip to first expression
                start += 3;

                // Keep identifying expression until end of function declaration
                while (start < parts.Length)
                {
                    if (parts[start] == "}")
                    {
                        return(start + 1);
                    }

                    // Identify from function context
                    IntoAST.IdentifyResponse ir = IntoAST.Identify("function", currContext, parts, start);

                    // Move to next statement and add function child to todo
                    start = ir.next;
                    if (ir.IChild is IChildFunctionDeclaration icfd)
                    {
                        todo.Add(icfd);
                    }
                    else
                    {
                        throw new Exception("Function child '" + ir.IChild + "' cannot follow function '" + funcName + "'");
                    }
                }

                // Didn't find end of function
                throw new Exception("No } found for function " + funcName);
            }
        }