[comp.unix.microport] YAMB: problems with yacc?

jay@splut.UUCP (Jay Maynard) (03/20/88)

I tried entering the program hoc1, from the book _The Unix Programming
Environment_, and compiling it last night. It doesn't run: when fed an
expression like 2+2, instead of printing 4, it prints 2. It appears to
reproduce productions of the form:
expr: expr '+' expr { $$ = $1 + $3 }...
by simply returning $3, instead of computing the sum. I have checked the
program against the printed source in the book twice, and found no
errors. Neither yacc nor cc complain during compilation of the program.
I tried #defining YYDEBUG and setting yydebug to 1, but just got a lot
of output that I don't understand.
Am I bashing my head against YAMB (yet another Microport bug)?
Vitals: System V/AT (286) 2.3.0, plenty of (hard and ram-) disk.
I'd post the program here, to see if anyone else has the problem, but am
unsure of the legalities. (Any help here appreciated.)
The reason behind running a program that, according to its authors,
"provides about the same capabilities as a minimal pocket calculator,
and is substantially less portable"? I wanted to make sure I could make
it run before I went to the time and effort of keying in hoc6, the
full-featured version.

-- 
Jay Maynard, EMT-P, K5ZC...>splut!< | GEnie: JAYMAYNARD  CI$: 71036,1603
uucp: {uunet!nuchat,academ!uhnix1,{ihnp4,bellcore,killer}!tness1}!splut!jay
Never ascribe to malice that which can adequately be explained by stupidity.
The opinions herein are shared by none of my cats, much less anyone else.

nix@xinx.UUCP (Takuji Akiyama) (03/21/88)

In article <437@splut.UUCP>, jay@splut.UUCP (Jay Maynard) writes:
> I tried entering the program hoc1, from the book _The Unix Programming
> Environment_, and compiling it last night. It doesn't run: when fed an
> expression like 2+2, instead of printing 4, it prints 2. It appears to
> reproduce productions of the form:... (many lines deleted)

Yes, it's YAMB.  I reported it about 9 months ago (when microport was
1.3) and did again on BIX (Byte Information eXchange) few manths ago.  
Seems they admitted it as a bug, but havn't put it on bug list,yet.
'dleu' told us (on BIX) they will *TRY TO* fix this bug in next version.

BTW, I tried to 'yacc' same yacc-src-code on diffrent system (very old
VENIX/86 on pc/xt!) and transfer back to microport, then 'cc' it.
It DID work!  If you have other unix system handy, give it try.

							|nix|
---
Takuji Akiyama (nix)            Workshop Mu
USnail: 2306 E 18th St. #A-11   UUCP:  uunet!xinx!nix  
        Vancouver, WA 98661     ICBM:  45 25 N / 122 38 W

markz@ssc.UUCP (Mark Zenier) (03/22/88)

In article <437@splut.UUCP>, jay@splut.UUCP (Jay Maynard) writes:
> I tried entering the program hoc1, from the book _The Unix Programming
> Environment_, and compiling it last night. It doesn't run: when fed an
> expression like 2+2, instead of printing 4, it prints 2. It appears to
> reproduce productions of the form:
> expr: expr '+' expr { $$ = $1 + $3 }...
> ...
> Am I bashing my head against YAMB (yet another Microport bug)?
> ...
> Jay Maynard, EMT-P, K5ZC...>splut!< | GEnie: JAYMAYNARD  CI$: 71036,1603
> ...


Having written 8 cross assemblers, a database screen compiler and mucked with
a spreadsheet, I'm pretty sure that Yacc on Microport is clean. (Plug, Plug)

It sounds like Yacc is interpeting your action as an imbedded one.

"Actions that do not terminate a rule are actually handled by yacc by 
manufactureing a new nonterminal ..."

The next stuff after the closing } needs to be a semicolon or
a vertical bar.  

example

expr : expr '+' expr
	{ $$ = $1 + $3; }
    ;  

or

