コード例 #1
0
        /// <summary>
        /// Parse ForStatement
        /// </summary>
        private void ForStatement()
        {
            IdentifierRecord controlVariableRecord = new IdentifierRecord();
            VariableRecord finalValueRecord = new VariableRecord();
            VariableRecord controlStatementRecord = new VariableRecord();
            string controlLabelRecord = string.Empty;
            string loopLabel = string.Empty;
            ControlRecord stepValueRecord = new ControlRecord();

            switch(lookAheadToken.tag)
            {
                case Tags.MP_FOR:
                    UsedRules.WriteLine("57");
                    Match((int)Tags.MP_FOR);
                    ControlVariable(ref controlVariableRecord);
                    Match((int)Tags.MP_ASSIGN);
                    InitialValue(ref controlVariableRecord);
                    analyzer.GenerateLabel(ref controlLabelRecord);
                    analyzer.GenerateIdPush(controlVariableRecord,ref controlStatementRecord);
                    StepValue(ref stepValueRecord);
                    FinalValue(ref finalValueRecord);
                    analyzer.GenerateBranch(ref loopLabel, stepValueRecord.branchType);
                    Match((int)Tags.MP_DO);
                    Statement();
                    analyzer.GenerateIncrement(ref controlVariableRecord, stepValueRecord.addingOperator);
                    analyzer.GenerateBranch(ref controlLabelRecord, BranchType.br);
                    analyzer.GenerateLabel(ref loopLabel);
                    break;
                default:
                    Error("Expecting ForStatement found " + lookAheadToken.lexeme);
                    break;
            }
        }
コード例 #2
0
 /// <summary>
 /// Parse StepValue
 /// </summary>
 /// <param name="stepValueRecord"></param>
 private void StepValue(ref ControlRecord stepValueRecord)
 {
     switch (lookAheadToken.tag)
     {
         case Tags.MP_TO: // "to"
             UsedRules.WriteLine("60");
             stepValueRecord.addingOperator = "add";
             stepValueRecord.branchType = BranchType.bgt;
             Match((int)Tags.MP_TO);
             break;
         case Tags.MP_DOWNTO: //"downto"
             UsedRules.WriteLine("61");
             stepValueRecord.addingOperator = "sub";
             stepValueRecord.branchType = BranchType.blt;
             Match((int)Tags.MP_DOWNTO);
             break;
         default:
             Error("Expecting StepValue but found " + lookAheadToken.lexeme);
             break;
     }
 }