Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished testing jump instructions

  • Loading branch information...
commit d1735a883df93f35a26b7b08cf238ba60237503d 1 parent 684d8b3
@pksunkara authored
View
21 genome.c
@@ -171,24 +171,24 @@ void pop_numbers_from_stack(int f, int n) {
int i;
gmem tmp;
for(i=0; i<n; i++) {
- if(tmp == NULL)
- break;
if(f == 1) {
tmp = top;
top = tmp->down;
+ free(tmp);
if(top != NULL)
top->up = NULL;
- free(tmp);
+ else
+ yyerror("Number of elements in the stack is less than required number");
} else {
tmp = bottom;
bottom = tmp->up;
+ free(tmp);
if(bottom != NULL)
bottom->down = NULL;
- free(tmp);
+ else
+ yyerror("Number of elements in the stack is less than required number");
}
}
- if(tmp == NULL)
- yyerror("Number of elements in the stack is less than required number");
return;
}
@@ -340,15 +340,16 @@ gins jmp_start_nth(int f, int n, gins buf) {
gins jmp_end(void) {
int i = 1;
gins tmp;
-
if (blks == NULL || blks->link == NULL) {
yyerror("Block arrangement fault");
} else {
tmp = blks->link;
}
-
while (1) {
- if (tmp->t == 30) {
+ tmp = tmp->after;
+ if (tmp == NULL) {
+ yyerror("No instruction after the end of block");
+ } else if (tmp->t == 30) {
i = i + 1;
} else if (tmp->t == 31) {
i = i - 1;
@@ -356,9 +357,7 @@ gins jmp_end(void) {
break;
}
}
- tmp = tmp->after;
}
-
return tmp;
}
View
7 parser.y
@@ -211,10 +211,13 @@ void count(void) {
}
void yyerror(char* msg) {
- if(strlen(yytext)) {
+ if (strlen(yytext)) {
printf("Error: Line %4.4d, Column %4.4d-%4.4d: %s\n",lineNum,(colNum-yyleng>0?colNum-yyleng:0),colNum-1,msg);
} else {
- printf("%*s\n",0,"^");
+ if (strlen(msg) && msg != "syntax error") {
+ printf("%s\n", msg);
+ exit(1);
+ }
printf("Error: Line %d:Unexpected EOF found\n",lineNum);
}
}
View
1  test/t-001/answer
@@ -1,3 +1,2 @@
-^
Error: Line 2:Unexpected EOF found
View
1  test/t-038/answer
@@ -0,0 +1 @@
+AA
View
11 test/t-038/program
@@ -0,0 +1,11 @@
+{Jump unconditionally to end of the block}
+TTC
+ ATA GTA GAT
+ TTC
+ ATA GTA GAT
+ TGA
+ ATA GTA GAG
+ TTG
+ ATA GAA GCC
+ CTA
+TTG CGG
View
11 test/t-039/answer
@@ -0,0 +1,11 @@
+81
+64
+49
+36
+25
+16
+9
+4
+1
+0
+A
View
20 test/t-039/program
@@ -0,0 +1,20 @@
+{Jump unconditionally to start of the block}
+{Jump on zero to end of the block}
+TTC
+ ATA GCC
+ ATA GCC
+ TTC
+ TTT
+ AAC
+ TAC
+ CAC
+ ATT GAC
+ CTG GAT
+ TGT
+ TCA
+ TTG
+ ACA
+ ATA GTA GAT
+ ATA GCC
+ CTA
+TTG CGG
View
1  test/t-040/answer
@@ -0,0 +1 @@
+AA
View
13 test/t-040/program
@@ -0,0 +1,13 @@
+{Testing jumps over nested blocks}
+TTC
+ ATA GTA GAT
+ TTC
+ ATA GTA GAT
+ TGA
+ TTC
+ ATA GTA GAT
+ TTG
+ TTG
+ ATA GCC
+ CTA
+TTG CGG
Please sign in to comment.
Something went wrong with that request. Please try again.