void CompilationEng::compileStatements()
{
	while(true)
	{
		getToken();
		if(m_token == "}")
		{
			m_bPutback = true;
			break;
		}
		else 
		{
			if(m_bZeroStatements)
			{
				printNonterminal("statements");
				numOfTab++;
			}
			m_bZeroStatements = false;
			if(m_token == "let")
			{
				compileLet();
				m_bZeroStatements =false;
			}
			else if(m_token == "if")
			{
				compileIf();
				m_bZeroStatements=false;
			}
			else if(m_token == "while")
			{
				compileWhile();
				m_bZeroStatements = false;
			}
			else if(m_token == "do")
			{
				compileDo();
				m_bZeroStatements =false;
			}
			else if(m_token == "return")
			{
				compileReturn();
				m_bZeroStatements=false;
			}
			else
			{
				m_ofs << m_token << endl;
				break;
			}
		}
		
	}
	if(!m_bZeroStatements)
	{
		numOfTab--;
		printNonterminal("statements",false); //end of statements
	}
	m_bZeroStatements = true;
}
Esempio n. 2
0
void CompilationEngine::compileStatements()
{
    /*  statements: statement*
        statement: letStatement | ifStatement | whileStatement | doStatement | returnStatement */

    tagNonTerminal("statements");

    while (jt.tokenType() == TokenType::kKEYWORD && isStatement(jt.getToken())) {

        switch (jt.keyword()) {

            case Keyword::kLET:
                compileLet();
                break;

            case Keyword::kDO:
                compileDo();
                break;

            case Keyword::kIF:
                compileIf();
                break;

            case Keyword::kWHILE:
                compileWhile();
                break;

            case Keyword::kRETURN:
                compileReturn();

            default:
                break;

        }
    }

    untagNonTerminal("statements");
}