cznic / goyacc Goto Github PK
View Code? Open in Web Editor NEWgithub.com/cznic/goyacc has moved to modernc.org/goyacc
Home Page: https://godoc.org/modernc.org/goyacc
License: BSD 3-Clause "New" or "Revised" License
github.com/cznic/goyacc has moved to modernc.org/goyacc
Home Page: https://godoc.org/modernc.org/goyacc
License: BSD 3-Clause "New" or "Revised" License
i am trying to consume a large grammer file (postgresql) which is in Bison format.
Bison is supposed to be the GNU implementation/extension of Yacc but I think it has some differences since I got a syntax error. I have not spent time to find out the differences between Yacc/Bison related to this. Maybe you can comment on that.
The section that cause the error is
OptSchemaEltList:
OptSchemaEltList schema_stmt
{
if (@$ < 0) /* see comments for YYLLOC_DEFAULT */
@$ = @2;
$$ = lappend($1, $2);
}
| /* EMPTY */
{ $$ = NIL; }
;
The @$
causes: strconv.ParseInt: parsing "": invalid syntax:
Type of $$
gets overwrtitten by the type of last $n
used.
$ cat test.y
%union {
val string
}
%token <val> INT
%%
Start:
INT
{
_ = $1
return 0
}
$ goyacc -o /dev/stdout 2>/dev/null test.y | grep valreturn
_ = stack[sp-0].valreturn 0
$
They should be sorted. Also, some of the defaults are documented after the flag while others after the description: make it uniform.
Cf. #2
The error list is scanner.ErrorList
. The Error() method of scanner.ErrorList
returns only the first error.
Probably only in parsers with conflicts. It never occured to me test such cases, but it must work and must produce stable, best-effort parsers as the original yacc does.
I have a *.y file to generate a parser for sql, but I found there was different output between MacOS(10.13) and Linux(CentOS 6.3).
Ant the output parser from MacOS not working good. I had to generate the parser on linux and send the parser file to mac to continue my work.
There are lost of different between to parser.
I use the command like this:
goyacc -o sql.go sql.y
gofmt -w sql.go
hi
How build goyacc tool in GO?
i have goyacc -h
package in my system.
but want install go tool yacc
on go 1.8
how can do this?
go fmt
go test
PASS
ok github.com/cznic/goyacc 0.002s
go install
go tool vet -printfuncs "Log:0,Logf:1" *.go
golint .
make todo
make[1]: Entering directory '/home/guest/go/src/github.com/cznic/goyacc'
main.go:554: _ = yyerrok
main.go:706: _ = yypt // guard against "declared and not used"
main.go:791: _ = oNoLines //TODO Ignored for now
all_test.go:37:func TODO(...interface{}) string {
all_test.go:39: return fmt.Sprintf("TODO: %s:%d:\n", path.Base(fn), fl)
main.go:791: _ = oNoLines //TODO Ignored for now
make[1]: Leaving directory '/home/guest/go/src/github.com/cznic/goyacc'
I was trying to parse cockroachdb's sql.y and hit a bug:
sql.y:454:9: unexpected '*', expected identifier
It appears this doesn't like the *
in %token <*tree.NumVal> ICONST FCONST
.
Hi,
parser.y:36:41: $$ of declarations has no declared type (and 30 more errors)
what does it complain?
program: declarations
{
}
declarations: declaration
{
declarationNode := newDeclarationNode($$.funcDecl)
$$.node = declarationNode
cast(yylex).SetAstRoot($$.node)
}
goyacc inherited issue 9099.
Should produce at least the non formatted version in such case.
$ cat bug.y
%union{
val int
vals []int
}
%token I
%type <vals> L
%%
S: L
L:
{
$$ = []int(nil)
}
| L I
{
$$ = append($$, $2)
}
$ goyacc -o /dev/stdout bug.y | grep yypt-0
Parse table entries: 5 of 24, x 8 bits == 5 bytes
yyVAL.vals = append(yyVAL.vals, yyS[yypt-0].)
$
Token I
should have been declared as %token <val> I
, but the missing type of $2
gets undetected by the y
package. Goyacc then renders invalid Go code.
Token values are assigned when ranging a map. Make the order of assigning the values stable to improve VCS diffs.
It's always yyDebug
but the prefix should come from the -p
option value.
The documented order is rule, state, ...
but the actual order is incorrectly state, rule, ...
.
... as -1
, but the value generated by cznic/y
should be used instead.
And one more bug in error recovery - instead of proper stem there's a hardcoded yy
.
Use the go/format.Source, Luke.
Not yet implemented as of now.
I have a parser that has the following basic structure:
program
: statements
;
statements
: statement
| statement statements
;
And I am getting the following error: y.go:348:12: duplicate index in array literal: 5
I opened up y.go
and lines 345-349 look like this:
yyParseTab = [83][]uint8{
// 0
{4: 46, 14: 50, 49, 25: 47, 32: 48, 45, 44, 36: 43},
{5: 42, 5: 42, 5: 42, 5: 42, 5: 42},
{1: 41, 5: 41, 41, 12: 41, 41},
...
}
If I'm not mistaken, it looks like the error corresponds to state 1. But I'm not a yacc expert, by any means. Looking at y.output
for state 1 gives the following:
state 1 // NAME SEMICOLON [$end]
0 $accept: program . [$end, AND, ARROW, LCURLY, OR]
$end accept
AND accept
ARROW accept
LCURLY accept
OR accept
So, I think I'm reading this correctly as "we just reduced program
, so check whether the next token is $end
, AND
, ARROW
, LCURLY
, or OR
." I'm not sure why it would be checking that though because there is no valid token other than $end
that can occur after reducing to program
, which is making me think this may be an issue with goyacc
. It appears to work if I manually alter the entry to just {5: 42}
. Thoughts?
The problem propagates from $go tool yacc
used by cznic/parser/yacc, see issue #2
I feel as though I should not have had to write this:
// Tokname returns the string name of a token type (for testing purposes).
func Tokname(i int) string {
if i < 128 {
return string([]byte{byte(i & 0xff)})
}
return cparseTokname(i - 57342)
}
That magic number is particularly annoying.
Would you please make something equivalent a public method?
Hi,
could you upload some examples which uses goyacc together with golex?
Thanks,
Gerald
It always start with yy
but the prefix should come from the -p option value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.