|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/01-edu/z01"
|
|
|
|
)
|
|
|
|
|
|
|
|
const SIZE = 2048
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) == 2 {
|
|
|
|
progpoint := []byte(os.Args[1])
|
|
|
|
var arby [SIZE]byte
|
|
|
|
pos := 0
|
|
|
|
openBr := 0 //opened brackets
|
|
|
|
i := 0 //iterates through the source code passed in the argument
|
|
|
|
N := len(progpoint) //length of the source code
|
|
|
|
for i >= 0 && i < N {
|
|
|
|
switch progpoint[i] {
|
|
|
|
case '>':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// Increment the pointer
|
|
|
|
pos++
|
|
|
|
case '<':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// decrement the pointes
|
|
|
|
pos--
|
|
|
|
case '+':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// increment the pointed byte
|
|
|
|
arby[pos]++
|
|
|
|
case '-':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// decrement the pointed byte
|
|
|
|
arby[pos]--
|
|
|
|
case '.':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// print the pointed byte on std output
|
|
|
|
z01.PrintRune(rune(arby[pos]))
|
|
|
|
case '[':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// go to the matching ']' if the pointed byte is 0 (while start)
|
|
|
|
openBr = 0
|
|
|
|
if arby[pos] == 0 {
|
|
|
|
for i < N && (progpoint[i] != byte(']') || openBr > 1) {
|
|
|
|
if progpoint[i] == byte('[') {
|
|
|
|
openBr++
|
|
|
|
} else if progpoint[i] == byte(']') {
|
|
|
|
openBr--
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case ']':
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// go to the matching '[' if the pointed byte is not 0 (while end)
|
|
|
|
openBr = 0
|
|
|
|
if arby[pos] != 0 {
|
|
|
|
for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) {
|
|
|
|
if progpoint[i] == byte(']') {
|
|
|
|
openBr++
|
|
|
|
} else if progpoint[i] == byte('[') {
|
|
|
|
openBr--
|
|
|
|
}
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
z01.PrintRune('\n')
|
|
|
|
}
|
|
|
|
}
|