Beispiel #1
0
        public static GATNode _factor(this LL1Processor ll1)
        {
            var node   = new GATNode();
            var offset = 0;

            switch (WordContainer.GetWordType(offset))
            {
            case WordType.BRACKET_L:
            {
                WordContainer.Advance(WordType.BRACKET_L);
                var expression = ll1._expression();
                node.AddChild(expression);
                node.generator = Factor1;
                WordContainer.Advance(WordType.BRACKET_R);
                break;
            }

            case WordType.ID:
            {
                offset = 1;
                if (WordContainer.GetWordType(offset) == WordType.BRACKET_L)
                {
                    var CALL = ll1._call();
                    node.AddChild(CALL);
                    node.generator = Factor2;
                }
                else
                {
                    var VAR = ll1._var();
                    node.AddChild(VAR);
                    node.generator = Factor3;
                }
                break;
            }

            case WordType.NUM:
            {
                var num = WordContainer.Advance(WordType.NUM);
                node.AddChild(num);
                node.generator = Factor4;
                break;
            }

            default:
            {
                throw new BNFException();
            }
            }
            return(node);
        }
Beispiel #2
0
        public static GATNode _expression(this LL1Processor ll1)
        {
            var node         = new GATNode();
            var offset       = 0;
            var search       = WordContainer.GetWordType(offset);
            var depth        = 0;
            var finishSearch = false;

            while (search != WordType.IGNORE)
            {
                switch (search)
                {
                case WordType.SEMICOLON:
                {
                    var simpleExpression = ll1._simpleExpression();
                    node.AddChild(simpleExpression);
                    node.generator = Expression1;
                    finishSearch   = true;
                    break;
                }

                case WordType.EQUAL:
                {
                    var VAR = ll1._var();
                    node.AddChild(VAR);
                    node.generator = Expression2;
                    WordContainer.Advance(WordType.EQUAL);
                    var expression = ll1._expression();
                    node.AddChild(expression);
                    finishSearch = true;
                    break;
                }

                case WordType.BRACKET_L:
                {
                    depth++;
                    break;
                }

                case WordType.BRACKET_R:
                {
                    depth--;
                    if (depth < 0)
                    {
                        var simpleExpression = ll1._simpleExpression();
                        node.AddChild(simpleExpression);
                        node.generator = Expression1;
                        finishSearch   = true;
                    }
                    break;
                }
                }
                if (finishSearch)
                {
                    break;
                }
                offset++;
                search = WordContainer.GetWordType(offset);
            }

            return(node);
        }