Exemple #1
0
//-----------------------------------------
int termList(int left)
{
	int right;
	int temp;
	int expVal;

    switch(currentToken -> kind)
    {
      case PLUS:
        consume(PLUS);
        right = term();
        temp = add(left, right);
		expVal = termList(temp);
        return expVal;
        break;
      case RIGHTPAREN:
      case SEMICOLON:
		return left;
        ;
        break;
      default:
        displayErrorLoc();
        printf(
           "Scanning %s, expecting \"+\", \")\", or \";\"\n",
           currentToken -> image);
        abend();
    }
}
Exemple #2
0
//-----------------------------------------
int expr(void)
{
    int left, termVal;
    left = term();
    termVal = termList(left);
    return termVal;
}
Exemple #3
0
static int ruleList(int symbolIndex){
	int length;
	int result;

	assert(nRULES < MAX_RULES);
	RULENAME[nRULES] = symbolIndex;


	result = termList();
	nRULES += 1;

	if(result){
		return result;
	}

	if(TOKENNAME[tokenIndex] == TOKNAME_PIPE){
		tokenIndex++;
		result = ruleList(symbolIndex);
		if(result){
			return result;
		}
		return 0;
	} else {
		return 0;
	}
}
Exemple #4
0
//-----------------------------------------
int expr(void)
{
	int left;
	int expVal;

    left = term();
    expVal = termList(left);
	return expVal;
}
Exemple #5
0
//-----------------------------------------
int termList(int left)
{
    int right, temp, expVal, result;
	char temp1[MAX], temp2[MAX];

    switch(currentToken -> kind)
    {
      case PLUS:
        consume(PLUS);
        right = term();
        
		if (isConstant(left) && isConstant(right))
		{
			result = atoi(dwValue[left]) + atoi(dwValue[right]);		
			if (result >= 0)
			{
				sprintf(temp1, "@%d", result);
				sprintf(temp2, "%d", result);
				temp = enter(temp1, temp2, FALSE);
			}
			else
			{
				sprintf(temp1, "@_%d", result);
				sprintf(temp2, "%d", result);
				temp = enter(temp1, temp2, FALSE);
			}
		}
		else
		{
			temp = add(left, right);
		}
        expVal = termList(temp);
        return expVal;
		break;
      case RIGHTPAREN:
      case SEMICOLON:
        ;
        return left;
      default:
        displayErrorLoc();
        printf(
           "Scanning %s, expecting \"+\", \")\", or \";\"\n",
           currentToken -> image);
        abend();
        return -1;
    }
}
Exemple #6
0
static int termList(){
	int result;

	if(TOKENNAME[tokenIndex] == TOKNAME_TERMINAL
			|| TOKENNAME[tokenIndex] == TOKNAME_NONTERMINAL
			|| TOKENNAME[tokenIndex] == TOKNAME_SIGMA){

		if(TOKENNAME[tokenIndex] != TOKNAME_SIGMA){
			if(TOKENNAME[tokenIndex] == TOKNAME_TERMINAL){
				assert(RULESIZE[nRULES] < MAX_RULE_SIZE);
				RULE[nRULES][RULESIZE[nRULES]] = TOKENVALUE[tokenIndex];
				RULESIZE[nRULES]++;
			} else if(TOKENNAME[tokenIndex] == TOKNAME_NONTERMINAL){
				assert(RULESIZE[nRULES] < MAX_RULE_SIZE);
				RULE[nRULES][RULESIZE[nRULES]] = TOKENVALUE[tokenIndex];
				RULESIZE[nRULES]++;
			}
		}

		tokenIndex++;

		if(TOKENNAME[tokenIndex] == TOKNAME_TERMINAL
				|| TOKENNAME[tokenIndex]== TOKNAME_NONTERMINAL){
			result = termList();
			if(result){
				return result;
			}
			return 0;
		} else {
			return 0;
		}
	} else {
		parserErrorNumber = PARSERR_EXPECTED_TERMINAL_NONTERMINAL;
		return -1;
	}
}