Skip to content

Commit

Permalink
Finished testing jump instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Aug 15, 2012
1 parent 684d8b3 commit d1735a8
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 14 deletions.
21 changes: 10 additions & 11 deletions genome.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -340,25 +340,24 @@ 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;
if (i == 0) {
break;
}
}
tmp = tmp->after;
}

return tmp;
}

Expand Down
7 changes: 5 additions & 2 deletions parser.y
Expand Up @@ -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);
}
}
1 change: 0 additions & 1 deletion test/t-001/answer
@@ -1,3 +1,2 @@
^
Error: Line 2:Unexpected EOF found

1 change: 1 addition & 0 deletions test/t-038/answer
@@ -0,0 +1 @@
AA
11 changes: 11 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions test/t-039/answer
@@ -0,0 +1,11 @@
81
64
49
36
25
16
9
4
1
0
A
20 changes: 20 additions & 0 deletions 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
1 change: 1 addition & 0 deletions test/t-040/answer
@@ -0,0 +1 @@
AA
13 changes: 13 additions & 0 deletions 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

0 comments on commit d1735a8

Please sign in to comment.