Exemplo n.º 1
0
        public static ForLoopEntry Make(int step, int lhs, int rhs, int increment)
        {
            ForLoopEntry entry = new ForLoopEntry();

            entry.Step      = step;
            entry.LHS       = lhs;
            entry.RHS       = rhs;
            entry.Increment = increment;
            return(entry);
        }
Exemplo n.º 2
0
 //------------------------------------------------------------------------------------------------------------
 private void forStatement(string[] tokens, int lineNumber)
 {
     // Place increment value into the symbol table
     _symbolTable.AddConst(FOR_LOOP_INCREMENT);
     if (findNext(out int intNextLineLocation)) // validate there is a 'next' statement
     {
         // validate that the 'for' statement following the correct syntax
         // [2] = variable, [3] = comparator, [4] = var/const, [5] = 'to', [6] = var/const
         string strLHS   = tokens[2];
         string strRHS   = tokens[4];
         string strCheck = tokens[6];
         if (Toolbelt.IsValidVariable(strLHS) &&
             tokens[3] == "=" &&
             tokens[5] == "to")
         {
             putInSymbolTable(tokens);
             // Format the assignment string so it can be properly processed
             string assignment = $"00 let {strLHS} = {strRHS}";
             letStatement(assignment.Split(' '), lineNumber);
             // after let statement is process, the next entry will be the start of the commands in the loop
             _forLoopEntries.Push(ForLoopEntry.Make(
                                      step: _workingLineNumber,
                                      lhs: _symbolTable.Find(strLHS).Location(),
                                      rhs: _symbolTable.Find(strCheck).Location(),
                                      increment: FOR_LOOP_INCREMENT
                                      ));
         }
         else
         {
             throw new SystemException($"Invalid 'for' statement -on code line {lineNumber}");
         }
     }
     else
     {
         throw new SystemException($"'for' missing 'next' statment -on code line {lineNumber}");
     }
 }