示例#1
0
        private Expression Term()
        {
            Expression Higher = Factor();

            //* | /
            while (Match(TokenType.Star) || Match(TokenType.Slash))
            {
                Token Token = Advance();
                Higher = new BinaryExpr(Higher, Token, Factor());
                if (IsAtEnd())
                {
                    return(Higher);
                }
            }

            return(Higher);
        }
示例#2
0
        private Expression Expression()
        {
            Expression Higher = Term();

            //+ | - | == | != | <= | >= | < | > | && | || | ^^
            while (Match(TokenType.Plus) || Match(TokenType.Minus) || Match(TokenType.Equal_Equal) || Match(TokenType.Bang_Equal) ||
                   Match(TokenType.Less) || Match(TokenType.Less_Equal) || Match(TokenType.Greater) || Match(TokenType.Greater_Equal) ||
                   Match(TokenType.And) || Match(TokenType.Or) || Match(TokenType.Xor))
            {
                Token Token = Advance();
                Higher = new BinaryExpr(Higher, Token, Term());
                if (IsAtEnd())
                {
                    return(Higher);
                }
            }

            return(Higher);
        }