Ejemplo n.º 1
0
CoutStatementNode * ParserClass::CoutStatement() {
    Match(COUT_TOKEN);
    Match(INSERTION_TOKEN);
    CoutStatementNode *csn = new CoutStatementNode();
    ExpressionNode *expression = Expression();
    csn->AddExpression(expression);
    while (true) {
        TokenType tt = mScanner->PeekNextToken().GetTokenType();
        if (tt == INSERTION_TOKEN) {
            Match(INSERTION_TOKEN);
            TokenClass next = mScanner->PeekNextToken();
            if (next.GetTokenType() == ENDL_TOKEN) {
                Match(ENDL_TOKEN);
                csn->AddExpression(NULL);
            }
            else {
                ExpressionNode *nextExpression = Expression();
                csn->AddExpression(nextExpression);
            }
        }
        else {
            if (tt == ENDL_TOKEN) {
                Match(ENDL_TOKEN);
                csn->AddExpression(NULL);
            }
            Match(SEMICOLON_TOKEN);
            break;
        }
    }
    return csn;
}
Ejemplo n.º 2
0
CoutStatementNode * ParserClass::CoutStatement()
{
	CoutStatementNode * csn = new CoutStatementNode();
	this->Match(INSERTION_TOKEN);
	
	TokenType tt = this->mScanner->PeekNextToken().GetTokenType();
	switch (tt)
	{
	case ENDL_TOKEN:
		this->Match(ENDL_TOKEN);
		csn->AddExpression(NULL);
		break;
	default:
		csn->AddExpression(this->Expression());
		break;
	}

	while (true)
	{
		tt = this->mScanner->PeekNextToken().GetTokenType();

		if (tt != INSERTION_TOKEN) break;

		this->Match(INSERTION_TOKEN);

		tt = this->mScanner->PeekNextToken().GetTokenType();
		switch (tt)
		{
		case ENDL_TOKEN:
			this->Match(ENDL_TOKEN);
			csn->AddExpression(NULL);
			break;
		default:
			csn->AddExpression(this->Expression());
			break;
		}
	}
	return csn;
}