Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!compilers-sender From: oakhill!epsilon!steve@cs.utexas.edu Newsgroups: comp.compilers Subject: Re: I need answer to a simple YACC question. Summary: Here is the code you need. Message-ID: <3359@ima.ima.isc.com> Date: 16 Feb 89 23:09:32 GMT References: <3281@ima.ima.isc.com> <3328@ima.ima.isc.com> Sender: compilers-sender@ima.ima.isc.com Reply-To: oakhill!epsilon!steve@cs.utexas.edu Organization: Motorola Inc. Austin, Tx Lines: 64 Approved: compilers@ima.UUCP In article <3328@ima.ima.isc.com>, djones@megatest.uucp (Dave Jones) writes: > [yacc error states are hard to analyze, particularly if you want to see > the follow sets in a particular context.] In fact here is the code that does this error dumping: 257,275c256,257 < if ((yy_n = yypact[yystate]) > YYFLAG && yy_n < YYLAST) < { < short index; < extern char *p_error(); < fprintf(stderr,"expecting: "); < for (index = yy_n>0 ? yy_n : 0; < index < YYLAST; < ++index) < { < if (yychk[yyact[index]] == index - yy_n < && index - yy_n != YYERRCODE) < fprintf(stderr,"%s, ",p_error(index-yy_n)); < } < fprintf(stderr,"found:"); < fprintf(stderr,"%s\n",p_error(yychar)); < } < else < yyerror( "syntax error" ); < goto skip_init; --- > yyerror( "syntax error" ); > goto skip_init; For those of you who cannot tell this is a diff of yaccpar that does that does this error dumping. This yaccpar is from the standard SYSTEM V. You do need to supply the function char *p_error(int). This function takes the token number passed in, and changes it into a string name for that token. Errors come out in the fashion: expecting: ')', ',', '+', found '['. Not totally coherent, but better than 'syntax error'. This message gets very long in some cases. Three last notes: 1) Credit for this change does not belong to me but to one of my partners at Remora, Inc. I think he got this trick from a book (which my copy is unfortunately at home) on building a compiler in UNIX (reference supplied if requested). At least I can claim I understand what is happening here. 2) Do not comment on the programing style too much. This code was hacked today from our (Remora's) version of yaccpar into the UNIX version just for this post. The code as posted works (is tested). 3) Excuse the cryptic nature of this message, I am typing it in on my own lunch time when I should be debuging Motorola's code. enough from this mooncalf - Steven -- Steven R Weintraub cs.utexas.edu!oakhill!devsys!steve Motorola Inc. Austin, Texas (512) 440-3023 (office) (512) 453-6953 (home) -- Send compilers articles to ima!compilers or, in a pinch, to Levine@YALE.EDU Plausible paths are { decvax | harvard | yale | bbn}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request