From d1735a883df93f35a26b7b08cf238ba60237503d Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 15 Aug 2012 16:58:32 +0530 Subject: [PATCH] Finished testing jump instructions --- genome.c | 21 ++++++++++----------- parser.y | 7 +++++-- test/t-001/answer | 1 - test/t-038/answer | 1 + test/t-038/program | 11 +++++++++++ test/t-039/answer | 11 +++++++++++ test/t-039/program | 20 ++++++++++++++++++++ test/t-040/answer | 1 + test/t-040/program | 13 +++++++++++++ 9 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 test/t-038/answer create mode 100644 test/t-038/program create mode 100644 test/t-039/answer create mode 100644 test/t-039/program create mode 100644 test/t-040/answer create mode 100644 test/t-040/program diff --git a/genome.c b/genome.c index 15f9e06..47d92de 100644 --- a/genome.c +++ b/genome.c @@ -171,24 +171,24 @@ void pop_numbers_from_stack(int f, int n) { int i; gmem tmp; for(i=0; idown; + 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; } diff --git a/parser.y b/parser.y index 9c2990e..39565ee 100644 --- a/parser.y +++ b/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); } } diff --git a/test/t-001/answer b/test/t-001/answer index a9e4e0a..451584e 100644 --- a/test/t-001/answer +++ b/test/t-001/answer @@ -1,3 +1,2 @@ -^ Error: Line 2:Unexpected EOF found diff --git a/test/t-038/answer b/test/t-038/answer new file mode 100644 index 0000000..104cbc4 --- /dev/null +++ b/test/t-038/answer @@ -0,0 +1 @@ +AA diff --git a/test/t-038/program b/test/t-038/program new file mode 100644 index 0000000..07212b3 --- /dev/null +++ b/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 diff --git a/test/t-039/answer b/test/t-039/answer new file mode 100644 index 0000000..59aa372 --- /dev/null +++ b/test/t-039/answer @@ -0,0 +1,11 @@ +81 +64 +49 +36 +25 +16 +9 +4 +1 +0 +A diff --git a/test/t-039/program b/test/t-039/program new file mode 100644 index 0000000..dbe19cc --- /dev/null +++ b/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 diff --git a/test/t-040/answer b/test/t-040/answer new file mode 100644 index 0000000..104cbc4 --- /dev/null +++ b/test/t-040/answer @@ -0,0 +1 @@ +AA diff --git a/test/t-040/program b/test/t-040/program new file mode 100644 index 0000000..a8ec80e --- /dev/null +++ b/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