1 /* C code supplied at the beginning of the file. */
8 extern
int yylexlinenum
; /* these are in YYlex */
9 extern
char *yytext
; /* current token */
14 /* Keywords and reserved words begin here. */
16 %
union{ /* this is the data union */
17 char name
[128]; /* names */
20 /*-------------------- the reserved words -----------------------------*/
36 %type
<name
> declarative
37 %type
<name
> verb_phrase
38 %type
<name
> noun_phrase
39 %type
<name
> position_phrase
42 %type
<name
> POSITIONAL VERB ADVERB PROPER_NOUN
43 %type
<name
> NOUN DECLARATIVE CONDITIONAL
47 sentence_list
: sentence
48 | sentence_list NEWLINE sentence
52 sentence
: verb_phrase noun_phrase position_phrase adverb period
54 printf
("I understand that sentence.\n");
55 printf
("VP = %s \n",$1);
56 printf
("NP = %s \n",$2);
57 printf
("PP = %s \n",$3);
58 printf
("AD = %s \n",$4);
60 |
{ yyerror("That's a strange sentence !!"); }
63 position_phrase
: POSITIONAL declarative PROPER_NOUN
65 sprintf
($$
,"%s %s %s",$1,$2,$3);
67 |
/* empty */ { strcpy
($$
,""); }
71 verb_phrase
: VERB
{ strcpy
($$
,$1); strcat
($$
," "); }
74 sprintf
($$
,"%s %s",$1,$2);
78 adverb
: ADVERB
{ strcpy
($$
,$1); }
79 |
/* empty */ { strcpy
($$
,""); }
82 noun_phrase
: DECLARATIVE NOUN
84 sprintf
($$
,"%s %s",$1,$2);
86 | CONDITIONAL declarative NOUN
88 sprintf
($$
,"%s %s %s",$1,$2,$3);
90 | NOUN
{ strcpy
($$
,$1); strcat
($$
," "); }
93 declarative
: DECLARATIVE
{ strcpy
($$
,$1); }
94 |
/* empty */ { strcpy
($$
,""); }
104 /* Supplied main() and yyerror() functions. */
106 int main
(int argc
, char *argv
[])
108 yyparse(); /* parse the file */
112 int yyerror(char *message
)
116 fprintf
(yyout
,"\nError at line %5d. (%s) \n",
117 yylexlinenum
,message
);