Beispiel #1
0
        public static Token Create(ContinueQueue parsingObject)
        {
            Label label = Label.Create(parsingObject);
            Token token = null;

            string content = parsingObject.Dequeue();

            if (!char.IsLetterOrDigit(content[0]))
            {
                char character = content[0];
                switch (character)
                {
                case '(':
                    break;

                case '{':
                    break;

                case '\"':
                    token = FormatString.Create(parsingObject);
                    break;

                //  # Pre-interpretation option. eg. #include <stdlib>
                case '#':
                    token = PreInterpretationStatement.Create(parsingObject);
                    break;

                // // Comment. eg. // Comment
                case '/':
                    if (parsingObject.Peek()[0] == '/')
                    {
                        parsingObject.Dequeue();
                        token = Comment.Create(parsingObject);
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (content)
                {
                case "if":
                    token = If_Procedure.Create(parsingObject);
                    break;

                default:
                    break;
                }
            }

            token.Label = label;
            return(token);
        }
Beispiel #2
0
        public static Expression Create(ContinueQueue parsingObject, File definitionFile = null)
        {
            string termContent = parsingObject.Dequeue();

            Expression prefab = null;

            if (char.IsLetterOrDigit(termContent[0]))
            // It is a not a meta character
            {
                if (char.IsLetter(termContent[0]))
                // It is a variable or function
                {
                    if (parsingObject.Peek() == "(")
                    // It is a function
                    {
                        parsingObject.Dequeue();

                        prefab      = new Expression();
                        prefab.Name = termContent;

                        string next = parsingObject.Peek();

                        while (next != ")")
                        {
                            Label paramLabel = Label.Create(parsingObject);
                            var   exp        = Expression.Create(parsingObject);
                            exp.Label = paramLabel;
                            prefab.parameters.Add(exp);
                            next = parsingObject.Peek();
                            if (next == ",")
                            {
                                parsingObject.Dequeue();
                            }
                        }

                        if (next == ")")
                        {
                            parsingObject.Dequeue();
                            return(prefab);
                        }
                    }
                    else
                    // It is a variable (declared)
                    {
                        switch (termContent)
                        {
                        case "true":
                        case "false":
                            prefab = Variable.Create(termContent, new SmlBool(true));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            else
            {
                switch (termContent)
                {
                case "(":
                    // It is a term in the form of (Expression())

                    Label termLabel = Label.Create(parsingObject);
                    prefab       = Expression.Create(parsingObject, null);
                    prefab.Label = termLabel;
                    // Next char should be `)`
                    parsingObject.Dequeue();
                    break;

                case "\"":
                    Label stringLabel = Label.Create(parsingObject);
                    prefab       = FormatString.Create(parsingObject);
                    prefab.Label = stringLabel;
                    break;

                default:
                    break;
                }
            }

            return(prefab);
        }