golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.06k stars 17.68k forks source link

goyacc generating error #618

Closed gopherbot closed 9 years ago

gopherbot commented 14 years ago

by superisaac.ke:

I wrote a simple expression evaluator that accept and evaluate strings such as 
"1 + 4 * 2 / 3".  The part of grammar is 
expr1:
         NUMBER
|        expr1 '*' NUMBER
{
    $$.numval = $1.numval * $3.numval
    finalval = $$.numval
}
|       expr1 '/' NUMBER
{
    $$.numval = $1.numval / $3.numval
    finalval = $$.numval
}
Then it reports the following error: 
y.go:61: syntax error: unexpected $
when I went to the y.go 
61: YYVAL.numval = YYS[yypt-2].numval / $3.numval
$3 is not changed into YYS[yypt-3], seems there are somthing wrong. "/" was 
considered as the begining of comment in one line. however if $3.number is 
at different line with "$$.numval = $1.numval /" the program is OK

Attachments:

  1. goexpr.y (1695 bytes)
gopherbot commented 14 years ago

Comment 1 by superisaac.ke:

YYS[yypt-3] should be YYS[yypt-0]
robpike commented 14 years ago

Comment 2:

Owner changed to k...@golang.org.

Status changed to Accepted.

rsc commented 14 years ago

Comment 3:

i think this is because goyacc is a transliteration of the limbo yacc,
and in limbo the comment character is a single #.
the translation converted # to / but missed the doubling.
robpike commented 14 years ago

Comment 4:

yes, that's it. will fix.

Owner changed to r...@golang.org.

robpike commented 14 years ago

Comment 5:

This issue was closed by revision 38202de114b6cf25f4ad900f64cd73bf2414748.

Status changed to Fixed.

Merged into issue #-.