Пример #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);
        }