コード例 #1
0
ファイル: Parser.cpp プロジェクト: asgeir/old-school-projects
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;
}
コード例 #2
0
ファイル: parser.cpp プロジェクト: nicolai490/---endur
void Parser::parseCompoundStatement(){
	match(tc_BEGIN);
	if(m_parserError){
		TokenCode synch[] = {tc_BEGIN, tc_IF, tc_WHILE, tc_ID, tc_END, tc_NONE};
		recover(synch);
//		if(isNext(tc_BEGIN)){
//			match(tc_BEGIN);
//		}
	}
	parseOptionalStatements();
	match(tc_END);
	if(m_parserError){
		TokenCode synch[] = {tc_END, tc_DOT, tc_SEMICOL, tc_ELSE, tc_NONE};
		recover(synch);
//		if(isNext(tc_END)){
//			match(tc_END);
//		}
	}
}