yacc & lex for Go?

3,644 views
Skip to first unread message

Mr.Solo

unread,
May 5, 2011, 11:52:19 PM5/5/11
to golang-nuts
I want to write a simple translator, from one language (a little like
latex) to HTML. So I decided that yacc and lex would be great for this
job.

I think there should be a lex tool for Go. But I didn't find it.
Anyone who knows? If yes, I think a guide or example to write lexer in
Go is also needed.

I see there is goyacc in $GOROOT/bin. It can generate parser.go from
parser.y. Somebody has an example or tutorial of writing parser.y in
Go?
I tried to write a very simple one, but I don't even know what
function to call in its main(I tried, not yyparse() like in C).

Many Thanks!!

Mr.Solo

unread,
May 5, 2011, 11:56:43 PM5/5/11
to golang-nuts
I saw a package called ebnf. Seems like ebnf has similar functionality
as goyacc? Or ebnf can only parse Go code?

Evan Shaw

unread,
May 6, 2011, 12:59:44 AM5/6/11
to Mr.Solo, golang-nuts
On Fri, May 6, 2011 at 3:52 PM, Mr.Solo <liyaoh...@gmail.com> wrote:
> I think there should be a lex tool for Go. But I didn't find it.
> Anyone who knows? If yes, I think a guide or example to write lexer in
> Go is also needed.

There's nothing official but this looks promising (and compatible with
goyacc): https://github.com/blynn/nex

> I see there is goyacc in $GOROOT/bin. It can generate parser.go from
> parser.y. Somebody has an example or tutorial of writing parser.y in
> Go?

There's some documentation here: http://golang.org/cmd/goyacc/

- Evan

Arlen Cuss

unread,
May 6, 2011, 4:24:36 AM5/6/11
to Mr.Solo, golang-nuts
I posted an announcement about golex a few weeks ago: https://groups.google.com/group/golang-nuts/browse_thread/thread/5894413c5f8633b9/fac36a835bb7e222?lnk=gst&q=golex+again#fac36a835bb7e222

It aims to be fully flex compatible, and it works with goyacc. Here's the page itself:


2011/5/6 Mr.Solo <liyaoh...@gmail.com>



--
Arlen Cuss
Software Engineer
Noble Samurai

Jan Mercl

unread,
May 6, 2011, 1:01:42 PM5/6/11
to golan...@googlegroups.com, liyaoh...@gmail.com
On Friday, May 6, 2011 5:52:19 AM UTC+2, Mr.Solo wrote:
I think there should be a lex tool for Go. But I didn't find it.
Anyone who knows? If yes, I think a guide or example to write lexer in
Go is also needed.

If you have the latest weekly.2011-04-27, which newly enabled goinstall to handle also commands/tools additionally to packages, then you might want to try:


In the golex sources and it's directory there are some godocs and examples, e.g. to demonstrate how long it takes to scan the whole Go source tree:

~/go/src/pkg/github.com/cznic/golex$ gomake example2 && time ./example2
...
1089 .go files, 7256536 bytes, 1324831 tokens

real 0m0.254s
user 0m0.220s
sys 0m0.040s

Please feel free to contact me with questions and/or to get support.

Michael Jones

unread,
May 6, 2011, 2:56:11 PM5/6/11
to golan...@googlegroups.com, liyaoh...@gmail.com
It would be interesting to instrument modes of use. (number of cases, frequency of multiple assignment by tuple size, number of semicolons, ...
--

Michael T. Jones

   Chief Technology Advocate, Google Inc.

   1600 Amphitheatre Parkway, Mountain View, California 94043

   Email: m...@google.com  Mobile: 650-335-5765  Fax: 650-649-1938

   Organizing the world's information to make it universally accessible and useful


sambeau

unread,
May 9, 2011, 5:37:25 PM5/9/11
to golang-nuts
It would be great to see a Go generator for Ragel:

http://www.complang.org/ragel/

I keep promising myself that I will tackle it bet ever get round to
it...

...anyone?

Alek

unread,
May 10, 2011, 9:33:34 AM5/10/11
to golan...@googlegroups.com
This work: http://code.google.com/p/pego/

is also in field of lex/yacc alternatives - This is very clean port of Roberto Ierusalimschy's C parsing machine for Lua. Dr.Ierusalimschy (the Lua author) approach gives reasonably fast PEG (which also means scannerless) parsing, without the memory weight of Packrat algorithm.

Scannerless parsing is very actual today, because of increased usage of nested grammars (HTML/XML/JS/DSLs or language extensions for example) and need of semantic (parsing time) predicates for hard lanaguages.

Best Regards,
Alek

André Moraes

unread,
May 10, 2011, 12:13:31 PM5/10/11
to golang-nuts
> It would be great to see a Go generator for Ragel:
> I keep promising myself that I will tackle it bet ever get round to
> it...

On Ragen trunk you have the Go generator.

--
André Moraes
http://andredevchannel.blogspot.com/

Reply all
Reply to author
Forward
0 new messages