Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ass 5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lex.yy.c: y.tab.h ass5_12CS10037.l ass5_12CS10037_translator.o
flex ass5_12CS10037.l

y.tab.c: ass5_12CS10037.y
yacc -dtv ass5_12CS10037.y
yacc -dt --warnings=none ass5_12CS10037.y



Expand Down
21 changes: 18 additions & 3 deletions ass 5/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ bool sortCompare(const SFields &s1,const SFields& s2)
return true;
return false;
}
bool parCom(const SFields &s1,const SFields& s2)
{
if(s1.parNum<s2.parNum)
return true;
return false;
}

SymbolTable::SymbolTable()
:n(0),offset(0),paramNum(0)
{
nameindex.clear();
table.clear();
table.reserve(100);
table.reserve(100000);
}

Fields* SymbolTable::gentemp(SymbolTable &st)
Expand Down Expand Up @@ -64,6 +70,10 @@ void SymbolTable::print()

printf("\n--------------------SymbolTable---------------------------\n");
printf("no of params=%d\n",paramNum );
std::vector<Fields> pars=getParamList();
tr(pars,it)
printf("%s ",it->name.c_str() );
printf("\n");
std::vector<SFields> temp(table.begin(), table.end());
sort(temp.begin(), temp.end(),sortCompare);
int c=1;
Expand All @@ -79,7 +89,12 @@ void SymbolTable::print()
}
printf("-----------------------------------------------------------\n");


// tr(table, it)
// {
// printf("%u %s\n",&(*it),it->name.c_str() );
// }

// printf("-----------------------------------------------------------\n");
}

void SymbolTable::update(Fields* f,const Type& t)
Expand Down Expand Up @@ -121,7 +136,7 @@ Fields* SymbolTable::search(const string& s)
std::vector<Fields> SymbolTable::getParamList()
{
std::vector<SFields> temp(table.begin(), table.end());
sort(temp.begin(), temp.end(),sortCompare);
sort(temp.begin(), temp.end(),parCom);
if(paramNum>0)
return std::vector<Fields>(temp.begin(),temp.begin()+paramNum);
std::vector<Fields> v;
Expand Down
4 changes: 3 additions & 1 deletion ass 5/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ struct Fields{
bool isBoolExp; //if it is a boolean expression then t has true list and false lists
Fields* arrSize; //if type is array, store the size while reducing grammar
bool isArray;
bool isPointer;
Fields* arrayBase;
int parNum;

ListType tl,fl;//true list and false lists
Fields():type(),loc(NULL),size(4),offset(0),nestedTable(NULL),
isConst(false),isBoolExp(false),arrSize(NULL),
isArray(false)
isArray(false),isPointer(false),parNum(100000)

{}

Expand Down
9 changes: 6 additions & 3 deletions ass 5/ass5_12CS10037.l
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
void count();

extern SymbolTable* st;
int isComment=0;
%}


Expand Down Expand Up @@ -192,7 +193,7 @@ STRING_LITERAL \"{S_CHAR_SEQUENCE}?\"
BEGIN(INITIAL);
}

\/\/.* {}
\/\/.* {isComment=1;}



Expand All @@ -214,6 +215,8 @@ void count()
column += 8 - (column % 8);
else
column++;

ECHO;
if(!isComment)
;
else
isComment=0;
}
Loading