public Expression Condition(Expression arg1, Expression arg2, Expression arg3, Token start, Token oper) { Wall.OfType<bool>(arg1, start.Location); Wall.TypesMatch(arg2, arg3, oper.Location); return Expression.Condition(arg1, arg2, arg3); }
public Expression AndAlso(Expression arg1, Expression arg2, Token oper) { Wall.LAnd(arg1, arg2, oper); try { return Expression.AndAlso(arg1, arg2); } catch { throw new ParseErrorException(MakeInvalidTypesError(oper, arg1.Type, arg2.Type), ExprString, oper.Location); } }
public Expression Add(Expression arg1, Expression arg2, Token oper) { var type1 = arg1.Type; var type2 = arg2.Type; TypeAdapter.MakeTypesCompatible(arg1, arg2, out arg1, out arg2, oper.Type); Wall.Add(arg1, arg2, type1, type2, oper); try { return Expression.Add(arg1, arg2); } catch { throw new ParseErrorException(MakeInvalidTypesError(oper, type1, type2), ExprString, oper.Location); } }
private bool Next() { int line, column; Expression = Expression.TrimStart(out line, out column); Location.Line += line; Location.Column = line > 0 ? column : Location.Column + column; if (Expression.Length == 0) return false; foreach (var kvp in RegexMap) { var regex = kvp.Value; var match = regex.Match(Expression); if (!match.Success) continue; var value = match.Value; Token = new Token(kvp.Key, ConvertTokenValue(kvp.Key, value), new Location(Location)); Expression = Expression.Substring(value.Length, out line, out column); Location.Line += line; Location.Column = line > 0 ? column : Location.Column + column; return true; } throw new ParseErrorException("Invalid token.", new Location(Location)); }
private string MakeInvalidTypesError(Token oper, Type type1, Type type2) { return $"Operator '{oper.Value}' cannot be applied to operands of type '{type1}' and '{type2}'."; }
public Expression UnaryPlus(Expression arg, Token oper) { Wall.Unary(arg, oper); try { return Expression.UnaryPlus(arg); } catch { throw new ParseErrorException(MakeInvalidTypeError(oper, arg.Type), ExprString, oper.Location); } }
private string MakeInvalidTypeError(Token oper, Type type) { return $"Operator '{oper.Value}' cannot be applied to operand of type '{type}'."; }
public void BAnd(Expression arg1, Expression arg2, Token oper) { BOrBAndXor(arg1, arg2, oper); }
public void LAnd(Expression arg1, Expression arg2, Token oper) { LOrLAnd(arg1, arg2, oper); }
private void AssertArgsNotNullLiterals(Expression arg1, Type type1, Expression arg2, Type type2, Token oper) { if (arg1.IsNullLiteral() && arg2.IsNullLiteral()) { throw new ParseErrorException( $"Operator '{oper.Value}' cannot be applied to operands of type 'null' and 'null'.", Expr, oper.Location); } if (!arg1.IsNullLiteral() && arg2.IsNullLiteral()) { throw new ParseErrorException( $"Operator '{oper.Value}' cannot be applied to operands of type '{type1}' and 'null'.", Expr, oper.Location); } if (arg1.IsNullLiteral() && !arg2.IsNullLiteral()) { throw new ParseErrorException( $"Operator '{oper.Value}' cannot be applied to operands of type 'null' and '{type2}'.", Expr, oper.Location); } }
private void AssertArgsNotNullLiterals(Expression arg1, Expression arg2, Token oper) { AssertArgsNotNullLiterals(arg1, arg1.Type, arg2, arg2.Type, oper); }
public void print_token_for_debug_purposes() { var token = new Token(TokenType.FLOAT, 1.0, "1.0", new Location(1, 2)); Assert.Equal(@"""1.0"" FLOAT (1, 2)", token.ToString()); }