expr : expr '+' expr
	{  $$ = $1 + $3 }
    |  expr '*' expr
	{  $$ =    ... and so on

Mark Zenier, Specialized Systems Consultants, Inc.

work@dragos.UUCP (Dragos Ruiu) (03/22/88)

In article <437@splut.UUCP>, jay@splut.UUCP (Jay Maynard) writes:
> I tried entering the program hoc1, from the book _The Unix Programming
> Environment_, and compiling it last night. It doesn't run: when fed an
> expression like 2+2, instead of printing 4, it prints 2. It appears to
> reproduce productions of the form:
> expr: expr '+' expr { $$ = $1 + $3 }...
> by simply returning $3, instead of computing the sum. I have checked the
> program against the printed source in the book twice, and found no
> errors. Neither yacc nor cc complain during compilation of the program.

> Vitals: System V/AT (286) 2.3.0, plenty of (hard and ram-) disk.
> 
> -- 
> Jay Maynard, EMT-P, K5ZC...>splut!< | GEnie: JAYMAYNARD  CI$: 71036,1603
> uucp: {uunet!nuchat,academ!uhnix1,{ihnp4,bellcore,killer}!tness1}!splut!jay

 I also encountered the bug in yacc. It seems to be in the add/sub/mult/div
 of two floating point numbers. I spent a bit of time looking over this
 problem... but I eventually discarded my work and tried the desc calculator
 program I wrote on BSD and HP-UX systems and they worked there.

 I can dig up the sources in a day, but if my memory serves me correctly,
 it's not a Yacc problem... I believe it was a bug in the c compiler as I
 went and actually debugged the yacc output. There is a large set of
 indirection and structure references produced by yacc, and printfs on the
 intermediate results and actual results just don't match. Unfortunately
 I don't have time to track down this bug anymore.
 
 I can email the sources which produce bugs to interested parties. Or if
 enough people are interested I can post them. They aren't long.

-- 
Dragos Ruiu   ruiu@dragos.UUCP
              ...alberta!dragos!ruiu	  OS/2... No thanks I have a pencil.

Disclaimer: These are my employers opinions. I'm unemployed.

wswietse@eutrc3.UUCP (Wietse Venema) (03/23/88)

In article <437@splut.UUCP>, jay@splut.UUCP (Jay Maynard) writes:
> I tried entering the program hoc1, from the book _The Unix Programming
> Environment_, and compiling it last night. It doesn't run: when fed an
> expression like 2+2, instead of printing 4, it prints 2. It appears to
> reproduce productions of the form:
> expr: expr '+' expr { $$ = $1 + $3 }...
> ...
> Am I bashing my head against YAMB (yet another Microport bug)?
> ...
> Jay Maynard, EMT-P, K5ZC...>splut!< | GEnie: JAYMAYNARD  CI$: 71036,1603
> ...

Well, actually it's a bug in the C compiler. Take a look of the 
assembly language generated by the compiler. Seems the compiler
generates incorrect 80287 opcodes. BTW we reported this problem
a long time ago (6 months) in the days of version 2.2. What 
happened to that bug list?

The problems should go away if you typedef the YACC stack as int.

-- 
uucp:	mcvax!eutrc3!wswietse	| Eindhoven University of Technology
bitnet:	wswietse@heithe5	| Dept. of Mathematics and Computer Science
surf:	tuerc5::wswietse	| Eindhoven, The Netherlands.

markz@ssc.UUCP (Mark Zenier) (03/23/88)

In article <437@splut.UUCP>, jay@splut.UUCP (Jay Maynard) writes:
> I tried entering the program hoc1, from the book _The Unix Programming
> Environment_, and compiling it last night. It doesn't run: when fed an
> expression like 2+2, instead of printing 4, it prints 2. It appears to
> reproduce productions of the form:... (many lines deleted)

After this posting and the one from nix, I typed in hoc1 and tried it.
Yup it blew up. 

It even printed out the bad values in the action, right after the addition. 

Hmmmm, after I converted the stack and NUMBER type from double to long 
it worked.

In summary, its the damn floating point in the c compiler choking on the
references to the stack.

example 
	yylval = yypvt[-2] + yypvt[-0];

This compiler is a piece of dung when it comes to floating point.

For a real debugging thrill, try using 1.0e-7 as an initializer, and
then try to figure out why the assembler blows up.

Mark Zenier