13 char InBuff
[MAXINBUFF
];
15 char FilenameBuff
[80];
17 char *current_command
= InBuff
;
18 int current_command_type
;
25 while(InBuff
[i
] != '\0')
27 printf("%c", InBuff
[i
++]);
34 current_command
= InBuff
;
41 while(current_command
!= k
)
43 if(*k
== '\n') { ++i
; }
49 int search_command(const char *current_command
, const char term
)
53 while(*(current_command
+i
) != '\r' && *(current_command
+i
) != '\n' && *(current_command
+i
) != '\0')
55 if(*(current_command
+i
) == term
) { ++found
; }
61 void print_current_command()
64 while(*(current_command
+i
) != '\r' && *(current_command
+i
) != '\n' && *(current_command
+i
) != '\0' && i
<= 20)
66 printf("%c", *(current_command
+i
));
69 if(settings
.code
!= 0 || settings
.comments
!= 0) { printf("\n"); }
72 void init_parser(char *FilenameBuff
)
74 if((pInfile
= fopen(FilenameBuff
, "rb")) == NULL
)
75 exit_error(3, "Cannot Open Input (Source) File");
78 while(!feof(pInfile
) && k
< MAXINBUFF
)
80 InBuff
[++k
] = fgetc(pInfile
);
86 /* printf("Input Buffer Loaded\n"); */
88 exit_error(4, "Input Too Large for Input Buffer");
92 int has_more_commands()
95 while(isprint(*(current_command
+i
))) { ++i
; }
96 if(*(current_command
+i
) == '\0') { return 0; }
97 if(isspace(*(current_command
+i
)))
101 } while (isspace(*(current_command
+i
)));
102 if(*(current_command
+i
) == '\0') { return 0; }
112 } while(*current_command
!= '\n' && *current_command
!= '\0');
113 while(isspace(*current_command
)) { ++current_command
; }
114 if(*(current_command
+1) == '/')
123 if(*current_command
== '@')
125 current_command_type
= A_COMMAND
;
127 } else if(search_command(current_command
, '(') > 0 || search_command(current_command
, ')') > 0) {
128 current_command_type
= L_COMMAND
;
130 } else if(!isdigit(*current_command
)){
131 current_command_type
= C_COMMAND
;
133 } else if(isdigit(*current_command
)){
134 current_command_type
= C_COMMAND
;
137 int i
= find_line_num();
138 line_notification(i
);
139 exit_error(7, "Incorrect Command Type");
146 int convert
= 0, i
= 0;
150 /* determine if this is a symbol or an address */
151 convert
= isdigit(*(current_command
+1));
153 if(current_command_type
== A_COMMAND
)
155 if(convert
== 0) /* text (symbolic) entries */
158 while(!isspace(*(current_command
+i
+1)))
160 sym
[i
] = *(current_command
+i
+1);
164 address
= get_address(sym
);
167 address
= get_ram_address();
172 } else { /* numeric entries */
174 while(!isspace(*(current_command
+i
+1)))
176 sym
[i
] = *(current_command
+i
+1);
180 /* value looks like a string of chars must be converted */
181 address
= (int)strtol(sym
, (char **) NULL
, 10);
186 /* TODO: THIS MUST BE CHANGED TO LOOK IN HASH FOR THIS SYMBOL
187 BY NOW IT HAS ALREADY BEEN ADDED TO THE HASH TABLE
189 if(current_command_type
== L_COMMAND
)
193 /* lookup this symbol in hash table and get it's address */
195 while(!isspace(*(current_command
+i
+1)) && *(current_command
+i
+1) != ')')
197 sym
[i
] = *(current_command
+i
+1);
201 return get_address(sym
);
203 /* convert numbers into integer and return current symbol as integer */
205 while(!isspace(*(current_command
+i
+1)) && *(current_command
+i
+1) != ')')
207 sym
[i
] = *(current_command
+i
+1);
211 return (int)strtol(sym
, (char **) NULL
, 10);
214 exit_error(8, "Symbol Function Called on Incorrect Command Type.");
220 char sym
[MAXCOMMAND
];
222 while(!isspace(*(current_command
+i
+1)) && *(current_command
+i
+1) != ')')
224 sym
[i
] = *(current_command
+i
+1);
228 add_entry(sym
, get_rom_address());
232 int dest(char dest
[])
237 if(current_command_type
== C_COMMAND
)
239 while(*(current_command
+i
) != '\n' && *(current_command
+i
) != '\0')
241 if(*(current_command
+i
) == '=') { ++dest_exist
; }
244 if(dest_exist
== 0) /* no dest in command */
250 while(*(current_command
+i
) != '=')
252 dest
[i
] = *(current_command
+i
);
259 line_notification(i
);
260 exit_error(8, "Symbol Function Called on Incorrect Command Type.");
264 int comp(char comp
[])
269 char *delimiter
= NULL
;
271 while(*(current_command
+i
) != '\n' && *(current_command
+i
) != '\0')
273 if(*(current_command
+i
) == '=') { ++eq_exist
; delimiter
= current_command
+i
; }
274 if(*(current_command
+i
) == ';') { ++semi_exist
; }
278 if(!semi_exist
&& !eq_exist
)
280 line_notification(i
);
281 exit_error(9, "Command Does Not Contain Proper Delimiter.");
285 if(current_command_type
== C_COMMAND
)
287 if(eq_exist
) /* found '=' in command -- skip to char after equal and copy till new line */
291 while(*(delimiter
+i
) != ';' && !isspace(*(delimiter
+i
)) && *(delimiter
+i
) != '\0')
293 comp
[i
] = *(delimiter
+i
);
296 } else { /* no '=' in command -- copy until semicolon found */
298 while(*(current_command
+i
) != ';')
300 comp
[i
] = *(current_command
+i
);
308 line_notification(i
);
309 exit_error(8, "Symbol Function Called on Incorrect Command Type.");
313 int jump(char jump
[])
316 char *delimiter
= NULL
;
317 int valid_command
= 0;
318 if(current_command_type
== C_COMMAND
)
320 /* Test for semicolon before newline char */
322 while(*(current_command
+i
) != '\n' && *(current_command
+i
) != '\0')
324 if(*(current_command
+i
) == ';') { ++valid_command
; }
327 if(valid_command
== 0)
331 } /* no jump in command */
332 delimiter
= strchr(current_command
, ';');
335 while(!isspace(*(delimiter
+i
)) && *(delimiter
+i
) != '\0')
337 jump
[i
] = *(delimiter
+i
);
344 line_notification(i
);
345 exit_error(8, "Symbol Function Called on Incorrect Command Type.");