InitStatus finite state machine
(b byte, values []byte)
| 245 | |
| 246 | // InitStatus finite state machine |
| 247 | func InitStatus(b byte, values []byte) (string, []byte) { |
| 248 | if isLetter(b) { |
| 249 | values = append(values, b) |
| 250 | if b == 'i' { |
| 251 | return Int1, values |
| 252 | } |
| 253 | return Identifier, values |
| 254 | } |
| 255 | |
| 256 | if b == '>' { |
| 257 | values = append(values, b) |
| 258 | return GT, values |
| 259 | } |
| 260 | if b == '=' { |
| 261 | values = append(values, b) |
| 262 | return Assignment, values |
| 263 | } |
| 264 | if isDigit(b) { |
| 265 | values = append(values, b) |
| 266 | return IntLiteral, values |
| 267 | } |
| 268 | |
| 269 | if b == '+' { |
| 270 | values = append(values, b) |
| 271 | return Plus, values |
| 272 | } |
| 273 | if b == '-' { |
| 274 | values = append(values, b) |
| 275 | return Minus, values |
| 276 | } |
| 277 | if b == '*' { |
| 278 | values = append(values, b) |
| 279 | return Star, values |
| 280 | } |
| 281 | if b == '/' { |
| 282 | values = append(values, b) |
| 283 | return Slash, values |
| 284 | } |
| 285 | if b == '(' { |
| 286 | values = append(values, b) |
| 287 | return LeftParen, values |
| 288 | } |
| 289 | if b == ')' { |
| 290 | values = append(values, b) |
| 291 | return RightParen, values |
| 292 | } |
| 293 | if b == '\n' { |
| 294 | values = append(values, b) |
| 295 | return Enter, values |
| 296 | } |
| 297 | |
| 298 | return Init, values |
| 299 | } |
| 300 | |
| 301 | func isLetter(b byte) bool { |
| 302 | return b >= 65 && b <= 122 |