[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yacc available



i wrote:
> in case anyone finds it useful, here are some ed diffs
> from the distributed yacc to make it reentrant.

oops, i'd forgotten that mail eats '.'
here are some cdiffs instead. (what is the preferred format
for diffs these days anyway ?)

  rog.

*** calc.y.orig	Sun Feb 16 19:43:57 1997
--- calc.y	Sun Feb 16 19:34:37 1997
***************
*** 17,25 ****
  # the user must define
  #	type YYSTYPE
! #	yylex: fn(): int
! #	yyerror: fn(err: string);
  #
  # yacc will produce
! #	yyparse: fn();
  #
  # any names beginning with yy or YY are reserved for yacc's use.
--- 17,27 ----
  # the user must define
  #	type YYSTYPE
! #	type YYLEX containing:
! #		lex: fn(l: self ref YYLEX): int
! #		lval of type YYSTYPE
! #		error: fn(l: ref YYLEX, err: string);
  #
  # yacc will produce
! #	yyparse: fn(l: ref YYLEX);
  #
  # any names beginning with yy or YY are reserved for yacc's use.
***************
*** 29,33 ****

  	YYSTYPE: adt { v: real; };
! 	yylval:	YYSTYPE;
  }

--- 31,40 ----

  	YYSTYPE: adt { v: real; };
! 	YYLEX: adt {
! 		in: ref Iobuf;
! 		lval:	YYSTYPE;
! 		lex:	fn(l: self ref YYLEX): int;
! 		error:	fn(l: self ref YYLEX, err: string);
! 	};
  }

***************
*** 69,73 ****
  %%

- in: ref Iobuf;
  stderr: ref Sys->FD;

--- 76,79 ----
***************
*** 76,85 ****
  	sys = load Sys Sys->PATH;
  	bufio = load Bufio Bufio->PATH;
! 	in = bufio->fopen(sys->fildes(0), Bufio->OREAD);
  	stderr = sys->fildes(2);
! 	yyparse();
  }

! yyerror(err: string)
  {
  	sys->fprint(stderr, "%s\n", err);
--- 82,92 ----
  	sys = load Sys Sys->PATH;
  	bufio = load Bufio Bufio->PATH;
! 	l := ref YYLEX;
! 	l.in = bufio->fopen(sys->fildes(0), Bufio->OREAD);
  	stderr = sys->fildes(2);
! 	yyparse(l);
  }

! YYLEX.error(l: self ref YYLEX, err: string)
  {
  	sys->fprint(stderr, "%s\n", err);
***************
*** 86,93 ****
  }

