Make syntax error call yyerror() rather than raising a Python exception
[piyacc.git] / lex-yacc-examples / example6.y
1 %{
2 #include <stdio.h>
3 #include <string.h>
4
5 #define YYSTYPE char *
6
7 int yydebug=0;
8
9 void yyerror(const char *str)
10 {
11         fprintf(stderr,"error: %s\n",str);
12 }
13
14 int yywrap()
15 {
16         return 1;
17 }
18
19 main()
20 {
21         yyparse();
22 }
23
24 %}
25
26 %token WORD FILENAME QUOTE OBRACE EBRACE SEMICOLON ZONETOK FILETOK
27
28 %%
29
30 commands:
31         |        
32         commands command SEMICOLON
33         ;
34
35
36 command:
37         zone_set 
38         ;
39
40 zone_set:
41         ZONETOK quotedname zonecontent
42         {
43                 printf("Complete zone for '%s' found\n",$2);
44         }
45         ;
46
47 zonecontent:
48         OBRACE zonestatements EBRACE 
49
50 quotedname:
51         QUOTE FILENAME QUOTE
52         {
53                 $$=$2;
54         }
55         ;
56
57 zonestatements:
58         |
59         zonestatements zonestatement SEMICOLON
60         ;
61
62 zonestatement:
63         statements
64         |
65         FILETOK quotedname 
66         {
67                 printf("A zonefile name '%s' was encountered\n", $2);
68         }
69         ;
70
71 block: 
72         OBRACE zonestatements EBRACE SEMICOLON
73         ;
74
75 statements:
76         | statements statement
77         ;
78
79 statement: WORD | block | quotedname