public LR_SyntaxTree ParseAll(SyntaxTreeBuilder pSyntaxTreeBuilder)
    {
        if (!pSyntaxTreeBuilder.TokenScanner.MoveNext())
        {
            return(null);
        }

        var kSyntaxTree = new LR_SyntaxTree();
        var rootId      = new ParseNode_Id(Rule_Start.NtName);

        m_dicIdName2RuleOrToken[Rule_Start.NtName] = Rule_Start;
        rootId.Init_PreCheckSet(this);
        Rule_Start.parent = rootId;
        pSyntaxTreeBuilder.SyntaxRule_Cur = kSyntaxTree.root = new SyntaxTreeNode_Rule(rootId);
        pSyntaxTreeBuilder.ParseNode_Cur  = Rule_Start.Parse(pSyntaxTreeBuilder);

        pSyntaxTreeBuilder.SyntaxRule_Err = pSyntaxTreeBuilder.SyntaxRule_Cur;
        pSyntaxTreeBuilder.ParseNode_Err  = pSyntaxTreeBuilder.ParseNode_Cur;

        while (pSyntaxTreeBuilder.ParseNode_Cur != null)
        {
            if (!ParseStep(pSyntaxTreeBuilder))
            {
                break;
            }
        }

        return(kSyntaxTree);
    }
Exemplo n.º 2
0
    public LR_SyntaxTree Build()
    {
        if (!TokenScanner.MoveNext())
        {
            return(null);
        }

        var kSyntexTree = new LR_SyntaxTree();

        SyntaxRule_Cur = kSyntexTree.root = new SyntaxTreeNode_Rule(Parser.ParseRoot.RootID);
        ParseNode_Cur  = Parser.ParseRoot.Rule_Start.Parse(this);

        SyntaxRule_Err = SyntaxRule_Cur;
        ParseNode_Err  = ParseNode_Cur;

        while (ParseNode_Cur != null)
        {
            if (!ParseStep())
            {
                break;
            }
        }

        return(kSyntexTree);
    }
Exemplo n.º 3
0
    public void MoveToLine(int line, LR_SyntaxTree parseTree)
    {
        for (var prevLine = line - 1; prevLine >= 0; --prevLine)
        {
            var tokens = m_kTokenScanner.GetFormatedLine(prevLine).tokens;
            for (var i = tokens.Count - 1; i >= 0; --i)
            {
                var token = tokens[i];
                var leaf  = token.m_kLinkedLeaf;
                if (token.tokenKind == LexerToken.Kind.Missing)
                {
                    if (token.m_kLinkedLeaf != null && token.m_kLinkedLeaf.Parent != null)
                    {
                        token.m_kLinkedLeaf.Parent.m_sSyntaxError = null;
                    }
                    tokens.RemoveAt(i);
                    continue;
                }

                if (leaf == null || leaf.ParseNode == null)
                {
                    continue;
                }

                if (token.tokenKind < LexerToken.Kind.LastWSToken)
                {
                    continue;
                }

                if (leaf.m_sSyntaxError != null)
                {
                    ErrorToken   = leaf;
                    ErrorMessage = leaf.m_sSyntaxError;
                    continue;
                }

                MoveAfterLeaf(leaf);
                return;
            }
        }

        //tokens = null;
        //currentLine = -1;
        //currentTokenIndex = -1;
        m_kTokenScanner.Reset();

        SyntaxRule_Cur = null;
        ParseNode_Cur  = null;
        ErrorToken     = null;
        ErrorMessage   = null;
        SyntaxRule_Err = null;
        ParseNode_Err  = null;

        m_kTokenScanner.MoveNext();

        ParseNode_Rule startRule = Parser_CSharp.Instance.ParseRoot.Rule_Start;

        SyntaxRule_Cur = parseTree.root; // = new ParseTree.Node(rootId);
        ParseNode_Cur  = startRule;      //.Parse(pSyntaxTreeBuilder);
        SyntaxRule_Err = SyntaxRule_Cur;
        ParseNode_Err  = ParseNode_Cur;
    }