private static void CheckIfReturnsSpecifiedType(ExpressionNode expression, IList<Error> errors, TigerType type) { if (!(expression.ReturnType == type)) { errors.Add(new UnexpectedTypeError(expression.Line, expression.Column, expression.ReturnType, IntegerType.Create())); } }
public OperatorError(int line, int column, string operatorName, TigerType t1, TigerType t2) : base(line, column) { OperatorName = operatorName; T1 = t1; T2 = t2; }
public Variable(string name, TigerType type, bool readOnly = false) { Name = name; Type = type; ReadOnly = readOnly; _id = Guid.NewGuid().ToCleanString(); }
/// <summary> /// Adiciona un tipo al scope /// </summary> /// <param name="type">Tipo que se anadira al scope</param> /// <param name="name">Parametro opcional que especifica con que nombre se anadira al scope. Si es null, se utiliza type.Name</param> /// <param name="updateIfExists">Especifica si se debe actualizar el tipo en caso de que este exista en el scope</param> public void Add(TigerType type, string name = null, bool updateIfExists = false) { var nameToAdd = name ?? type.Name; if (DefinedTypes.ContainsKey(nameToAdd)) { if (updateIfExists) { DefinedTypes[nameToAdd] = type; } else { throw new Exception("Ya existe un tipo con ese nombre"); } } else { DefinedTypes.Add(nameToAdd, type); } }
public ArrayType(string name, TigerType elementsType) : base(name, Guid.NewGuid()) { ElementsType = elementsType; //TODO: Lanzar excepcion aqui si me crean un array de un tipo invalido (eg. Null)? }
public static bool CanBeAssignedTo(TigerType type) { return type is RecordType || type is ArrayType || type is StringType; }
public UnexpectedTypeError(int line, int column, TigerType type, TigerType expectedType) : base(line, column) { Type = type; ExpectedType = expectedType.ToString(); }
public UnexpectedTypeError(int line, int column, TigerType type, string expectedTypeString) : base(line, column) { Type = type; ExpectedType = expectedTypeString; }
/// <summary> /// Anade una nueva variable al scope /// </summary> /// <param name="variable">Variable a anadir</param> /// <param name="type">Tipo que almacenara esa variable</param> /// <param name="readOnly">Especifica si la variable sera de solo lectura o no (eg. la del 'for')</param> public void Add(string variable, TigerType type, bool readOnly = false) { if (DefinedVariables.ContainsKey(variable)) { throw new Exception("La variable ya existe"); } DefinedVariables.Add(variable, new Variable(variable, type, readOnly)); }