summaryrefslogtreecommitdiff
path: root/tests/test-bison-yylval/parser.y
diff options
context:
space:
mode:
authorWill Estes <wlestes@users.sourceforge.net>2001-05-18 17:22:22 +0000
committerWill Estes <wlestes@users.sourceforge.net>2001-05-18 17:22:22 +0000
commitdc3a30a46cb3a42fc0a858dfa243a96112c8e551 (patch)
tree3bfc63b1584ca1f53f299b84d39b3ebe8ddc2811 /tests/test-bison-yylval/parser.y
parent756defa0610404257cb8a1c8ef513365a6674789 (diff)
add john millaway's test directory
Diffstat (limited to 'tests/test-bison-yylval/parser.y')
-rw-r--r--tests/test-bison-yylval/parser.y75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test-bison-yylval/parser.y b/tests/test-bison-yylval/parser.y
new file mode 100644
index 0000000..8dfebd8
--- /dev/null
+++ b/tests/test-bison-yylval/parser.y
@@ -0,0 +1,75 @@
+/* Accepts html-like input.
+ How to compile:
+ bison --defines --output-file="parser.c" --name-prefix="test" parser.y
+ */
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+
+#define YYERROR_VERBOSE 1
+#define YYPARSE_PARAM scanner
+#define YYLEX_PARAM scanner
+
+
+int yyerror(char* msg);
+extern int testlex_init(void**);
+extern int testlex_destroy(void**);
+extern int testset_in(FILE*,void*);
+extern int testlex();
+
+/* A dummy function. A check against seg-faults in yylval->str. */
+int process_text(char* s) {
+ int total =0;
+ while(*s) {
+ total += (int) *s;
+ ++s;
+ }
+ return total;
+}
+
+
+%}
+
+%pure_parser
+
+%union {
+ long unused;
+ char * str;
+}
+%token <str> TAGNAME TEXT
+%token LT
+%token GT
+%token LTSLASH "</"
+
+%%
+
+html:
+ TEXT { process_text($1); free($1);}
+ | starttag html endtag
+ | html TEXT { process_text($2); free($2);}
+ | html starttag html endtag
+ ;
+
+starttag: LT TAGNAME GT { process_text($2); free($2);} ;
+endtag: LTSLASH TAGNAME GT { process_text($2);free($2);} ;
+%%
+
+int yyerror(char* msg) {
+ fprintf(stderr,"%s\n",msg);
+ return 0;
+}
+
+
+int main ( int argc, char** argv )
+{
+ void* scanner;
+ /*yydebug =1;*/
+ testlex_init ( &scanner );
+ testset_in(stdin,scanner);
+ testparse ( scanner );
+ testlex_destroy ( scanner );
+ return 0;
+}
+