! yylex(): int
  {
  	for(;;){
! 		c := in.getc();
  		case c{
  		' ' or '\t' =>
--- 93,100 ----
  }

! YYLEX.lex(l: self ref YYLEX): int
  {
  	for(;;){
! 		c := l.in.getc();
  		case c{
  		' ' or '\t' =>
***************
*** 99,106 ****
  			i := 0;
  			s[i++] = c;
! 			while((c = in.getc()) >= '0' && c <= '9' || c == '.' || c == 'e' || c
== 'E')
  				s[i++] = c;
! 			in.ungetc();
! 			yylval.v = real s;
  			return REAL;
  		* =>
--- 106,113 ----
  			i := 0;
  			s[i++] = c;
! 			while((c = l.in.getc()) >= '0' && c <= '9' || c == '.' || c == 'e' ||
c == 'E')
  				s[i++] = c;
! 			l.in.ungetc();
! 			l.lval.v = real s;
  			return REAL;
  		* =>
*** yacc.b.orig	Sun Feb 16 19:43:58 1997
--- yacc.b	Sun Feb 16 19:48:08 1997
***************
*** 636,640 ****
  	ftable.puts("YYERRCODE: con 2;\n");
  	ftable.puts("YYMAXDEPTH: con 150;\n");
- 	ftable.puts("yyval: YYSTYPE;\n");

  	#
--- 636,639 ----
***************
*** 765,769 ****
  		peekline = 0;
  		c = finput.getc();
! 		while(c == ' ' || c == '\n' || c == '\t' || c == '\v') {
  			if(c == '\n')
  				lineno++;
--- 764,768 ----
  		peekline = 0;
  		c = finput.getc();
! 		while(c == ' ' || c == '\n' || c == '\t' || c == '\v' || c == '\r') {
  			if(c == '\n')
  				lineno++;
*** yaccpar.orig	Sun Feb 16 19:43:58 1997
--- yaccpar	Sun Feb 16 19:34:45 1997
***************
*** 16,21 ****

  # parser for yacc output
- yynerrs := 0;		# number of errors
- yyerrflag := 0;		# error recovery flag

  yytokname(yyc: int): string
--- 16,19 ----
***************
*** 33,40 ****
  }

! yylex1(): int
  {
  	c : int;
! 	yychar := yylex();
  	if(yychar <= 0)
  		c = yytok1[0];
--- 31,38 ----
  }

! yylex1(l: ref YYLEX): int
  {
  	c : int;
! 	yychar := l.lex();
  	if(yychar <= 0)
  		c = yytok1[0];
***************
*** 66,70 ****
  };

! yyparse(): int
  {
  	if(yysys == nil) {
--- 64,68 ----
  };

! yyparse(l: ref YYLEX): int
  {
  	if(yysys == nil) {
***************
*** 75,87 ****
  	yys := array[YYMAXDEPTH] of YYS;

! 	save1 := yylval;
! 	save2 := yyval;
! 	save3 := yynerrs;
! 	save4 := yyerrflag;
!
  	yystate := 0;
  	yychar := -1;
! 	yynerrs = 0;
! 	yyerrflag = 0;
  	yyp := -1;
  	yyn := 0;
--- 73,81 ----
  	yys := array[YYMAXDEPTH] of YYS;

! 	yyval: YYSTYPE;
  	yystate := 0;
  	yychar := -1;
! 	yynerrs := 0;		# number of errors
! 	yyerrflag := 0;		# error recovery flag
  	yyp := -1;
  	yyn := 0;
***************
*** 95,99 ****
  		yyp++;
  		if(yyp >= YYMAXDEPTH) {
! 			yyerror("yacc stack overflow");
  			yyn = 1;
  			break yystack;
--- 89,93 ----
  		yyp++;
  		if(yyp >= YYMAXDEPTH) {
! 			l.error("yacc stack overflow");
  			yyn = 1;
  			break yystack;
***************
*** 106,110 ****
  			if(yyn > YYFLAG) {	# simple state
  				if(yychar < 0)
! 					yychar = yylex1();
  				yyn += yychar;
  				if(yyn >= 0 && yyn < YYLAST) {
--- 100,104 ----
  			if(yyn > YYFLAG) {	# simple state
  				if(yychar < 0)
! 					yychar = yylex1(l);
  				yyn += yychar;
  				if(yyn >= 0 && yyn < YYLAST) {
***************
*** 114,118 ****
  						yyp++;
  						if(yyp >= YYMAXDEPTH) {
! 							yyerror("yacc stack overflow");
  							yyn = 1;
  							break yystack;
--- 108,112 ----
  						yyp++;
  						if(yyp >= YYMAXDEPTH) {
! 							l.error("yacc stack overflow");
  							yyn = 1;
  							break yystack;
***************
*** 120,124 ****
  						yystate = yyn;
  						yys[yyp].yys = yystate;
! 						yys[yyp].yyv = yylval;
  						if(yyerrflag > 0)
  							yyerrflag--;
--- 114,118 ----
  						yystate = yyn;
  						yys[yyp].yys = yystate;
! 						yys[yyp].yyv = l.lval;
  						if(yyerrflag > 0)
  							yyerrflag--;
***************
*** 134,138 ****
  			if(yyn == -2) {
  				if(yychar < 0)
! 					yychar = yylex1();
  		
  				# look through exception table
--- 128,132 ----
  			if(yyn == -2) {
  				if(yychar < 0)
! 					yychar = yylex1(l);
  		
  				# look through exception table
***************
*** 157,161 ****
  			# error ... attempt to resume parsing
  			if(yyerrflag == 0) { # brand new error
! 				yyerror("syntax error");
  				yynerrs++;
  				if(yydebug >= 1) {
--- 151,155 ----
  			# error ... attempt to resume parsing
  			if(yyerrflag == 0) { # brand new error
! 				l.error("syntax error");
  				yynerrs++;
  				if(yydebug >= 1) {
***************
*** 220,227 ****
  	}

- 	yylval = save1;
- 	yyval = save2;
- 	yynerrs = save3;
- 	yyerrflag = save4;
  	return yyn;
  }
--- 214,217 ----