Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Found a bug when a comment has this form: '*STR: MORE STR', it was pa…

…rsed as a label definition and not a comment; Fixed that.
  • Loading branch information...
commit fd88ea3dcba106c9196af5cec007608cc0c51b03 1 parent ce49f1f
@grnt426 authored
Showing with 20 additions and 19 deletions.
  1. +12 −10 idents.c
  2. +1 −1  idents.h
  3. +6 −7 translator.c
  4. +1 −1  translator.h
View
22 idents.c
@@ -20,14 +20,10 @@ short check_label_def(char *tok, struct program *prog){
return 0;
}
-void process_comment(){
- #ifdef DEBUG
- // fprintf(stderr, "Ignoring comment on line %d\n",
- // prog->line_count);
- #endif
-
+void process_comment(struct program *prog){
+
// Just eat the rest of the string
- blind_consume();
+ blind_consume(prog);
}
void process_label_def(char *tok, struct program *prog){
@@ -111,13 +107,19 @@ int process_literal(char *tok, int max_val){
return val > max_val ? -1 : val;
}
-void blind_consume(){
- while(strtok(0, STR_TOK_SEP));
+void blind_consume(struct program *prog){
+ char * buf;
+ while(1){
+ buf = strtok(0, ", \t\n");
+ if(!buf)
+ break;
+ }
}
short check_comment(char * tok, struct program * prog){
- if(tok[0] == COMMENT_SYM)
+ if(tok[0] == COMMENT_SYM){
return 1;
+ }
return 0;
}
View
2  idents.h
@@ -28,7 +28,7 @@ int process_literal(char *tok, int max_val);
// Comment Processing Functions
short check_comment(char * tok, struct program *prog);
-void process_comment();
+void process_comment(struct program *prog);
// Error Reporting
void print_compiler_error(struct program *prog, const char *color);
View
13 translator.c
@@ -220,18 +220,17 @@ void process_input_program(struct program *program){
*/
void process_token(char *tok, struct program *program){
- // check if we have a label
- if(check_label_def(tok, program)){
- process_label_def(tok, program);
+ // check for comments
+ if(check_comment(tok, program)){
+ process_comment(program);
return;
}
- // check for comments
- else if(check_comment(tok, program)){
- process_comment(tok, program);
+ // check if we have a label
+ else if(check_label_def(tok, program)){
+ process_label_def(tok, program);
return;
}
-
// process constant definitions
else if(check_const_def(tok, program)){
process_const_def(tok, program);
View
2  translator.h
@@ -2,7 +2,7 @@
#define translator_h_
// debug print control
-#define DEBUG // general purpose debug messages
+#define DEBUG_ // general purpose debug messages
// Machine Constraints
#define MAX_REGS 2
Please sign in to comment.
Something went wrong with that request. Please try again.