File: test.y

package info (click to toggle)
btyacc 3.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 456 kB
  • ctags: 550
  • sloc: ansic: 6,562; yacc: 1,902; makefile: 103; sh: 13
file content (32 lines) | stat: -rw-r--r-- 504 bytes parent folder | download | duplicates (20)
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
%{
/* first section */
%}
%%
%{
/* second section */
%}
S : /* empty */	{ printf("S -> epsilon\n"); }
  | '(' S ')' S { printf("S -> ( S ) S\n"); }
%ifdef ABC
    /* see how preprocessor can be used */
  | '*'         { printf("S -> *\n"); }
%endif
  ;
%%
#include <stdio.h>

main() {
  printf("yyparse() = %d\n",yyparse());
}

yylex() {
  int ch;

	do { ch = getchar(); } while (ch == ' ' || ch == '\n' || ch == '\t');
	if (ch == EOF) return 0;
	return ch;
}

yyerror(s) char*s; {
  printf("%s\n",s);
}