Esempio n. 1
0
constant_t node_add_eval(node_t*n, environment_t* env)
{
    double sum = 0;
    int t;
    for(t=0;t<n->num_children;t++) {
	sum += AS_FLOAT(EVAL_CHILD(t));
    }
    return float_constant(sum);
}
Esempio n. 2
0
constant_t node_sub_eval(node_t*n, environment_t* env)
{
    constant_t left = EVAL_CHILD(0);
    constant_t right = EVAL_CHILD(1);
    return float_constant(AS_FLOAT(left) - AS_FLOAT(right));
}
Esempio n. 3
0
//main function
int main()
{
	initialize_Symbol_Table();
	
	remove("a4_1.out");
	
	char input[1000];
	
	token t;
	int i;
	
	//loop for rading lines of source code into input buffer	
	while(gets(input))
	{
		lexemeBegin = 0;
		
		while(input[lexemeBegin]!='\0'&&input[lexemeBegin]!='\n' &&input[lexemeBegin]!='\r')  //while end of line is not found
		{
			while(input[lexemeBegin]==' ' || input[lexemeBegin] == '\t')
				lexemeBegin++;
						
			//checking for keywords and identifiers
			t = identifier_keyword(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}
			
			//checking for integer constants
			t = integer_constant(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}
			
			//checking for floating point number constants
			t = float_constant(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}

			//checking for arithmetic operators
			t = arithmetic_operator(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}

			//checking for assignment operators
			t = assignment_operator(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}

			//checking for relational operators
			t = relational_operator(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}

			//checking for special symbols
			t = special_symbol(input);
			if(t.tokenID!=NOTOK)
			{
				write_token(t);
				continue;
			}
			
			//checking for comments
			comment(input);
			//checking erroneous lexeme
			error_condition(input);
		}
	}	
}