-
Notifications
You must be signed in to change notification settings - Fork 5
/
ponc.in.y
81 lines (65 loc) · 1.31 KB
/
ponc.in.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%{
/* Grammar for the three *.in data files */
#include <stdio.h>
#include <locale.h>
#include "gettext.h"
int lineno = 1;
int errors = 0;
int rules = 0;
%}
%token POSTAG NEGTAG POSTAGEND NEGTAGEND WORD MESSAGE MESSAGEARG MACRO MESSAGEPLUS COMMENT BLANK
%%
lines: line
| lines line
;
line: COMMENT
| BLANK
| rule
;
rule: phrase ':' _TAIL_MACRO_ {rules++;}
;
phrase: phrase ' ' oneword
| oneword
;
result: _RESULT_MACRO_ ;
oneword: tagged_word
| untagged_word
;
tagged_word: POSTAG untagged_word POSTAGEND
| NEGTAG untagged_word NEGTAGEND
;
untagged_word: WORD
| MACRO
;
%%
extern FILE *yyin;
main()
{
setlocale (LC_MESSAGES, ""); /* read from environment */
setlocale (LC_CTYPE, ""); /* needed so accents appear correctly! */
bindtextdomain (PACKAGE_NAME, LOCALEDIR);
textdomain (PACKAGE_NAME);
do
{
yyparse();
}
while (!feof(yyin));
if (errors) {
printf(ngettext ("There was %d error.\n",
"There were %d errors.\n",
errors), errors);
}
else {
/* used to print number of lines parsed too: lineno-1 */
printf(ngettext ("Successfully parsed %d rule.\n",
"Successfully parsed %d rules.\n",
rules), rules);
}
return (errors);
}
yyerror(s)
char* s;
{
fprintf(stderr, gettext ("Line %d: %s\n"), lineno, s);
errors++;
}