Beispiel #1
0
AST* Parser::statement(Scope* ps)
{
    AST* ret = NULL;

    if (expect(";"))
    {
        ret = emptyStatement();
    }
    else if (expect("var"))
    {
        ret = varStatement(ps);
        opteol();
    }
    else if (expect("{"))
    {
        ret = block(ps);
        opteol();
    }
    else if (expect("if"))
    {
        ret = ifStatement(ps);
    }
    else if (expect("switch"))
    {
        ret = switchStatement(ps);
    }
    else if (expect("do"))
    {
        ret = doStatement(ps);
        opteol();
    }
    else if (expect("while"))
    {
        ret = whileStatement(ps);
    }
    else if (expect("for"))
    {
        ret = forStatement(ps);
    }
    else if (expect("with"))
    {
        ret = withStatement(ps);
    }
    else if (expect("continue"))
    {
        ret = continueStatement();
        opteol();
    }
    else if (expect("break"))
    {
        ret = breakStatement();
        opteol();
    }
    else if (expect("return"))
    {
        ret = returnStatement(ps);
        opteol();
    }
    else if (expect("try"))
    {
        ret = tryStatement(ps);
    }
    else if (expect("throw"))
    {
        ret = throwStatement(ps);
        opteol();
    }
    else
    {
        ret = expression(0, ps);
        opteol();
    }

    return ret;
}
Beispiel #2
0
void ArduinoBASIC::handleChar ( PSTRStrings & cannedProgram, char ch  )
{
  int gotStatement = statements.matchString (ch, false);
  int gotCommand   = commands.matchString   (ch, false);
  char c;
  int value;
    
  if (lastStatement > -1)
  { 
    // Save uninterpretted parameters to EEPROM
    continueStatement (ch); 
    if (ch == 13) 
      lastStatement = -1; // done
  }
  else if (gotStatement > -1)
  { 
    debugUtils.printPSTR ( PSTR ( "Matched on statement: " ) );
    statements.printString ( gotStatement );
    eepromProgram.addCh (gotStatement, true);
    lastStatement = gotStatement;
  }
  
  else // Check for command
  {
        
    if (gotCommand > -1) 
    {    
      //debugUtils.printPSTR ( PSTR ( "gotCommand: " ) );
      //Serial.println ( gotCommand );
      //commands.printString ( gotCommand ); 
      //debugUtils.printPSTR ( PSTR ( "\n" ) );
       
      switch (gotCommand)
      {
        case 0: 
          debugUtils.printPSTR ( PSTR ( "Commands: \n" ));
          commands.show(1,NUMBER_OF_COMMANDS);
          debugUtils.printPSTR ( PSTR ( "\nstatements: \n" ));
          statements.show(1,NUMBER_OF_STATEMENTS);
          break;
        case 1:
          eepromProgram.showSteps();
          break;
        case 2:
          eepromProgram.clear();
          break;
        case 3:
          eepromProgram.dump();
          break;
        case 4: 
          eepromProgram.run();
          break;    
        case 5: // remove a line
          value = eepromProgram.readDec ( &c);
          eepromProgram.removeLine(value);
          break;  
        case 6: // Load program from canned list
          loadProgram ( cannedProgram );
          break;
        case 7: // Stop the program 
          eepromProgram.writeTestState (0); 
          debugUtils.printPSTR ( PSTR ( "*Test now idle*" ) );
          break; 
		case 8: // Show test state
          debugUtils.printPSTR ( PSTR ( "Test state: " ) );
          Serial.println ( eepromProgram.testState);
          break;		  
        default:
          break;
      }
    }  
  }
}