summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-01-01 00:22:25 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-01-01 00:22:25 +0400
commiteb9fab2b0e9124ab0c9ef9091dfb2950f2857be2 (patch)
tree413aa1800c5fac5daa25275774b10e53fb873f0b
parentb89000d3a0c5103e4605accd4d2e367fe61a3a3c (diff)
nests reduced
-rw-r--r--src/main.go48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/main.go b/src/main.go
index 9383dc5..3b7c0ce 100644
--- a/src/main.go
+++ b/src/main.go
@@ -136,32 +136,34 @@ func parse(tokens[]Token) []Operation {
op.crosslabel = fmt.Sprintf(".loop%d", looplabels[len(looplabels) - 1])
op.label = fmt.Sprintf(".done%d", looplabels[len(looplabels) - 1])
looplabels = looplabels[:len(looplabels) - 1]
- default:
- number, err := strconv.Atoi(tokens[i].str);
- if err == nil {
- op.name = "number"
- op.intData= number
- } else if tokens[i].str[0] == '"' {
- op.name = "string"
- op.strData = tokens[i].str
- op.intData = len(tokens[i].str)
+ }
+
+ number, err := strconv.Atoi(tokens[i].str);
+ if err == nil {
+ op.name = "number"
+ op.intData= number
+ } else if tokens[i].str[0] == '"' {
+ op.name = "string"
+ op.strData = tokens[i].str
+ op.intData = len(tokens[i].str)
op.label = fmt.Sprintf("string_%d", stringlabel)
- stringlabel++
- } else if len(tokens[i].str) == 9 && tokens[i].str[:8] == "syscall." {
- parameters, err := strconv.Atoi(string(tokens[i].str[8]))
- /* FIXME: Too much nested */
- if err != nil {
- panic("invalid from for syscall")
- }
- if parameters < 1 || parameters > 6 {
- panic("syscall must be called with a number between 1 and 6")
- }
- op.name = "syscall"
- op.intData = parameters
- } else {
- panic ("invalid word")
+ stringlabel++
+ } else if len(tokens[i].str) == 9 && tokens[i].str[:8] == "syscall." {
+ parameters, err := strconv.Atoi(string(tokens[i].str[8]))
+ if err != nil {
+ panic("invalid from for syscall")
}
+ if parameters < 1 || parameters > 6 {
+ panic("syscall must be called with a number between 1 and 6")
+ }
+ op.name = "syscall"
+ op.intData = parameters
+ }
+
+ if op.name == "" {
+ panic ("invalid word")
}
+
ops = append(ops, op)
}
return ops