way better lex function
This commit is contained in:
parent
6f7adc0789
commit
65cecb3647
7 changed files with 60 additions and 37 deletions
|
|
@ -1,56 +0,0 @@
|
|||
package shsh
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func FmtToken(arg *Token) string {
|
||||
suffix := ""
|
||||
if arg.next != nil {
|
||||
suffix = "->"
|
||||
}
|
||||
|
||||
switch arg.tag {
|
||||
case LIST:
|
||||
return fmt.Sprintf("(%s, List @ %p, %d)%s", "LIST", arg._inner,
|
||||
arg.position, suffix)
|
||||
|
||||
default:
|
||||
return fmt.Sprintf("(%s, %s, %d)%s", GetTagAsStr(arg.tag), arg._inner,
|
||||
arg.position, suffix)
|
||||
}
|
||||
}
|
||||
|
||||
func GetTagAsStr(tag token_t) string {
|
||||
switch tag {
|
||||
case LIST:
|
||||
return "LIST"
|
||||
case STRING:
|
||||
return "STRING"
|
||||
case NUMBER:
|
||||
return "NUMBER"
|
||||
case SYMBOL:
|
||||
return "SYMBOL"
|
||||
}
|
||||
return "UNKNOWN"
|
||||
}
|
||||
|
||||
func PrintSExpression(arg *Token) {
|
||||
var lists TokenStack;
|
||||
lists.Push(arg)
|
||||
|
||||
loop:
|
||||
var constructor strings.Builder
|
||||
i := lists.Pop()
|
||||
if i == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for iter := i; iter != nil; iter = i.next {
|
||||
constructor.WriteString(FmtToken(iter))
|
||||
}
|
||||
|
||||
print(constructor.String())
|
||||
goto loop
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue