// Equality ExprNode ParseEquality() { var LHS = ParseRelational(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.EQ)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseRelational(), OpName = "==", Operator = ExprNodeBinary.OpEQ, }; } else if (_tokenizer.TrySkipToken(Token.NE)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseRelational(), OpName = "!=", Operator = ExprNodeBinary.OpNE, }; } else { return(LHS); } } }
// Shift ExprNode ParseShift() { var LHS = ParseAdd(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.Shl)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseAdd(), OpName = "<<", Operator = ExprNodeBinary.OpShl, }; } else if (_tokenizer.TrySkipToken(Token.Shr)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseAdd(), OpName = ">>", Operator = ExprNodeBinary.OpShr, }; } else { return(LHS); } } }
// Relational ExprNode ParseRelational() { var LHS = ParseDup(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.LE)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseDup(), OpName = "<=", Operator = ExprNodeBinary.OpLE, }; } else if (_tokenizer.TrySkipToken(Token.GE)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseDup(), OpName = ">=", Operator = ExprNodeBinary.OpGE, }; } else if (_tokenizer.TrySkipToken(Token.GT)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseDup(), OpName = ">", Operator = ExprNodeBinary.OpGT, }; } else if (_tokenizer.TrySkipToken(Token.LT)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseDup(), OpName = "<", Operator = ExprNodeBinary.OpLT, }; } else { return(LHS); } } }
ExprNode ParseMultiply() { var LHS = ParseUnary(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.Multiply)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseUnary(), OpName = "*", Operator = ExprNodeBinary.OpMul, }; } else if (_tokenizer.TrySkipToken(Token.Divide)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseUnary(), OpName = "/", Operator = ExprNodeBinary.OpDiv, }; } else if (_tokenizer.TrySkipToken(Token.Modulus)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseUnary(), OpName = "%", Operator = ExprNodeBinary.OpMod, }; } else { return(LHS); } } }
// Logical OR ExprNode ParseLogicalOr() { var LHS = ParseLogicalAnd(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.LogicalOr)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseLogicalAnd(), OpName = "||", Operator = ExprNodeBinary.OpLogicalOr, }; } else { return(LHS); } } }
// Bitwise XOR ExprNode ParseBitwiseXor() { var LHS = ParseBitwiseAnd(); while (true) { var pos = _tokenizer.TokenPosition; if (_tokenizer.TrySkipToken(Token.BitwiseXor)) { LHS = new ExprNodeBinary(pos) { LHS = LHS, RHS = ParseBitwiseAnd(), OpName = "^", Operator = ExprNodeBinary.OpBitwiseXor, }; } else { return(LHS); } } }