void IfHeader() { Expect((int)TokenEnum.If); Expect((int)TokenEnum.LeftParenthesis); Expression(); try { GraphicFooType type = Quadruple.typeStack.Pop(); if (Semantics.ExpectType(type, GraphicFooType.Boolean)) { string id = Quadruple.operandStack.Pop(); Quadruple.CreateGotoFalseQuadruple(id); Quadruple.PushJump(); } else { SemErr( (int)SemanticEnum.TypeMismatch, "expected boolean, found " + type ); } } catch (InvalidOperationException) { SynErr((int)TokenEnum.NoExpression); } Expect((int)TokenEnum.RightParenthesis); }
/// <summary> /// Creates a return quadruple. /// </summary> /// <returns>The return quadruple.</returns> /// <param name="id">Identifier.</param> public static SemanticEnum CreateReturnQuadruple(string id) { Variable returnVariable = null; if (id != "") { returnVariable = ProgramMemory.FindVariable(scope, id); } // Validate return type SemanticEnum returnStatus = Semantics.ValidateReturn(scope.type, returnVariable); if (returnStatus == SemanticEnum.ValidReturn) { scope.SetEnd(Quadruple.quadruples.Count); Quadruple quadruple = new Quadruple(Operators.Return, returnVariable); PushQuadruple(quadruple); } return(returnStatus); }