public MiniPascalType NodeType(Scope Current) { Type = variable.Type; if (reference.ArrayIndex != null) { MiniPascalType refType = reference.ArrayIndex.NodeType(Current); if (!refType.Equals(MiniPascalType.Integer)) { throw new InvalidArrayIndexTypeException(refType); } if (Type.SimpleType.Equals(SimpleType.Boolean)) { return(MiniPascalType.Boolean); } else if (Type.SimpleType.Equals(SimpleType.Integer)) { return(MiniPascalType.Integer); } else if (Type.SimpleType.Equals(SimpleType.String)) { return(MiniPascalType.String); } else if (Type.SimpleType.Equals(SimpleType.Real)) { return(MiniPascalType.Real); } } return(Type); }
public Procedure(Identifier Identifier, Parameters Parameters, ScopedProgram Block, MiniPascalType Type) { identifier = Identifier; this.Parameters = Parameters; block = Block; ReturnType = Type; }
private DeclarationStatement VariableDeclaration() { if (Accept(Symbol.Variable)) { List <Identifier> ids = new List <Identifier>(); do { Identifier identifier = Identifier(); if (identifier == null) { throw new SyntaxException(expIdentifier, current); } ids.Add(identifier); } while (Accept(Symbol.Comma)); Require(Symbol.Colon); MiniPascalType type = ReadType(); if (type == null) { throw new SyntaxException(expType, current); } return(new DeclarationStatement(ids, type)); } return(null); }
public void EmitIR(CILEmitter Emitter) { for (int i = 0; i < toPrint.Count; i++) { IExpression expr = toPrint.Expression(i); MiniPascalType exprType = toPrint.Type(i); expr.EmitIR(Emitter, false); Emitter.CallPrint(exprType); } }
public void CheckType(Scope Current) { MiniPascalType condType = condition.NodeType(Current); if (!condType.Equals(MiniPascalType.Boolean)) { throw new TypeMismatchException(MiniPascalType.Boolean, condType); } thenStatement.CheckType(Current); elseStatement?.CheckType(Current); }
private Variable ReadVariable() { bool isReference = Accept(Symbol.Variable); Identifier identifier = Identifier(); if (identifier == null) { throw new SyntaxException(expIdentifier, current); } Require(Symbol.Colon); MiniPascalType type = ReadType(); if (type == null) { throw new SyntaxException(expType, current); } return(new Variable(identifier, type, isReference)); }
private Procedure ReadFunction() { if (Accept(Symbol.Function)) { Identifier ident = Identifier(); Require(Symbol.ClosureOpen); Parameters parameters = ReadParameters(); Require(Symbol.ClosureClose); Require(Symbol.Colon); MiniPascalType type = ReadType(); if (type == null) { throw new SyntaxException(expType, current); } Require(Symbol.SemiColon); ScopedProgram block = Block(); block.AddParameters(parameters); return(new Procedure(ident, parameters, block, type)); } return(null); }
public MiniPascalType NodeType(Scope Current) { arguments.CheckType(Current); ToCall = Current.Procedure(toBeCalled); if (arguments.Count != ToCall.Parameters.DeclaredCount) { throw new InvalidParameterCountException(ToCall.Parameters.DeclaredCount, arguments.Count); } Parameters parameters = ToCall.Parameters; for (int i = 0; i < arguments.Count; i++) { MiniPascalType argType = arguments.Type(i); MiniPascalType parType = parameters.At(i).Type; if (!argType.Equals(parType)) { throw new TypeMismatchException(parType, argType); } } Type = ToCall.ReturnType; return(Type); }
public void CheckType(Scope Current) { MiniPascalType type = variable.Type; MiniPascalType assigmentType = assigment.NodeType(Current); if (!assigmentType.Equals(type)) { if (variable.Type.IsArray && !assigmentType.IsArray) { if (!variable.Type.SimpleType.Equals(assigmentType.SimpleType)) { throw new InvalidSimpleTypeException(assigmentType.SimpleType, variable.Type.SimpleType); } } else { throw new TypeMismatchException(type, assigmentType); } } if (reference.ArrayIndex != null) { if (assigmentType.IsArray) { throw new ArrayAssigmentExpection(type.SimpleType, assigmentType); } MiniPascalType indexType = reference.ArrayIndex.NodeType(Current); if (!indexType.Equals(MiniPascalType.Integer)) { throw new InvalidArrayIndexTypeException(indexType); } } else if (reference.ArrayIndex == null && variable.Type.IsArray && !assigmentType.IsArray) { throw new InvalidArrayIndexTypeException(null); } }
public Variable(Identifier Identifier, MiniPascalType Type, bool IsReference) { this.Identifier = Identifier; this.Type = Type; this.IsReference = IsReference; }