I HAVE SLAIN THE BISON WITH A THREE KILOBYTE SIZED DUCK
This commit is contained in:
parent
446d3c909c
commit
568e60fe39
2
Makefile
2
Makefile
@ -11,4 +11,4 @@ clean:
|
||||
-rm object/*
|
||||
|
||||
test:
|
||||
-./farmsay < <(printf "QUACK bread! I'me! Megmutatom ne'ktek az utolso' embert. Mi az, hogy szerelem? Mi az, hogy teremte's? Mi az, hogy va'gy? Mi az, hogy csillag? - i'gy ke'rdezo''sko:dik az utolso' ember e's vaksin pislog.")
|
||||
valgrind ./farmsay < <(printf "QUACK bread! I'me! Megmutatom ne'ktek az utolso' embert. Mi az, hogy szerelem? Mi az, hogy teremte's? Mi az, hogy va'gy? Mi az, hogy csillag? - i'gy ke'rdezo''sko:dik az utolso' ember e's vaksin pislog.")
|
||||
|
28
farmsay.y
28
farmsay.y
@ -1,27 +1,25 @@
|
||||
%code{
|
||||
extern void yyerror(...);
|
||||
}
|
||||
%{
|
||||
#include "farmsay.yy.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
extern void bison_say(const char * const s);
|
||||
extern void snake_say(const char * const s);
|
||||
extern void sheep_say(const char * const s);
|
||||
extern void duck_say(const char * const s);
|
||||
|
||||
void yyerror(...) { puts("\033[31m\033[7m!!!\033[0m"); }
|
||||
|
||||
using namespace std;
|
||||
%}
|
||||
|
||||
%union {
|
||||
char * strval;
|
||||
}
|
||||
|
||||
%token <strval> DOT BANG QUESTIONMARK QUACK
|
||||
%token DOT BANG QUESTIONMARK QUACK
|
||||
%token <strval> STRING
|
||||
%type <strval> sentence snake sheep bison
|
||||
|
||||
%type <strval> sentence
|
||||
%%
|
||||
|
||||
speech: %empty
|
||||
@ -31,16 +29,14 @@ speech: %empty
|
||||
| speech duck
|
||||
;
|
||||
|
||||
snake: sentence DOT { snake_say($$); };
|
||||
bison: sentence BANG { bison_say($$); };
|
||||
sheep: sentence QUESTIONMARK { sheep_say($$); };
|
||||
snake: sentence DOT { snake_say((string() + $1 + '.').c_str()); free($1); };
|
||||
bison: sentence BANG { bison_say((string() + $1 + '!').c_str()); free($1); };
|
||||
sheep: sentence QUESTIONMARK { sheep_say((string() + $1 + '?').c_str()); free($1); };
|
||||
|
||||
duck: QUACK sentence BANG { printf("'%s'\n", $2); };
|
||||
duck: QUACK sentence BANG { duck_say($2); free($2); };
|
||||
|
||||
sentence: STRING
|
||||
| sentence STRING
|
||||
sentence: STRING { $$ = strdup($1); free($1); }
|
||||
| sentence STRING { $$ = strdup((string() + $1 + $2).c_str()); free($1); free($2); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
void yyerror(...) { puts("\033[31m\033[7m!!!\033[0m"); }
|
||||
|
11
main.cpp
11
main.cpp
@ -67,6 +67,17 @@ void sheep_say(const char * const s) {
|
||||
fputs("\033[0m", stdout);
|
||||
}
|
||||
|
||||
void duck_say(const char * const s) {
|
||||
const char * const DUCK =
|
||||
" \\_0<\n"
|
||||
" V_ \n"
|
||||
;
|
||||
fputs("\033[34m", stdout);
|
||||
frame('X', 6, s);
|
||||
puts(DUCK);
|
||||
fputs("\033[0m", stdout);
|
||||
}
|
||||
|
||||
|
||||
signed main(int argc, char * * argv) {
|
||||
yyparse();
|
||||
|
Loading…
x
Reference in New Issue
Block a user