Example #1
0
        public ParseNode GetAndMove(ParseNodeTag tag)
        {
            ParseNode node = Items[_index++];

            if (node.Tag != tag)
            {
                throw new SyntaxException("Unexpected parse node: {0} (expected: {1})", node.Tag, tag);
            }

            return(node);
        }
Example #2
0
        private Func <ParseNode> GetFlattenLeftRecurtion(
            ParseNodeTag nodeTag,
            Func <ParseNode> childFactory,
            Func <bool> continueCondition)
        {
            return(() =>
            {
                var root = new ParseNode(nodeTag);

                do
                {
                    root.AddChild(childFactory());
                }while (continueCondition());

                return root;
            });
        }
Example #3
0
        private Func <ParseNode> GetBinaryOperation(
            ParseNodeTag nodeTag,
            Func <ParseNode> childFactory,
            Func <bool> breakCondition)
        {
            Func <ParseNode, ParseNode, ParseNode> nodeFactory = (leftOp, rightOp) =>
            {
                return(new ParseNode(nodeTag)
                       .AddChild(leftOp)
                       .AddChild(rightOp.Children.GetAndMove())
                       .AddChild(rightOp.Children.GetAndMove()));
            };

            Func <ParseNode> rightChildFactory = () =>
            {
                return(new ParseNode(nodeTag)
                       .AddChild(Terminal())
                       .AddChild(childFactory()));
            };

            return(GetLeftRecurtion(nodeFactory, childFactory, rightChildFactory, breakCondition));
        }
Example #4
0
 public ParseNode Wrap(ParseNodeTag tag)
 {
     return(new ParseNode(tag, this));
 }
Example #5
0
 public ParseNode(ParseNodeTag tag, Token terminal, IEnumerable <ParseNode> children)
 {
     Tag      = tag;
     Token    = terminal;
     Children = new ParseNodeCollection(children);
 }
Example #6
0
 public ParseNode(ParseNodeTag tag, params ParseNode[] children)
     : this(tag, default(Token), children)
 {
 }
Example #7
0
 public bool Check(ParseNodeTag tag)
 {
     return((_index >= 0 && _index < Items.Count) &&
            Items[_index].Tag == tag);
 }