Exemplo n.º 1
0
ExpressionNode* Parser::TermPrime(ExpressionNode* param)
{
    if(currenttoken->type == Multiplication)
    {
        ConsumeToken();
        ExpressionNode* expression=Power();
        return TermPrime(new MultiplicationNode(param,expression));
    }
    else if(currenttoken->type == RealDivision)
    {
        ConsumeToken();
        ExpressionNode* expression=Power();
        return TermPrime(new DivisionNode(param,expression));
    }
    else if(currenttoken->type == IntegerDivision)
    {
        ConsumeToken();
        ExpressionNode* expression=Power();
        return TermPrime(new DivNode(param,expression));
    }
    else if(currenttoken->type == Mod)
    {
        ConsumeToken();
        ExpressionNode* expression=Power();
        return TermPrime(new ModNode(param,expression));
    }
    else
    {
        return param;
    }
}
Exemplo n.º 2
0
void TermPrime(void)
{
   switch (Symb.type) {
   case TIMES:
      /* T' -> * F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '*');      /* BinOp.dop = '*' */
      TermPrime();
      break;
   case DIVIDE:
      /* T' -> / F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '/');      /* BinOp.dop = '/' */
      TermPrime();
      break;
   case PLUS:
   case MINUS:
   case RPAR:
   case EOI:
      /* T' -> e */
      break;
   default:
      ExpansionError("T'", Symb.type);
   }
}
Exemplo n.º 3
0
bool syntaxparser::TermPrime(){
	bool bTermPrime = false;
	if (lexeme == "*"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= *<Factor><TermPrime>" << endl;
			printproduction("<TermPrime> ::= *<Factor><TermPrime>");
		}
		Factor();
		project3.gen_inst("MUL","-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '*' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '*' on boolean");

		TermPrime();	
		bTermPrime = true;		
	}
	else if (lexeme == "/"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= /<Term><FactorPrime>" << endl;
			printproduction("<TermPrime> ::= /<Term><FactorPrime>");
		}
		bTermPrime = true;
		Factor();
		project3.gen_inst("DIV", "-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '/' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '/' on boolean");

		TermPrime();
	}
	else{
		bTermPrime = true;
		if(displayFlag){
			cout << "<TermPrime> ::= epsilon" << endl;
			printproduction("<TermPrime> ::= epsilon");
		}
	}
	return bTermPrime;
}
Exemplo n.º 4
0
void TermPrime()
{
   switch (Symb.type) {
   case TIMES:
      Symb = readLexem();
      Factor();
      Gener(BOP, Times);
      TermPrime();
      break;
   case DIVIDE:
      Symb = readLexem();
      Factor();
      Gener(BOP, Divide);
      TermPrime();
      break;
   default:
      break;
   }
}
Exemplo n.º 5
0
// Purpose: Tests the production rule for term
bool syntaxparser::Term(){
	bool bTerm = false;
	if(displayFlag){
		cout << "<Term> ::= <Factor><TermPrime>" << endl;
		printproduction("<Term> ::= <Factor><TermPrime>");
	}
	Factor();  
	TermPrime();
	bTerm = true;
	return bTerm;
}
Exemplo n.º 6
0
Node *TermPrime(Node *Dvalue)
{
   switch (Symb.type) {
   case TIMES:
      /* T' -> * F T' */
      Symb = readLexem();
      return TermPrime(new BinOp('*', Dvalue, Factor()));
   case DIVIDE: 
      /* T' -> / F T' */
      Symb = readLexem();
      return TermPrime(new BinOp('/', Dvalue, Factor()));
   case PLUS:
   case MINUS:
   case RPAR:
   case EOI:
      /* T' -> e */
      return Dvalue;
   default:
      ExpansionError((char*) "T'", Symb.type);
   }
}
Exemplo n.º 7
0
void Term(void) {
   switch (Symb.type) {
   case IDENT:
   case LPAR:
      printf("(4) T -> F T'\n");
      Factor();
      TermPrime();
      break;
   default:
      ExpansionError("T", Symb.type);
   }
}
Exemplo n.º 8
0
/* <Term Prime> ::= * <Factor> <Term Prime> | / <Factor> <Term Prime> | epsilon */
void SyntaxAnalyzer::TermPrime()
{
    
    if(rrr == o_multiply)
    {
        NextRecord();
		logger.Log("<Term Prime> ::= * <Factor> <Term Prime>");
		Factor();
	    TermPrime();
    }
    else if(rrr == o_divide)
    {
        NextRecord();
		logger.Log("<Term Prime> ::= / <Factor> <Term Prime>");
        Factor();
        TermPrime();
    }
    else
    {
		logger.Log("<Term Prime> ::= epsilon");
    }
}
Exemplo n.º 9
0
void TermPrime(void) {
   switch (Symb.type) {
   case TIMES:
      printf("(5) T' -> * F T'\n");
      Compare(TIMES);
      Factor();
      TermPrime();
      break;
   case DIVIDE:
      printf("(5) T' -> / F T'\n");
      Compare(DIVIDE);
      Factor();
      TermPrime();
      break;
   case PLUS:
   case MINUS:
   case RPAR:
   case EOI:
      printf("(6) T' -> e\n");
      break;
   default:
      ExpansionError("T'", Symb.type);
   }
}
Exemplo n.º 10
0
Node *Term(void)
{
   /* T -> F T' */
   return TermPrime(Factor());
}
Exemplo n.º 11
0
void Term()
{
   Factor();
   TermPrime();
}
Exemplo n.º 12
0
ExpressionNode *Parser::Term()
{
    ExpressionNode * expression=Power();
    return TermPrime(expression);
}
Exemplo n.º 13
0
void Term(void)
{
   /* T -> F T' */
   Factor();
   TermPrime();
}
Exemplo n.º 14
0
/* <Term> ::= <Factor> <Term Prime> */
void SyntaxAnalyzer::Term()
{
	Factor();
	TermPrime();
    logger.Log("<Term> ::= <Factor><Term Prime>");
}