/// <summary> /// Generates code for a push statement for literal type /// </summary> /// <param name="litRecord"></param> /// <param name="factorRecord"></param> internal void GenerateLitPush(LiteralRecord litRecord, ref VariableType factorRecord) { cilOutput.WriteLine(" ldc.i4 " + litRecord.lexeme); factorRecord = litRecord.type; }
/// <summary> /// Parse Factor /// </summary> /// <param name="factorRecord"></param> private void Factor(ref VariableRecord factorRecord) { IdentifierRecord idRecord = new IdentifierRecord(); LiteralRecord litRecord = new LiteralRecord(); VariableType tempType = VariableType.Void; List<Parameter> parameterList = new List<Parameter>(); MethodRecord methodRecord = new MethodRecord(); methodRecord.parameterList = new List<Parameter>(); string idRecName = null; switch (lookAheadToken.tag) { case Tags.MP_INTEGER_LIT: UsedRules.WriteLine("94"); litRecord.lexeme = lookAheadToken.lexeme; litRecord.type = VariableType.Integer; Match((int)Tags.MP_INTEGER_LIT); analyzer.GenerateLitPush(litRecord, ref tempType); factorRecord.variableType = tempType; break; case Tags.MP_NOT: UsedRules.WriteLine("95"); Match((int)Tags.MP_NOT); Factor(ref factorRecord); break; case Tags.MP_LPAREN: UsedRules.WriteLine("96"); Match((int)Tags.MP_LPAREN); Expression(ref factorRecord); Match((int)Tags.MP_RPAREN); break; case Tags.MP_IDENTIFIER: UsedRules.WriteLine("97"); Identifier(ref idRecName); idRecord.lexeme = idRecName; analyzer.ProcessId(ref idRecord); analyzer.GenerateIdPush(idRecord, ref factorRecord); analyzer.processParameters(idRecord,ref methodRecord,ref parameterList); OptionalActualParameterList(parameterList); analyzer.ProcessMethod(idRecord,ref methodRecord); analyzer.GenerateCallMethod(methodRecord); break; default: Error("Expecting Factor but found " + lookAheadToken.lexeme); break; } }