예제 #1
0
파일: Verbs.cs 프로젝트: ozyx/PowerWalk
        public static void SplitSentence(string line, ref string verb, ref string complement, string pattern = Patterns.getverb)
        {
            line = line.Trim();

            verb = Verbs.GetWord(line, pattern);

            complement = verb.Length < line.Length ? line.Substring(verb.Length).Trim() : "";
        }
예제 #2
0
파일: Verbs.cs 프로젝트: ozyx/PowerWalk
            public static void GetOrientationProperty

                (ref string line,
                ref string left,
                ref string right,
                ref bool referential)
            {
                Verbs.SplitSentence(line, ref left, ref right);

                if (referential = Operators.bidirectional.Contains(left))
                {
                    line = right;
                }
            }
예제 #3
0
            public Parameter(bool isReferential, string declaration) : this()
            {
                string op = "";

                ParseDeclaration
                (
                    declaration,
                    ref key, ref readable, ref writeable,
                    ref op, ref typename, ref expression
                );

                Verbs.VerifyRightToLeftOperator(op);

                referential = isReferential;
            }
예제 #4
0
파일: Verbs.cs 프로젝트: ozyx/PowerWalk
        public static void GoToAssignmentOrDeclaration(Interpreter.Sequence receiver, string line)
        {
            try
            {
                if (Operators.permissionops.Contains(Verbs.GetVerb(line)))
                {
                    throw new Exception();
                }

                AssignTo(receiver, line);
            }
            catch
            {
                Declare(receiver, line);
            }
        }
예제 #5
0
파일: Verbs.cs 프로젝트: ozyx/PowerWalk
            public static void GetPermissionProperties

                (ref string line,
                ref string left,
                ref string right,
                ref bool read,
                ref bool write)
            {
                Verbs.SplitSentence(line, ref left, ref right);

                if (Operators.permissionops.Contains(left))
                {
                    SpecifyPermissions(left, ref read, ref write);

                    line = right;
                }
                else
                {
                    read = write = true;
                }
            }
