Beispiel #1
0
CompoundStatementPtr Parser::parseCompoundStatement()
{
    if (!match(TokenType::Begin)) {
        reportError(ErrorCodes::ExpectedBegin);

        panic(compoundStatementFollow, compoundStatementFollowSize);
        return CompoundStatementPtr();
    }

    StatementsPtr statements = parseOptionalStatements();
    if (m_errorCode && m_errorCode != ErrorCodes::ExpectedStatement) {
        panic(compoundStatementFollow, compoundStatementFollowSize);
        return CompoundStatementPtr();
    }

    m_errorCode = ErrorCodes::NoError;

    if (!match(TokenType::End)) {
        reportError(ErrorCodes::ExpectedEnd);

        panic(compoundStatementFollow, compoundStatementFollowSize);
        return CompoundStatementPtr();
    }

    CompoundStatementPtr compoundStatement(new CompoundStatement);
    compoundStatement->statements = statements;

    return compoundStatement;
}
// <statement>		::=	<simple statement>
//                      | <complex statement>
void SyntaxAnalyzer::statement(std::set<symboltype> followers)
{
    //ako neterminala ne se vika ot drugo mqsto
    //ne se pravi startcheck & endcheck v tqh a samo v parenta
    if (statementStarters.find(symbol) != statementStarters.end()) {
        switch(symbol) {
            case ident: assignment(followers); break;
            case beginsy: compoundStatement(followers); break;
            case ifsy: ifStatement(followers); break;
            case whilesy: whileStatement(followers); break;
            case readsy: readStatement(followers); break;
            case writesy: writeStatement(followers); break;
            default:
                break;
        } // swtich
    } else {
        syntaxerror(othersy);
    }
} // statement()
Beispiel #3
0
void statement(void)
{
  STYPE *symPtr;     /* Save Symbol Table pointer to token */

  TRACE(lstFile,"[statement");

  /* Generate file/line number pseudo-operation to facilitate P-Code testing */

  pas_GenerateLineNumber(FP->include, FP->line);

  /* We will push the string stack pointer at the beginning of each
   * statement and pop the string stack pointer at the end of each
   * statement.  Subsequent optimization logic will scan the generated
   * pcode to ascertain if the push and pops were necessary.  They
   * would be necessary if expression parsing generated temporary usage
   * of string stack storage.  In this case, the push will save the
   * value before the temporary usage and the pop will release the
   * temporaray storage.
   */

  pas_GenerateSimple(opPUSHS);

  /* Process the statement according to the type of the leading token */

  switch (token)
    {
      /* Simple assignment statements */

    case sINT :
      symPtr = tknPtr;
      getToken();
      pas_Assignment(opSTS, exprInteger, symPtr, symPtr->sParm.v.parent);
      break;
    case sCHAR :
      symPtr = tknPtr;
      getToken();
      pas_Assignment(opSTSB, exprChar, symPtr, symPtr->sParm.v.parent);
      break;
    case sBOOLEAN :
      symPtr = tknPtr;
      getToken();
      pas_Assignment(opSTSB, exprBoolean, symPtr, NULL);
      break;
    case sREAL :
      symPtr = tknPtr;
      getToken();
      pas_LargeAssignment(opSTSM, exprReal, symPtr, symPtr->sParm.v.parent);
      break;
    case sSCALAR :
      symPtr = tknPtr;
      getToken();
      pas_Assignment(opSTS, exprScalar, symPtr, symPtr->sParm.v.parent);
      break;
    case sSET_OF :
      symPtr = tknPtr;
      getToken();
      pas_Assignment(opSTS, exprSet, symPtr, symPtr->sParm.v.parent);
      break;
    case sSTRING :
    case sRSTRING :
      symPtr = tknPtr;
      getToken();
      pas_StringAssignment(symPtr, symPtr->sParm.v.parent);
      break;

      /* Complex assignments statements */

    case sSUBRANGE :
    case sRECORD :
    case sRECORD_OBJECT :
    case sPOINTER :
    case sVAR_PARM :
    case sARRAY :
      pas_ComplexAssignment();
      break;

      /* Branch, Call and Label statements */

    case sPROC         : pas_ProcStatement(); break;
    case tGOTO         : pas_GotoStatement(); break;
    case tINT_CONST    : pas_LabelStatement(); break;

      /* Conditional Statements */

    case tIF           : pas_IfStatement(); break;
    case tCASE         : pas_CaseStatement(); break;

      /* Loop Statements */

    case tREPEAT       : pas_RepeatStatement(); break;
    case tWHILE        : pas_WhileStatement(); break;
    case tFOR          : pas_ForStatement(); break;

      /* Other Statements */

    case tBEGIN        : compoundStatement(); break;
    case tWITH         : pas_WithStatement(); break;

      /* None of the above, try standard procedures */
    default            : builtInProcedure(); break;

  } /* end switch */

  /* Generate the POPS that matches the PUSHS generated at the begining
   * of this function (see comments above).
   */

  pas_GenerateSimple(opPOPS);

  TRACE(lstFile,"]");

} /* end statement */
// <statpart>		::=	<compoundstatement>
void SyntaxAnalyzer::statementPart(std::set<symboltype> followers)
{
    compoundStatement(followers);
} // statpart( )