Exemple #1
0
int parseexpression() {
	int invert = 0;
	switch (token) {
		case TOK_ADD:
			token = tokeniser_next();
			break;
		case TOK_SUB:
			token = tokeniser_next();
			invert = 1;
			break;
	}
	int lhs = parseterm();
	if (invert) {
		lhs = -lhs;
	}
	if (token == TOK_ADD) {
		token = tokeniser_next();
		int rhs = parseterm();
		if (token == TOK_ERR) {
			return 0;
		}
		return lhs + rhs;
	}
	if (token == TOK_SUB) {
		token = tokeniser_next();
		int rhs = parseterm();
		if (token == TOK_ERR) {
			return 0;
		}
		return lhs - rhs;
	}
	return lhs;
}
Exemple #2
0
static void parseapplication(void)
{
  if(tokentype == TYPEID)
  {
    int count = 1;
    push(gettemplate(tokenval));
    gettoken();
    while(tokentype == NUMBER
       || tokentype == IDENTIFIER
       || tokentype == TYPEID
       || tokentype == CHARACTER
       || tokentype == STRING
       || tokentype == LPAR
       || tokentype == LBRACK
       || tokentype == LACC)
    {
      parseterm();
      count++;
    }
    makecompound(STRUCT, count);
  }
  else if(tokentype == OPERATOR)
    parsename();
  else
    parseterm();
  while(tokentype == NUMBER
     || tokentype == IDENTIFIER
     || tokentype == TYPEID
     || tokentype == CHARACTER
     || tokentype == STRING
     || tokentype == LPAR
     || tokentype == LBRACK
     || tokentype == LACC)
  {
    parseterm();
    makeinverse(APPLY);
  }
  if(tokentype == OPERATOR && strcmp(tokenval, ":") == 0)
  {
    gettoken();
    if(tokentype == RPAR)
    {
      push(gettemplate(":"));
      make(APPLY);
    }
    else
    {
      parseapplication();
      makeinverse(LIST);
    }
  }
}