News for hackers. Stuff that matters.
Re:Porting the Go compiler from C to Go by daeken on Friday April 25, 2014 @01:11PM (#7647739)
I'm not surprised to see them in a compiler. When you're parsing and want to treat it as a big state machine, gotos are your best friend.
Re:Porting the Go compiler from C to Go by clarry on Friday April 25, 2014 @02:44PM (#7648335)
Encoding state implicitly in control flow tends to give you nicer and more natural code. A big state machine implemented with gotos can be tough to read if it's also a parser (which may need to build a tree, recurse, etc.). A small hand-rolled lexer might be reasonable to implement with goto. Although I would prefer to enumerate the states and use a switch.

If you're writing a recursive descent parser for C while keeping minimal lookahead, I can think of a place or two where goto might really help. One is to deal with casts, compound literals and subexpressions. They all begin with a left-parenthesis, so you can't tell what you're dealing with until a bit further. Since these all appear in the parsing of simple expressions (identifiers, constants, unary operators), the code can go in one function and you can jump to the right place with goto as soon as you know what you are dealing with.

I did not look in the Go code but C programmers mostly use goto for error paths.

Re:Porting the Go compiler from C to Go by bakul on Friday April 25, 2014 @02:33PM (#7648267)
Except in languages with tail recursion such as Scheme! A state ends with a call to the next state instead of a goto next state.