Ejemplo n.º 1
0
func GetPoints(character string) uint {
	switch character {
	case "e", "a", "i", "o", "n", "r", "t", "l", "s", "u":
		return 1
	case "d", "g":
		return 2
	case "b", "c", "m", "p":
		return 3
	case "f", "h", "v", "w", "y":
		return 4
	case "k":
		return 5
	case "j", "x":
		return 8
	case "q", "z":
		return 10
	}
	cgreader.Tracef("Error, unknown Character: %s", character)
	return 0
}
Ejemplo n.º 2
0
func RecursiveParser(command *Command) {
	for ; streamIsValid && currentStreamIndex < len(rawProgramStream); currentStreamIndex++ {
		characterCounter++

		switch rawProgramStream[currentStreamIndex] {
		case PI:
			command.add(&Command{func([]*Command) {
				programIndex++
			}, nil})

		case PD:
			command.add(&Command{func([]*Command) {
				programIndex--
			}, nil})

		case VI:
			command.add(&Command{func([]*Command) {
				programBuffer[programIndex]++
			}, nil})

		case VD:
			command.add(&Command{func([]*Command) {
				programBuffer[programIndex]--
			}, nil})

		case IN:
			command.add(&Command{func([]*Command) {
				if inputIsAvailable {
					if len(programInput) == 0 {
						programInput = []byte(<-inputChannel)
					}

					if len(programInput) > 0 {
						programBuffer[programIndex] = brainfuck_t(programInput[0])
						programInput = programInput[1:]
					} else {
						programBuffer[programIndex] = EOF
					}
				} else {
					programBuffer[programIndex] = EOF
				}
			}, nil})

		case NOUT:
			command.add(&Command{func([]*Command) {
				if outputIsAvailable {
					outputChannel <- fmt.Sprintf("%d", programBuffer[programIndex])
				}
			}, nil})

		case COUT:
			command.add(&Command{func([]*Command) {
				if outputIsAvailable {
					outputChannel <- fmt.Sprintf("%s", string(programBuffer[programIndex]))
				}
			}, nil})

		case START:
			startLoopCounter++
			currentStreamIndex++

			loop := CreateLoopGroup()
			RecursiveParser(loop)
			command.add(loop)

		case STOP:
			if stopLoopCounter > startLoopCounter {
				ErrorTextParseError("Parsed filed, encountered \"]\" while expecting ><+-,.#[", lineCounter, characterCounter)
				streamIsValid = false
			}

			stopLoopCounter++
			return

		case LF, CR:
			lineCounter, characterCounter = lineCounter+1, 0

		case TRACE:
			command.add(&Command{func([]*Command) {
				cgreader.Tracef("[%d] = %d\n", programIndex, programBuffer[programIndex])
			}, nil})
		}
	}
}