Esempio n. 1
0
        private SyntaxTreeNode Term()
        {
            SyntaxTreeNode t = Factor();
            while ((CurToken != null) &&
                (CurToken.Type == TokenType.Multi || CurToken.Type == TokenType.Div))
            {
                SyntaxTreeNode p = new OpSyntaxTreeNode(CurToken);
                p.AddChild(t);
                t = p;

                MatchToken(CurToken.Type);
                SyntaxTreeNode fac = Factor();
                if (fac == null)
                {
                    throw new ParseException("need exp after token: *, /");
                }
                t.AddChild(fac);
            }

            return t;
        }
Esempio n. 2
0
        private SyntaxTreeNode SimpExp()
        {
            SyntaxTreeNode t = Term();
            while ((CurToken !=null)
                && (CurToken.Type == TokenType.Add || CurToken.Type == TokenType.Minus))
            {
                SyntaxTreeNode p = new OpSyntaxTreeNode(CurToken);
                p.AddChild(t);
                t = p;

                MatchToken(CurToken.Type);
                t.AddChild(Term());
            }

            return t;
        }