예제 #6
0
        public static List <string> ParseHeading(IList <string> queue, ref int start, ref string name, ref string returnType)
        {
            var typenames = new List <string>();

            string verb = null, complement = null;

            Match typenameCapture;

            name = Regex.Match(queue[start], Patterns.getdefname).Value;

            returnType = Regex.Match
                         (
                queue[start],
                Patterns.gettypename,
                RegexOptions.RightToLeft
                         )
                         .Value;

            switch (Regex.Match(queue[start], Patterns.punctuation).Value)
            {
            case ":":
            {
                try
                {
                    Verbs.SplitSentence(queue[start + 1], ref verb, ref complement);

                    while (Operators.parameterOrientations.Contains(verb))
                    {
                        start = start + 1;

                        foreach (string declaration in complement.Split(','))
                        {
                            if (!String.IsNullOrWhiteSpace(declaration))
                            {
                                typenameCapture = Regex.Match(declaration, Patterns.gettypename);

                                typenames.Add(typenameCapture.Success ? typenameCapture.Value : Definition.DEFAULT_TYPENAME);
                            }
                        }

                        if (Regex.IsMatch(queue[start], ",\\s*$"))
                        {
                            complement = queue[start + 1];
                        }
                        else
                        {
                            Verbs.SplitSentence(queue[start + 1], ref verb, ref complement);
                        }
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new Exception("Bug: Attempting to parse an unfinished definition.");
                }
            }

            break;

            case "(":
            {
                foreach (string declaration in

                         Regex.Match(queue[start], Patterns.getdefparams).Value.Split(','))
                {
                    if (!String.IsNullOrWhiteSpace(declaration))
                    {
                        typenameCapture = Regex.Match(declaration, Patterns.gettypename);

                        typenames.Add(typenameCapture.Success ? typenameCapture.Value : Definition.DEFAULT_TYPENAME);
                    }
                }
            }

            break;
            }

            start = start + 1;

            return(typenames);
        }
예제 #7
0
        public static List <Parameter> ParseHeading(IList <string> queue, ref int start)
        {
            var parameters = new List <Parameter>();

            string verb = null, complement = null;

            try
            {
                switch (Regex.Match(queue[start], Patterns.punctuation).Value)
                {
                case ":":
                {
                    bool isOutParameter;

                    try
                    {
                        Verbs.SplitSentence(queue[start + 1], ref verb, ref complement);

                        isOutParameter = ParameterOrientation(verb);

                        while (Operators.parameterOrientations.Contains(verb))
                        {
                            start = start + 1;

                            foreach (string declaration in complement.Split(','))
                            {
                                if (!String.IsNullOrWhiteSpace(declaration))
                                {
                                    parameters.Add(new Parameter(isOutParameter, declaration));
                                }
                            }

                            if (Regex.IsMatch(queue[start], ",\\s*$"))
                            {
                                complement = queue[start + 1];
                            }
                            else
                            {
                                Verbs.SplitSentence(queue[start + 1], ref verb, ref complement);

                                isOutParameter = ParameterOrientation(verb);
                            }
                        }
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        throw new Exception("Bug: Attempting to parse an unfinished definition.");
                    }
                }

                break;

                case "(":
                {
                    foreach (string declaration in

                             Regex.Match(queue[start], Patterns.getdefparams).Value.Split(','))
                    {
                        if (!String.IsNullOrWhiteSpace(declaration))
                        {
                            Verbs.SplitSentence(declaration, ref verb, ref complement);

                            if (Operators.parameterOrientations.Contains(verb))
                            {
                                parameters.Add(new Parameter(verb, complement));
                            }
                            else
                            {
                                parameters.Add(new Parameter(false, declaration));
                            }
                        }
                    }
                }

                break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(CommandLineInterface.GetErrorMessageWithLineNumberAndHeading(start, "Syntax Error", e));
            }

            start = start + 1;

            return(parameters);
        }
예제 #8
0
        public static object Call(Interpreter.Sequence sender, string name, List <object> arguments)
        {
            Definition newProcess = Get(name, arguments);

            int lineNumber = newProcess.LineNumber;

            List <string> script = Transcript.Table[newProcess.Path];

            int startingLvl = Interpreter.Sequence.GetLevel(script[lineNumber]);

            List <Parameter> parameters = ParseHeading(script, ref lineNumber);

            var receiver = new Interpreter.Sequence();

            Dictionary <string, Named> table;

            for (int i = 0; i < parameters.Count; ++i)
            {
                if (parameters[i].referential)
                {
                    try
                    {
                        table = sender.Names.GetTable((string)arguments[i]);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Failed to get a reference for a bidirectional parameter. Are you missing a 'ref' keyword?");
                    }
                }
                else
                {
                    table = null;
                }

                Verbs.Declare(receiver,
                              parameters[i].key,
                              parameters[i].key,
                              parameters[i].readable,
                              parameters[i].writeable,
                              arguments[i],
                              table,
                              parameters[i].typename);
            }

            try
            {
                while (lineNumber < script.Count)
                {
                    if (String.IsNullOrWhiteSpace(script[lineNumber]))
                    {
                        lineNumber = lineNumber + 1;
                    }
                    else if (Interpreter.Sequence.GetLevel(script[lineNumber]) > startingLvl)
                    {
                        lineNumber = receiver.Execute(script, lineNumber);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Return r)
            {
                if (Operators.returnvoid.Contains(newProcess.ReturnType))
                {
                    if (r.Payload == null)
                    {
                        throw new Exception("Line " + (lineNumber + 1) + ": Syntax Error: Returning 'null' from a process that returns void.");
                    }

                    throw new Exception("Line " + (lineNumber + 1) + ": Syntax Error: Returning a '" + r.Payload.GetType().Name + "' from a process that returns void.");
                }

                if (r.Payload != null && !r.Payload.GetType().Name.Equals(newProcess.ReturnType))
                {
                    throw new Exception("Line " + (lineNumber + 1) + ": Type Mismatch: Returning a '" + r.Payload.GetType().Name + "' from a process that returns '" + newProcess.ReturnType + "'.");
                }

                return(r.Payload);
            }

            if (!Operators.returnvoid.Contains(newProcess.ReturnType))
            {
                throw new Exception("Line " + (newProcess.LineNumber + 1) + ": Syntax Error: No return at the end of non-void returning process.");
            }

            return(null);
        }