CD Lab
CD Lab
h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include "spaces.h"
#include "preprocess.h"
#define MAX_SIZE 20
} *Symbol;
if(type == "id"){
n->data_type = typee;
n->Tame = "Var";
}
else{
n->return_type = typee;
n->Tame = "Func";
}
if(strcmp(str,"printf")==0 || strcmp(str,"scanf")==0 ){
n->return_type = "NULL";
}
n->arg = arg;
int main(){
//executing space function from spaces.h
space();
//executing process function from preprocess.h
process();
for(int i=0;i<MAX_SIZE;i++)
hashTable[i] = NULL;
if(isDatatype(buffer) == 1){
insert(buffer, row, col, 1);
strcpy(data_type_buffer, buffer);
}
else if(isKeyword(buffer) == 1){
insert(buffer, row, col, 1);
}
else{
insert(buffer, row, col, 0);
if(c == '('){
n = ftell(fin);
int arg=0;
c = fgetc(fin);
if(c!=')'){
arg+=1;
while (c!=')'){
c=fgetc(fin);
if(c==',')
arg+=1;
}
fseek( fin, n-1, SEEK_SET );
}
insertSymbolTable(buffer,
"func",data_type_buffer,arg);
}else
insertSymbolTable(buffer, "id",data_type_buffer,0);
data_type_buffer[0] = '\0';
}
i = 0;
if(c == '\n')
row++, col_global = 1;
buffer[0] = '\0';
}
else if(isdigit(c) != 0){
buffer[i++] = c;
col = col_global;
while(isdigit(c) != 0 || c == '.'){
c = fgetc(fin);
col_global++;
if(isdigit(c) != 0 || c == '.')
buffer[i++] = c;
}
buffer[i] = '\0';
insert("num", row, col, 0); // numerical constant
i = 0;
if(c == '\n')
row++, col_global = 1;
buffer[0] = '\0';
c = fgetc(fin);
col_global++;
}
else if(c == '\"'){
col = col_global;
buffer[i++] = c;
c = 0;
while(c != '\"'){
c = fgetc(fin);
col_global++;
buffer[i++] = c;
}
buffer[i] = '\0';
insert("String", row, col, 0); // string literals
buffer[0] = '\0';
i = 0;
c = fgetc(fin);
col_global++;
}
else{
col = col_global;
if(c == '='){ // relational and logical operators
c = fgetc(fin);
col_global++;
if(c == '='){
insert("==", row, col, 1);
}
else{
insert("=", row, col, 1);
fseek(fin, -1, SEEK_CUR);
col_global--;
}
}
if(c == '>' || c == '<' || c == '!'){
c = fgetc(fin);
col_global++;
if(c == '='){
char temp_str[2] = {c, '='};
insert(temp_str, row, col, 1);
}
else{
char temp_str[1] = {c};
insert(temp_str, row, col, 1);
fseek(fin, -1, SEEK_CUR);
col_global--;
}
}
if(isOperator(c) == 1 || isBracket(c) == 1){ //parentheses
char temp_string[1] = {c};
insert(temp_string, row, col, 1);
}
if(c == '\n')
row++, col_global = 1;
c = fgetc(fin);
col_global++;
}
}
displaySymbolTable();
return 0;
}