Beispiel #1
0
            public override bool ParseMatch(TokenReader tr, SyntaxTree.Node node)
            {
                /*var con = true;
                 * while (con) {
                 *  con = base.ParseMatch(tr, node);
                 * }*/

                while (base.ParseMatch(tr, node))
                {
                }

                return(true);
            }
Beispiel #2
0
 public bool ParseMatch(TokenReader tr, SyntaxTree.Node node)
 {
     if (tr.Peek()?.type == this)
     {
         tr.Next();
         if (createNode)
         {
             node.AddChild(new SyntaxTree.Node(this, tr.Current.value));
         }
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        public bool ParseMatch(TokenReader tr, SyntaxTree.Node node)
        {
            var n = createNode ? new SyntaxTree.Node(this, "") : node;

            for (int i = 0; i < patterns.Length; i++)
            {
                if (patterns[i].Match(tr, n))
                {
                    if (createNode)
                    {
                        node.AddChild(n);
                    }
                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
        public SyntaxTree Parse(string input)
        {
            var reader = new TokenReader(lexer.Lex(input));

            Console.WriteLine(reader.TokensAsText());

            var mainRule = parserules[0]; // hard-code to first rule for now

            var root = new SyntaxTree.Node(mainRule, "");

            if (!mainRule.ParseMatch(reader, root))
            {
                throw new ParserException("");
            }

            return(new SyntaxTree(root));
        }
Beispiel #5
0
            public bool Match(TokenReader tr, SyntaxTree.Node node)
            {
                int startIndex      = tr.index;
                int startChildCount = node.childCount;

                for (int i = 0; i < rules.Length; i++)
                {
                    if (!rules[i].ParseMatch(tr, node))
                    {
                        // fail. reset tokenreader index and syntaxtree nodes
                        tr.index = startIndex;
                        while (node.childCount > startChildCount)
                        {
                            node.RemoveChild(node.childCount - 1);
                        }

                        return(false);
                    }
                }
                return(true);
            }
Beispiel #6
0
 public override bool ParseMatch(TokenReader tr, SyntaxTree.Node node)
 {
     base.ParseMatch(tr, node);
     return(true);
 }
Beispiel #7
0
 public virtual bool ParseMatch(TokenReader tr, SyntaxTree.Node node) => inner.ParseMatch(tr, node);