(Message perl/py:5) Replied: Wed, 22 Apr 1998 10:40:39 -0400 Return-Path: gbacon@mickey.cs.uah.edu Return-Path: Delivered-To: mjd-filter-deliver@plover.com Received: (qmail 30929 invoked by uid 119); 22 Apr 1998 14:39:13 -0000 Delivered-To: mjd-filter@plover.com Received: (qmail 30924 invoked by uid 119); 22 Apr 1998 14:39:09 -0000 Delivered-To: mjd@plover.com Received: (qmail 30921 invoked from network); 22 Apr 1998 14:39:07 -0000 Received: from pluto.cs.uah.edu (146.229.2.78) by plover.com with SMTP; 22 Apr 1998 14:39:07 -0000 Received: from mickey.cs.uah.edu (from mickey [146.229.2.62]) by pluto.cs.uah.edu (SMI-8.6/SMI-SVR4) id JAA01846; Wed, 22 Apr 1998 09:30:19 -0500 Message-Id: <199804221430.JAA01846@pluto.cs.uah.edu> To: Mark-Jason Dominus Subject: Re: possible py bug Reply-To: gbacon@cs.uah.edu X-Face: "7sfK9d*!trQg^>swxP}M|R|<7$tFtlm|Z(4M$i`?}l87xigz\37|mQUBi/ct#>=H,&(V!A 6=jnjOfA#.0Q@jF1t~Eue)5=zFI In-Reply-To: Your message of "Wed, 22 Apr 1998 10:21:53 EDT." <19980422142153.30847.qmail@plover.com> Date: Wed, 22 Apr 1998 09:29:40 -0500 From: Greg Bacon In message <19980422142153.30847.qmail@plover.com>, Mark-Jason Dominus writes: : Actually, could you just send me the original .y file, and : the test input that you gave to the parser? ---- begin assem.y ---- %token ID INT /* directives */ %token START /* instructions */ %token ADD %% line : label direct | label instr ; label : ID | ; direct : START addr ; instr : ADD addr ; addr : INT | ID ; ---- end assem.y ---- ---- begin source.asm ---- TEST START 0 ADD TEST ---- end source.asm ---- In case you're wondering, I'm writing an assembler for a system software class. : > I changed line 60 of py-skel.pl to : > : > $state = $states[$#states] || 0; : > : > and it worked, : : I bet it didn't. For one thing, I'm totally sure line 50 is wrong: : - @args = splice(@values, -$length[$d]); : + @args = splice(@values, -$length[$d]) if $length[$d] : : Otherwise, you splice out the entire value stack. TOKENS: [][TEST][ ][START][ ][0] $VAR1 = { 'line' => 1, 'label' => 'TEST', 'direct' => { 'addr' => '0', 'direct' => 'START' } }; TOKENS: [ ][ADD][ ][TEST] $VAR1 = { 'line' => 2, 'instr' => { 'instr' => 'ADD', 'addr' => 'TEST' } }; ...which is the correct parse. : > Is there any equivalent of yyerror (or how do I say `fail' from within : > a rule)? : : Do you mean YYERROR? (I haven't done this in a really long time.) I : don't think so but it shouldn't be hard to add. Let me reread the : doscs and get back to you. What I'm interested in doing is purposefully parsing bad syntax to give error messages that are a little more helpful. I suppose it would be possible to examine the result from yyparse's caller to achieve the same effect. It would still be nice to have a way to abort the parse from within the rules. Greg