FAQ
Except, what happens if there's an error and Lookup is given an empty
string? Will it return token.ILLEGAL?

When you use a string slice like that the indexes which weren't assigned a
value are assigned a zero value. In this case, an empty string "". Rather
than add extra code to check for the empty string I felt it more intuitive
to use the map.
On Thursday, 8 May 2014 11:18:52 UTC-7, griff...@gmail.com wrote:

In the post about tokens, you say you avoided using slices to make the
Lookup function easier to write, but the code for a slice is almost
identical to the code for a map:

var tok_strings = []string{
EOF: "EOF",
ILLEGAL: "Illegal",
COMMENT: "Comment",
INTEGER: "Integer",
LPAREN: "(",
RPAREN: ")",
ADD: "+",
SUB: "-",
MUL: "*",
QUO: "/",
REM: "%",
}


The only change you need to make in your Lookup function is to typecast t
to Token.
--
Alex Griffin

On Saturday, May 3, 2014 7:39:04 PM UTC-5, Rob Thornton wrote:

I wrote a 10 part series talking about writing a compiler from scratch in
Go.

I'd love to hear feedback from the community and suggestions for
improvement. I'm sure I've cocked something up but hopefully nothing too
badly. The first post can be found at:
http://noeffclue.blogspot.ca/2014/05/compiler-part-1-introduction-to-writing.html

Go has helped me tremendously when it comes to compiler design and I hope
I've it justice. I want to take my hat off to everyone involved in making
such an awesome language.

A special thanks to Rob Pike who gave me the encouragement to learn
assembly and Ian Lance Taylor who took the time to answer my questions on
stacks. These thanks apply more to the 2nd series I'm in the middle of
writing rather than the one listed above, but I digress.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 11 of 11 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 4, '14 at 12:39a
activeMay 9, '14 at 3:58p
posts11
users7
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase