コード例 #1
0
ファイル: Parser.cpp プロジェクト: Jeffhabs/School
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;
}
コード例 #2
0
ファイル: Parser.cpp プロジェクト: sstephens/sstephens1
CoutStatementNode * Parser::Cout(){
	CoutStatementNode * coutnode = new CoutStatementNode();
	Match(COUT_TOKEN);
	Match(INSERTION_TOKEN);
	ExpressionNode * expr = Expression();
	coutnode->AddCnode(expr);
	while(true){	
		Token next = scan->PeekNextToken();
		if(next.GetTokenType() == INSERTION_TOKEN){
			Match(next.GetTokenType());
			Token nNext = scan->PeekNextToken();
			if(nNext.GetTokenType() == ENDL_TOKEN){
				Match(ENDL_TOKEN);
				coutnode->AddCnode(NULL);
			}
			else{
				ExpressionNode * nexpr = Expression();
				coutnode->AddCnode(nexpr);
			}
		}
		else{
			if(next.GetTokenType() == ENDL_TOKEN){
				Match(ENDL_TOKEN);
				coutnode->AddCnode(NULL);
			}
			Match(SEMICOLIN_TOKEN);
			break;
		}
	}
	MSG("Creating a CoutStatementNode.");
	return coutnode;
}
コード例 #3
0
ファイル: Parser.cpp プロジェクト: kevbateman/cs4550
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;
}