Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

bool Parser::processAssignment ( const QString &  line  ) 

Returns:
whether it was an assignment (which might not have been in the proper form).

Definition at line 461 of file parser.cpp.

References Microbe::addVariable(), Microbe::alias(), PIC14::isValidPort(), PIC14::isValidTris(), Microbe::isValidVariableName(), mistake(), Variable::name(), PortPin::pin(), PIC14::saveResultToVar(), PIC14::Ssetlh(), PIC14::SsevenSegment(), PIC14::Stristate(), Statement::tokenise(), PIC14::toPortPin(), Variable::type(), and Microbe::variable().

Referenced by parse().

{
      QStringList tokens = Statement::tokenise(line);
      
      // Have to have at least 3 tokens for an assignment;
      if ( tokens.size() < 3 )
            return false;
      
      QString firstToken = tokens[0];

      firstToken = mb->alias(firstToken);
      // Well firstly we look to see if it is a known variable. 
      // These can include 'special' variables such as ports
      // For now, the processor subclass generates ports it self
      // and puts them in a list for us.
      

      // Look for port variables first.
      if ( firstToken.contains(".") )
      {
            PortPin portPin = m_pPic->toPortPin( firstToken );
            
            // check port is valid
            if ( portPin.pin() == -1 )
                  mistake( Microbe::InvalidPort, firstToken );
            // more error checking
            if ( tokens[1] != "=" )
                  mistake( Microbe::UnassignedPin );
            
            QString state = tokens[2];
            if( state == "high" )
                  m_pPic->Ssetlh( portPin, true );
            else if( state == "low" )
                  m_pPic->Ssetlh( portPin, false );
            else
                  mistake( Microbe::NonHighLowPinState );
      }
      // no dots, lets try for just a port name
      else if( m_pPic->isValidPort( firstToken ) )
      {
            // error checking
            if ( tokens[1] != "=" )
                  mistake( Microbe::UnassignedPort, tokens[1] );
            
            Expression( m_pPic, mb, m_currentSourceLine, false ).compileExpression(line.mid(line.find("=")+1));
            m_pPic->saveResultToVar( firstToken );
      }
      else if ( m_pPic->isValidTris( firstToken ) )
      {
            if( tokens[1] == "=" )
            {
                  Expression( m_pPic, mb, m_currentSourceLine, false ).compileExpression(line.mid(line.find("=")+1));
                  m_pPic->Stristate(firstToken);
            }
      }
      else
      {
            // Is there an assignment?
            if ( tokens[1] != "=" )
                  return false;
            
            if ( !mb->isValidVariableName( firstToken ) )
            {
                  mistake( Microbe::InvalidVariableName, firstToken );
                  return true;
            }
            
            // Don't care whether or not the variable is new; Microbe will only add it if it
            // hasn't been defined yet.
            mb->addVariable( Variable( Variable::charType, firstToken ) );
            
            Expression( m_pPic, mb, m_currentSourceLine, false ).compileExpression(line.mid(line.find("=")+1));
            
            Variable v = mb->variable( firstToken );
            switch ( v.type() )
            {
                  case Variable::charType:
                        m_pPic->saveResultToVar( v.name() );
                        break;
                        
                  case Variable::keypadType:
                        mistake( Microbe::ReadOnlyVariable, v.name() );
                        break;
                        
                  case Variable::sevenSegmentType:
                        m_pPic->SsevenSegment( v );
                        break;
                        
                  case Variable::invalidType:
                        // Doesn't happen, but include this case to avoid compiler warnings
                        break;
            }
      }
      
      return true;
}


Generated by  Doxygen 1.6.0   Back to index