Example #1
0
 public Parser(Lexer lexer)
 {
     this.lexer      = lexer;
     this.endKeyword = lexer.endKeyword;
 }
Example #2
0
        Keyword NewToken()
        {
            if (builder.Length == 0)
            {
                hasSpacesPre = hasSpacesPost;
                return(null);
            }

            if (toReturn.Count > 0)
            {
                Keyword ret = toReturn.Dequeue();
                return(ret);
            }

            string keywordText = builder.ToString();

            builder.Clear();
            search.Text = keywordText;
            Keyword result;

            search.Type = KeywordType.Simple;
            if (core.Keywords.TryGetValue(search, out result))
            {
                if (keywordText[0] == '(')
                {
                    if (!hasSpacesPre)
                    {
                        toReturn.Enqueue(callKeyword);
                    }
                    else
                    {
                        int j = 111;
                    }

                    hasSpacesPost = true;
                    //if (lastKeywordType == KeywordType.Simple)
                }
                else if (keywordText[0] == ')')
                {
                    hasSpacesPost = false;
                }

                toReturn.Enqueue(result);

                lastKeywordType = result.Type;
                hasSpacesPre    = hasSpacesPost;
                return(null);
            }

            if (hasSpacesPost == hasSpacesPre)
            {
                search.Type = KeywordType.Binary;
                if (core.Keywords.TryGetValue(search, out result))
                {
                    toReturn.Enqueue(result);
                    lastKeywordType = result.Type;
                    hasSpacesPre    = hasSpacesPost;
                    return(null);
                }
            }

            if (/*!hasSpacesPost && */ hasSpacesPre)
            {
                search.Type = KeywordType.Prefix;
                if (core.Keywords.TryGetValue(search, out result))
                {
                    toReturn.Enqueue(result);
                    lastKeywordType = result.Type;
                    hasSpacesPre    = hasSpacesPost;
                    return(null);
                }
            }

            if (/*hasSpacesPost && */ !hasSpacesPre)
            {
                search.Type = KeywordType.Postfix;
                if (core.Keywords.TryGetValue(search, out result))
                {
                    toReturn.Enqueue(result);
                    lastKeywordType = result.Type;
                    hasSpacesPre    = hasSpacesPost;
                    return(null);
                }
            }

            Keyword ret1 = new Keyword(KeywordType.IdentifierOrLiteral, keywordText);

            lastKeywordType = ret1.Type /*KeywordType.Simple*/;
            hasSpacesPre    = hasSpacesPost;
            return(ret1);
        }
Example #3
0
        public Keyword GetNext()
        {
            if (endLine)
            {
                return(EndLine());
            }
            if (comma)
            {
                return(Comma());
            }
            if (pop)
            {
                return(Pop());
            }
            if (endBrackets)
            {
                return(EndBrackets());
            }

            do
            {
                kwtoken = lexer.GetNext();
            } while (kwtoken == null);

            /*Keyword*/

            if (end)
            {
                return(lexer.endKeyword);
            }

            if (kwtoken == lexer.endKeyword)
            {
                end = endLine = true;
                return(EndLine());
                //end
            }

            if (kwtoken is Operator operatorToken)
            {
                if (kwtoken is NestedOperator)
                {
                    kwtoken = kwtoken.Clone();
                    ((NestedOperator)kwtoken).Nesting = NestingIndex;
                    operatorToken = (Operator)kwtoken;
                }

                lastKeywordType = operatorToken.Type;

                if (kwtoken.Type == KeywordType.Simple)
                {
                    return(kwtoken);
                }

                OperatorToken = operatorToken;
                pop           = true;
                return(Pop());
            }
            if (kwtoken.Type == KeywordType.Comma)
            {
                comma = true;
                return(Comma());
            }
            else if (kwtoken.Type == KeywordType.EndLine)
            {
                endLine = true;
                return(EndLine());
            }
            else if (kwtoken.Type == KeywordType.LeftBracket)
            {
                NestingIndex++;
                ParserStack.Push(kwtoken);
                return(null /*kwtoken*/);
            }
            else if (kwtoken.Type == KeywordType.RightBracket)
            {
                NestingIndex--;
                endBrackets = true;
                return(EndBrackets());
            }
            else
            {
                return(kwtoken);
                //decimal number = 0;
                //if (decimal.TryParse(kwtoken.Text, out number))
                //{

                //}
                //else
                //{

                //}
            }

            return(EndLine());
        }