occs-compilers-2014-spring / discussion

A place for discussion
0 stars 0 forks source link

Why does Bob say we need so many states for the table-driven scanner? #1

Closed erose closed 10 years ago

erose commented 10 years ago

It seemed like Bob was saying we needed 40-ish "states" for the table-driven scanner (a 40 x 127 table). Does anyone know where that number is coming from? To me it seems like you would only need a few -- "default" (not currently reading in a keyword or identifier), "in_word" (in the middle of reading a word that might turn out to be a keyword or identifier). Also an "in_comment" I guess. I think Bob said something about why all those states were necessary but I don't remember what it was. Does anyone know?

ikehz commented 10 years ago

This is for the transition table, not the action table, right? I think it's for the ~40 characters that are readable in the language: 26 alphas, 10 digits, parentheses, etc.

erose commented 10 years ago

Yeah, it's the transition table. Okay, that makes sense. Just confused me because you don't do anything different upon e.g. seeing a '0' as opposed to a '9'. I ended up having a lot fewer states, which, upon reflection, I guess was because I didn't strictly speaking use a table.

ikehz commented 10 years ago

Yeah, you can use states or—maybe what you did—use object orientation to kind of implicitly define states.