private Expression Factor() { Expression expr = Unary(); while (Match(LexemeType.SLASH) || Match(LexemeType.STAR)) { Lexeme op = Previous(); Expression right = Unary(); expr = new Expression.Binary(expr, op, right); } return(expr); }
private Expression Comparison() { Expression expr = Term(); while (Match(LexemeType.GREATER) || Match(LexemeType.GREATER_EQUAL) || Match(LexemeType.LESS) || Match(LexemeType.LESS_EQUAL)) { Lexeme op = Previous(); Expression right = Term(); expr = new Expression.Binary(expr, op, right); } return(expr); }
private Expression Term() { Expression expr = Factor(); while (Match(LexemeType.MINUS) || Match(LexemeType.PLUS)) { Lexeme op = Previous(); Expression right = Factor(); expr = new Expression.Binary(expr, op, right); } return(expr); }
private Expression Equality() { Expression expr = Comparison(); while (Match(LexemeType.BANG_EQUAL) || Match(LexemeType.EQUAL_EQUAL)) { Lexeme op = Previous(); // Bug - I need to consume the second operator when doing comparisions. // Hack I need to figure out a better way to do this. Lexeme secondOp = Advance(); if (secondOp.LexemeType == LexemeType.EQUAL) { op.AddToken(secondOp); op.LexemeType = LexemeType.EQUAL_EQUAL; } // see what it is? maybe update the lexeme? Expression right = Comparison(); expr = new Expression.Binary(expr, op, right); } return(expr); }