Skip to content

Commit eb5d712

Browse files
committed
Symbol table update in one file for assignment purpose
1 parent 2be5e69 commit eb5d712

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CompilerDesignInC/CompilerDesignInC.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
</Link>
145145
</ItemDefinitionGroup>
146146
<ItemGroup>
147+
<ClCompile Include="..\assignment\symbol_table.c" />
147148
<ClCompile Include="Implementations\Dfa\RecognizeUsingDfa.c" />
148149
<ClCompile Include="Implementations\Symbol Table\SymbolTable.c" />
149150
<ClCompile Include="Implementations\Utility\ArrayLibrary\ArrayOfIntegers.c" />

CompilerDesignInC/CompilerDesignInC.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<ClCompile Include="Implementations\Dfa\RecognizeUsingDfa.c">
2828
<Filter>Resource Files</Filter>
2929
</ClCompile>
30+
<ClCompile Include="..\assignment\symbol_table.c">
31+
<Filter>Resource Files</Filter>
32+
</ClCompile>
3033
</ItemGroup>
3134
<ItemGroup>
3235
<ClInclude Include="Header Files\Symbol Table\SymbolTable.h">

assignment/symbol_table.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <string.h>
22
#include <stdlib.h>
33
#include <stdio.h>
4-
#include<ctype.h>
4+
#include <ctype.h>
55

66
#define STRING_LENGTH(string, length) \
77
{\
@@ -63,10 +63,25 @@ int recognize_other_types(const char ch)
6363

6464
int recognize_keywords(char *string)
6565
{
66-
int length = 0, i = 0, state = 0, k = 0;
66+
int length = 0, state = 0, k = 0;
6767
STRING_LENGTH(string, length);
68+
char* key[] = {
69+
"void", "int", "char", "float", "double", "long", "if", "else", "switch", "case", "default", "break", "continue", "for",
70+
"while", "do", "goto", "return", "short", "const", "struct", "typedef", "unsigned", "static", "enum", "sizeof"
71+
};
6872

69-
while (*(string + i))
73+
int size=sizeof key/sizeof key[0];
74+
75+
for (int i = 0; i < size; i++)
76+
{
77+
if (_strcmpi(string,key[i])==0)
78+
{
79+
return FINAL;
80+
}
81+
}
82+
return TRAP;
83+
84+
/*while (*(string + i))
7085
{
7186
switch(state)
7287
{
@@ -244,9 +259,8 @@ int recognize_keywords(char *string)
244259
}
245260
246261
i++;
247-
}
262+
}*/
248263

249-
return state == FINAL ? 1 : 0;
250264
}
251265

252266
int recognize_identifier(char *string)

0 commit comments

Comments
 (0)