Permalink
Browse files

Merge branch 'master' into exmpls

  • Loading branch information...
2 parents e629eda + a79089e commit 329596f039f55911eeacd2fa454bfed17d15d2fe @pksunkara committed Jul 28, 2011
Showing with 1,369 additions and 26 deletions.
  1. +2 −1 .gitignore
  2. +675 −0 COPYING
  3. +31 −10 Makefile
  4. +1 −0 README
  5. +1 −0 genome_lex.l → analyzer.l
  6. +8 −4 genome.c
  7. +29 −11 genome_parser.y → parser.y
  8. +11 −0 test/run_all.rb
  9. +8 −0 test/single.rb
  10. +3 −0 test/t-001/answer
  11. +1 −0 test/t-001/program
  12. +2 −0 test/t-002/answer
  13. +2 −0 test/t-002/program
  14. +2 −0 test/t-003/answer
  15. +2 −0 test/t-003/program
  16. 0 test/t-004/answer
  17. +2 −0 test/t-004/program
  18. 0 test/t-005/answer
  19. +3 −0 test/t-005/program
  20. +1 −0 test/t-006/answer
  21. +10 −0 test/t-006/program
  22. +2 −0 test/t-007/answer
  23. +10 −0 test/t-007/program
  24. +1 −0 test/t-008/answer
  25. +23 −0 test/t-008/program
  26. +3 −0 test/t-009/answer
  27. +8 −0 test/t-009/program
  28. +2 −0 test/t-010/answer
  29. +12 −0 test/t-010/program
  30. +2 −0 test/t-011/answer
  31. +13 −0 test/t-011/program
  32. +3 −0 test/t-012/answer
  33. +12 −0 test/t-012/program
  34. +2 −0 test/t-013/answer
  35. +12 −0 test/t-013/program
  36. +2 −0 test/t-014/answer
  37. +13 −0 test/t-014/program
  38. +2 −0 test/t-015/answer
  39. +12 −0 test/t-015/program
  40. +3 −0 test/t-016/answer
  41. +13 −0 test/t-016/program
  42. +3 −0 test/t-017/answer
  43. +13 −0 test/t-017/program
  44. +2 −0 test/t-018/answer
  45. +12 −0 test/t-018/program
  46. +3 −0 test/t-019/answer
  47. +13 −0 test/t-019/program
  48. +3 −0 test/t-020/answer
  49. +13 −0 test/t-020/program
  50. +3 −0 test/t-021/answer
  51. +13 −0 test/t-021/program
  52. +2 −0 test/t-022/answer
  53. +13 −0 test/t-022/program
  54. +3 −0 test/t-023/answer
  55. +18 −0 test/t-023/program
  56. +3 −0 test/t-024/answer
  57. +18 −0 test/t-024/program
  58. +2 −0 test/t-025/answer
  59. +14 −0 test/t-025/program
  60. +2 −0 test/t-026/answer
  61. +14 −0 test/t-026/program
  62. +2 −0 test/t-027/answer
  63. +14 −0 test/t-027/program
  64. +2 −0 test/t-028/answer
  65. +14 −0 test/t-028/program
  66. +4 −0 test/t-029/answer
  67. +16 −0 test/t-029/program
  68. +1 −0 test/t-030/answer
  69. +15 −0 test/t-030/program
  70. +2 −0 test/t-031/answer
  71. +17 −0 test/t-031/program
  72. +2 −0 test/t-032/answer
  73. +18 −0 test/t-032/program
  74. +2 −0 test/t-033/answer
  75. +14 −0 test/t-033/program
  76. +2 −0 test/t-034/answer
  77. +1 −0 test/t-034/input
  78. +15 −0 test/t-034/program
  79. +2 −0 test/t-035/answer
  80. +1 −0 test/t-035/input
  81. +12 −0 test/t-035/program
  82. +2 −0 test/t-036/answer
  83. +1 −0 test/t-036/input
  84. +12 −0 test/t-036/program
  85. +2 −0 test/t-037/answer
  86. +1 −0 test/t-037/input
  87. +14 −0 test/t-037/program
  88. +70 −0 test/test.rb
View
@@ -1,5 +1,6 @@
+genome
*.o
*.out
-genome
lex.yy.*
y.tab.*
+test/*/output
View
675 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,15 +1,36 @@
-all: exe
+prefix= /usr/bin
-exe: yacc lex genome.c
- gcc -g lex.yy.o y.tab.o genome.c -o genome
+RUBY= ruby
+TEST_SCRIPT= test/run_all.rb
-lex: genome_lex.l
- lex genome_lex.l
- gcc -g -c lex.yy.c
+INSTALL= install
+CC= gcc
+CFLAGS= -Wall -pedantic -g
+RM= rm -rf
-yacc: genome_parser.y
- yacc -d genome_parser.y
- gcc -g -c y.tab.c
+all: genome
+
+genome: lex.yy.o y.tab.o genome.c
+ $(CC) $(CFLAGS) $^ -o $@
+
+lex.yy.o: lex.yy.c y.tab.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
+y.tab.o: y.tab.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+lex.yy.c: analyzer.l
+ lex $^
+
+y.tab.c: parser.y
+ yacc -d $^
+
+install: genome
+ $(INSTALL) genome $(prefix)/genome
+
+check: $(TEST_SCRIPT) genome
+ $(RUBY) $<
clean:
- rm -f y.tab.* lex.yy.* genome *.out *.o
+ $(RM) *.o
+ $(RM) y.tab.* lex.yy.* genome
View
1 README
@@ -0,0 +1 @@
+Genome is an esoteric programming language imitating the genome sequence of a living organism
@@ -2,6 +2,7 @@
#include "y.tab.h"
extern void count(void);
+ extern void yyerror(char *);
%}
%%
View
@@ -9,6 +9,7 @@ extern char* yytext;
extern int yyparse(void);
extern int yywrap(void);
+extern void yyerror(char *);
typedef struct node {
int v;
@@ -80,7 +81,7 @@ void pop_number(void) {
void pop_numbers_from_stack(int f, int n) {
int i;
- gnode tmp, buf;
+ gnode tmp;
for(i=0;i<n;i++) {
if(tmp==NULL)
break;
@@ -275,23 +276,26 @@ void move(int f, int n) {
}
void read_n(int f, int n) {
- int i;
+ int i, in;
gnode tmp;
+ if(head==NULL)
+ push_number_into_stack(32);
tmp=(f==1)?head:tail;
for(i=1;i<n;i++) {
if(tmp==NULL)
break;
tmp=(f==1)?tmp->next:tmp->prev;
}
if(tmp!=NULL) {
- scanf("%d",&(tmp->v));
+ scanf("%c",&in);
+ tmp->v = in;
} else
yyerror("Number of elements in the stack is less than the required number");
return;
}
void read_top(void) {
- read_n(1,head->v);
+ read_n(1,head->v+1);
return;
}
@@ -16,6 +16,24 @@
void count(void);
void yyerror(char* msg);
+ extern void clear_stack(void);
+ extern void slide(int);
+ extern void push_number_into_stack(int);
+ extern void pop_number(void);
+ extern void pop_numbers_from_stack(int, int);
+ extern void dup_stack(void);
+ extern void dup_stack_n(int, int);
+ extern void copy_nth(int, int);
+ extern void arith(int);
+ extern void crement(int, int);
+ extern void print_whole_stack(int);
+ extern void print_stack_n(int, int, int);
+ extern void reverse_whole(void);
+ extern void reverse_stack_n(int, int);
+ extern void move_top(void);
+ extern void move(int, int);
+ extern void read_top(void);
+ extern void read_n(int, int);
%}
%token AAA // Duplicate the whole stack
@@ -48,14 +66,14 @@
%token TTC // Start block
%token TTG // Stop block
-%token TCA // Jump unconditionally to after {
-%token TCT // Jump on top item zero to after {
-%token TCC // Jump on nth item zero to after {
-%token TCG // Jump on bottom item zero after {
-%token TGA // Jump unconditionally to after }
-%token TGT // Jump on top item zero to after }
-%token TGC // Jump on nth item zero to after }
-%token TGG // Jump on bottom item zero to after }
+%token TCA // Jump unconditionally to start of the block
+%token TCT // Jump on top item zero to start of the block
+%token TCC // Jump on nth item zero to start of the block
+%token TCG // Jump on bottom item zero to start of the block
+%token TGA // Jump unconditionally to end of the bkock
+%token TGT // Jump on top item zero to end of the bkock
+%token TGC // Jump on nth item zero to end of the bkock
+%token TGG // Jump on bottom item zero to end of the bkock
%token CAA // Print the whole stack
%token CAT // Print top n items of stack
@@ -144,7 +162,7 @@ stmt: block
| CGT { move(1,1); }
| CGT number { move(1,$2); }
| CGC { move(0,1); }
- | CGC number { move(1,$2); }
+ | CGC number { move(0,$2); }
;
number: hex { $$=$1; }
@@ -176,11 +194,11 @@ hex: GAA { $$=0; }
;
start: TTC {
- //Start block
+ /* Start block */
};
stop: TTG {
- //End block
+ /* End block */
};
%%
View
@@ -0,0 +1,11 @@
+# Running all the tests using the test suite
+
+load 'test/test.rb'
+
+suite = TestSuite.new(File.expand_path('genome'), 'test/')
+
+Dir.glob('test/t-*').count.times do |i|
+ suite.run(i+1)
+end
+
+suite.statsput
View
@@ -0,0 +1,8 @@
+# Running a single test case using the test suite
+
+load 'test/test.rb'
+
+suite = TestSuite.new(File.expand_path('genome'), 'test/')
+
+suite.run(ARGV[0].to_i)
+suite.statsput
View
@@ -0,0 +1,3 @@
+^
+Error: Line 2:Unexpected EOF found
+
View
@@ -0,0 +1 @@
+{Empty program}
View
@@ -0,0 +1,2 @@
+Error: Line 0002, Column 0001-0003: syntax error
+
View
@@ -0,0 +1,2 @@
+{Program without block}
+CGG
View
@@ -0,0 +1,2 @@
+Error: Line 0002, Column 0004-0006: syntax error
+
View
@@ -0,0 +1,2 @@
+{Block without end and exit}
+TTCCGG
View
No changes.
View
@@ -0,0 +1,2 @@
+{Empty block and exit}
+TTCTTGCGG
View
No changes.
View
@@ -0,0 +1,3 @@
+{Whitespace check}
+TTC {space}TTG{newline}
+{tab} CGG
View
@@ -0,0 +1 @@
+ASCII
View
@@ -0,0 +1,10 @@
+{Pushing a number & printing in ascii}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ ATA GTA GCT
+ ATA GAA GCC
+ CTA {Printing a whole stack in ASCII}
+TTG CGG
View
@@ -0,0 +1,2 @@
+G
+g
View
@@ -0,0 +1,10 @@
+{Clearing stack}
+TTC
+ ATA GTA GTG
+ ATA GAA GCC
+ CTA
+ ACA
+ ATA GTC GTG
+ ATA GAA GCC
+ CTA
+TTG CGG
View
@@ -0,0 +1 @@
+0123456789101112131415
View
@@ -0,0 +1,23 @@
+{Pushing numbers & Printing in non-ascii}
+TTC
+ ATA GAA
+ ATA GAT
+ ATA GAC
+ ATA GAG
+ ATA GTA
+ ATA GTT
+ ATA GTC
+ ATA GTG
+ ATA GCA
+ ATA GCT
+ ATA GCC
+ ATA GCG
+ ATA GGA
+ ATA GGT
+ ATA GGC
+ ATA GGG
+ CAA {Printing whole stack in non-ascii}
+ ACA
+ ATA GAA GCC
+ CTA
+TTG CGG
View
@@ -0,0 +1,3 @@
+A
+A
+A
View
@@ -0,0 +1,8 @@
+{Duplicate whole stack}
+TTC
+ ATA GTA GAT
+ ATA GAA GCC
+ CTA
+ AAA
+ CTA
+TTG CGG
View
@@ -0,0 +1,2 @@
+AS
+AA
View
@@ -0,0 +1,12 @@
+{Pop number from stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GAA GCC
+ CTA
+ ATC
+ ATC
+ ATA GTA GAT
+ ATA GAA GCC
+ CTA
+TTG CGG
View
@@ -0,0 +1,2 @@
+ASCI
+ASCII
View
@@ -0,0 +1,13 @@
+{Duplicate top item of stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ ATA GAA GCC
+ CTA
+ ATC
+ AAC
+ ATA GAA GCC
+ CTA
+TTG CGG
View
@@ -0,0 +1,3 @@
+ASCII
+ASCII
+CII
View
@@ -0,0 +1,12 @@
+{Duplicate top n items of stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ AAC
+ ATA GAA GCC
+ CTA
+ AAT GTA
+ CTA
+TTG CGG
View
@@ -0,0 +1,2 @@
+ASCII
+ASCASCII
View
@@ -0,0 +1,12 @@
+{Duplicate bottom n items of stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ AAC
+ ATA GAA GCC
+ CTA
+ AAG GAG
+ CTA
+TTG CGG
View
@@ -0,0 +1,2 @@
+ASCII
+AS
View
@@ -0,0 +1,13 @@
+{Pop top n items from stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ AAC
+ ATA GAA GCC
+ CTA
+ ATT GTA
+ ATA GAA GCC
+ CTA
+TTG CGG
View
@@ -0,0 +1,2 @@
+ASCII
+CII
View
@@ -0,0 +1,12 @@
+{Pop bottom n items from stack}
+TTC
+ ATA GTA GAT
+ ATA GTT GAG
+ ATA GTA GAG
+ ATA GTA GCT
+ AAC
+ ATA GAA GCC
+ CTA
+ ATG GAC
+ CTA
+TTG CGG
View
@@ -0,0 +1,3 @@
+ASCII
+ASCII
+S
Oops, something went wrong.

0 comments on commit 329596f

Please sign in to comment.