Example #1
0
int exp1()
{
	/* 
	 * exp1 -> MINUS term exp1
	 * 		 | MINUS term exp2
	 *       | exp2
	 */

	if(match(MINUS))
	{
		advance();
		term();
		if(match(MINUS))
		{
			advance();
			term();
			exp1();
			printf("-\n");
		}
		expr_prime();
		printf("-\n");
	}
	else
	{
		expr_prime();
	}
}
Example #2
0
expression()
{
    /* expression -> term expression' */

    term();
    expr_prime();
}
Example #3
0
expr_prime()
{
    /* expression' -> PLUS term expression'
     *              | epsilon
     */

    if( match( PLUS ) )
    {
        advance();
        term();
        expr_prime();
    }
}
static boolean expr() {
  if(DEBUG) {
    printf("Looking for an <expr>\n");
  }
	
  if(term()) {
    if(expr_prime()) {
      return TRUE;
    } else {
      printf("<term> not followed by <expr-prime> in <expr>\n");
      return FALSE;
    }
  } else {
    printf("<term> not found in <expr>\n");
    return FALSE;
  }
}
static boolean expr_prime() {
  if(DEBUG) {
    printf("Looking for an <expr-prime>\n");
  }
	
  if(additive_op()) {
    if(term()) {
      if(expr_prime()) {
	return TRUE;
      } else {
	printf("<term> not followed by <expr-prime> in <expr-prime>\n");
	return FALSE;
      }
    } else {
      printf("<additive-op> not followed by <term> in <expr-prime>\n");
      return FALSE;
    }
  } else {
    return TRUE;
  }
}