Ejemplo n.º 1
0
void CompilationEngine::compileSubroutineCall(string subName)
{
    /*
        subroutineName '(' expressionList ')' |
        (className | varName) '.' subroutineName '(' expression ')'
    */

    string oldTok = jt.getToken();
    jt.setToken(subName);
    readIdentifier();
    jt.setToken(oldTok);

    if (jt.tokenType() == TokenType::kSYMBOL && jt.symbol() == '(') {

        readSymbol('(');
        nextToken();
        compileExpressionList();
        readSymbol(')');

    } else {

        readSymbol('.');
        nextToken();
        readIdentifier();
        nextToken();
        readSymbol('(');
        nextToken();
        compileExpressionList();
        readSymbol(')');

    }

    nextToken();
}
Ejemplo n.º 2
0
void CompilationEng::compileSubroutineCall()
{
	printCurrentToken(); //<id> </id>
	getToken();
	if(m_token == "(")
	{
		printCurrentToken(false); //<symbol> ( </symbol>
		compileExpressionList();
		printCurrentToken(); //<symbol> ) </symbol>
	}
	else if(m_token == ".")
	{
		printCurrentToken(false); //<symbol> . </symbol>
		printCurrentToken(); //<id> subroutineName </symbol>
		printCurrentToken(); //<symbol> ( </symbol>
		compileExpressionList();
		printCurrentToken(); //<symbol> ) </symbol>
	}
}
Ejemplo n.º 3
0
void CompilationEng::compileTerm()
{
	getToken();
	printNonterminal("term");
	numOfTab++;

	if(tokenizer.tokenType() == "keyword")
	{
		printCurrentToken(false); //<keyword> keyword </keyword>
	}
	else if(tokenizer.tokenType() == "stringconst")
	{
		printCurrentToken(false);
	}
	else if(tokenizer.tokenType() == "integerConstant")
	{
		printCurrentToken(false);
	}
	else if(tokenizer.tokenType() == "symbol")
	{
		if(m_token == "(") // (expression)
		{
			printCurrentToken(false);
			compileExpression();
			printCurrentToken();  //<symbol> )</symbol>
		}
		else if(m_token == "-" || m_token == "~")
		{
			printCurrentToken(false); //<symbol> -|~ </symbol>
			compileTerm();
		}
		else //empty term
		{

			m_bPutback = true;
			}
	}
	else if(tokenizer.tokenType() == "identifier")
	{
		getToken();
		if(m_token == "[") //varName [ expression ]
		{
			printToken(stringStack);
			printCurrentToken(false);
			compileExpression();
			printCurrentToken(); //<symbol> ] </symbol>
		}
		else if(m_token == "(" ) // subroutineCall
		{
			printToken(stringStack);
			printCurrentToken(false); //<symbol> ( </symbol>
			compileExpressionList();
			printCurrentToken();
		}
		else if(m_token == ".") 
		{
			printToken(stringStack); //className
			printCurrentToken(false); //<symbol> . </symbol>
			printCurrentToken(); //<id> subroutineName </id>
			printCurrentToken(); //<symbol> ( </symbol>
			compileExpressionList();
			printCurrentToken(); //<symbol> ) </symbol>
		}
		else  if(m_sOp.count(m_token[0]) > 0) //term op term
		{
			printToken(stringStack); //<id> </id>
			m_bPutback = true;
		}
		else//varName 
		{
			printToken(stringStack); //<id> varName </id>
			m_bPutback = true;
		}
	}

	numOfTab--;
	printNonterminal("term",false); //end of term
}