Re: I need answer to a simple YACC question.

oakhill!epsilon!steve@cs.utexas.edu
Thu, 16 Feb 89 15:09:32 PST

          From comp.compilers

Related articles
I need answer to a simple YACC question. hp-sdd!najmi@hpcuhb.HP.COM (1989-02-03)
Re: I need answer to a simple YACC question. djones@megatest.uucp (1989-02-07)
Re: I need answer to a simple YACC question. oakhill!epsilon!steve@cs.utexas.edu (1989-02-16)
Re: I need answer to a simple YACC question. megatest!djones@decwrl.dec.com (1989-02-24)
Re: I need answer to a simple YACC question. megatest!djones@decwrl.dec.com (1989-02-24)
| List of all articles for this month |
From: oakhill!epsilon!steve@cs.utexas.edu
Date: Thu, 16 Feb 89 15:09:32 PST
Summary: Here is the code you need.
References: <3281@ima.ima.isc.com> <3328@ima.ima.isc.com>
Organization: Motorola Inc. Austin, Tx

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)


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.