mirror of
https://github.com/Open-Argon/argon-v2.git
synced 2026-10-28 09:44:03 +00:00
add ifs
This commit is contained in:
1 parent
da3d680c1a
commit
1827f8635e
9 files changed
+139
-35
No files matched your search
@@ -27,5 +27,9 @@ func makeRegex(str string) *regexp.Regexp {
|
||||
}
|
||||
|
||||
func main() {
|
||||
importMod(os.Args[1])
|
||||
if len(os.Args) == 1 {
|
||||
shell()
|
||||
} else {
|
||||
importMod(os.Args[1])
|
||||
}
|
||||
}
|
||||
@@ -185,3 +185,6 @@ Run a file:
|
||||
Run the shell:
|
||||
|
||||
- run the Argon executable without any parameters, (e.g. `$ argon`)
|
||||
|
||||
# License
|
||||
MIT License
|
||||
+50
-1
@@ -1,6 +1,11 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ArgonLog(x ...any) any {
|
||||
output := []any{}
|
||||
@@ -14,3 +19,47 @@ func ArgonLog(x ...any) any {
|
||||
func ArgonNumber(x ...any) any {
|
||||
return (number(x[0]))
|
||||
}
|
||||
|
||||
func ArgonString(x ...any) any {
|
||||
return (anyToArgon(x[0]))
|
||||
}
|
||||
|
||||
func ArgonWhole(x ...any) any {
|
||||
return (math.Floor(number(x[0])))
|
||||
}
|
||||
|
||||
func ArgonInput(x ...any) any {
|
||||
fmt.Print(x[0])
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Scan()
|
||||
line := scanner.Text()
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Println("Error encountered:", err)
|
||||
}
|
||||
return (line)
|
||||
}
|
||||
|
||||
func ArgonLicense(...any) any {
|
||||
fmt.Println(`MIT License
|
||||
|
||||
Copyright (c) 2022 William Bell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.`)
|
||||
return nil
|
||||
}
|
||||
+6
-9
@@ -1,10 +1,7 @@
|
||||
if yes [
|
||||
log("cool")
|
||||
const name = input('name: ')
|
||||
const age = whole(input('age: '))
|
||||
if (age < 18) [
|
||||
log('hello, '+name+'! you are '+age+' years old. You too young to vote!')
|
||||
] else [
|
||||
]
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('hello, '+name+'! you are '+age+' years old. You can vote!')
|
||||
]
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -20,7 +19,6 @@ func importMod(path string) {
|
||||
}
|
||||
exPath := filepath.Dir(ex)
|
||||
path = filepath.Join(exPath, path)
|
||||
fmt.Println(path)
|
||||
if xiny(path, imported) {
|
||||
return
|
||||
}
|
||||
@@ -29,6 +27,9 @@ func importMod(path string) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
script := translate(string(data))
|
||||
run(script)
|
||||
runStr(string(data))
|
||||
}
|
||||
|
||||
func runStr(str string) {
|
||||
run(translate(str))
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -35,6 +36,8 @@ func anyToArgon(x any) string {
|
||||
}
|
||||
case nil:
|
||||
return "unknown"
|
||||
case variable:
|
||||
return x.(variable).variable
|
||||
default:
|
||||
return fmt.Sprint(x)
|
||||
}
|
||||
@@ -47,7 +50,11 @@ func runprocess(codeseg any) any {
|
||||
case variable:
|
||||
myvar := vars[codeseg.(variable).variable]
|
||||
if myvar.EXISTS != nil {
|
||||
return myvar.VAL
|
||||
if myvar.TYPE != "func" && myvar.TYPE != "init_function" {
|
||||
return myvar.VAL
|
||||
} else {
|
||||
return codeseg
|
||||
}
|
||||
}
|
||||
log.Fatal("undecared variable " + codeseg.(variable).variable + " on line " + fmt.Sprint(codeseg.(variable).line+1))
|
||||
case funcCallType:
|
||||
@@ -74,28 +81,35 @@ func runprocess(codeseg any) any {
|
||||
|
||||
func callFunc(call funcCallType) any {
|
||||
if vars[call.name].EXISTS == nil {
|
||||
log.Fatal("undecared function on line " + fmt.Sprint(call.line+1))
|
||||
} else if vars[call.name].TYPE != "func" && vars[call.name].TYPE != "init" {
|
||||
log.Fatal("cannot call " + vars[call.name].TYPE + " on line " + fmt.Sprint(call.line+1))
|
||||
} else if vars[call.name].FUNC == false {
|
||||
log.Fatal(call.name + " is not a function on line " + fmt.Sprint(call.line+1))
|
||||
log.Fatal("undecared function '" + call.name + "' on line " + fmt.Sprint(call.line+1))
|
||||
}
|
||||
callable := call
|
||||
for vars[callable.name].TYPE != "func" && vars[callable.name].TYPE != "init_function" && fmt.Sprint(reflect.TypeOf(vars[callable.name].VAL)) == "main.variable" {
|
||||
callable = funcCallType{name: vars[callable.name].VAL.(variable).variable, args: callable.args, line: callable.line}
|
||||
}
|
||||
if vars[callable.name].TYPE != "func" && vars[callable.name].TYPE != "init_function" {
|
||||
log.Fatal("'" + call.name + "' is not a function on line " + fmt.Sprint(call.line+1))
|
||||
}
|
||||
|
||||
argvals := []any{}
|
||||
for i := 0; i < len(call.args); i++ {
|
||||
argvals = append(argvals, runprocess(call.args[i]))
|
||||
for i := 0; i < len(callable.args); i++ {
|
||||
argvals = append(argvals, runprocess(callable.args[i]))
|
||||
}
|
||||
return vars[call.name].VAL.(func(...any) any)(argvals...)
|
||||
|
||||
return vars[callable.name].VAL.(func(...any) any)(argvals...)
|
||||
}
|
||||
|
||||
func setVariableVal(x setVariable) {
|
||||
variable := vars[x.variable]
|
||||
if variable.EXISTS == nil || variable.TYPE == "var" {
|
||||
if variable.EXISTS == nil {
|
||||
vars[x.variable] = variableValue{
|
||||
TYPE: x.TYPE,
|
||||
EXISTS: true,
|
||||
VAL: runop(x.value),
|
||||
FUNC: false,
|
||||
}
|
||||
} else if variable.TYPE == "var" {
|
||||
variable.VAL = runop(x.value)
|
||||
} else {
|
||||
log.Fatal("cannot edit " + variable.TYPE + " variable on line " + fmt.Sprint(x.line+1))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func shell() {
|
||||
fmt.Println("Argon Shell\nMIT License\n\nCopyright (c) 2022 William Bell\ncall 'license' for license information\n ")
|
||||
for {
|
||||
runStr(ArgonInput("> ").(string))
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
var anyAndNewline = "((.)|(\\n))"
|
||||
var variableOnly = "([a-zA-Z_])([a-zA-Z0-9_])*"
|
||||
var stringCompile = makeRegex("(( *)\"((\\\\([a-z\\\"'`]))|[^\\\"])*\"( *)))|((( *)'((\\\\([a-z\\'\"`]))|[^\\'])*'( *))|(( *)(`(\\\\[a-z\\\"'`\\n]|[^\\`])*`)( *))")
|
||||
var stringCompile = makeRegex("(( *)\"((\\\\([a-z\\\"'`]))|[^\\\"])*\"( *))|(( *)'((\\\\([a-z\\'\"`]))|[^\\'])*'( *))|(( *)(`(\\\\[a-z\\\"'`\\n]|[^\\`])*`)( *))")
|
||||
var numberCompile = makeRegex("( *)(\\-)?(([0-9]+(\\.[0-9]+)?)(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
|
||||
var whileCompile = makeRegex("( *)(while " + anyAndNewline + "+ \\[.*)( *)")
|
||||
var subCompile = makeRegex("( *)(sub " + variableOnly + "\\(" + anyAndNewline + "+\\) \\[.*)( *)")
|
||||
@@ -131,11 +131,13 @@ func getValuesFromCommas(str string, line int) ([]any, bool) {
|
||||
temp = append(temp, str[i])
|
||||
}
|
||||
tempstr := string(temp[:])
|
||||
resp, worked := processfunc(code{code: tempstr, line: 0})
|
||||
if worked {
|
||||
output = append(output, resp)
|
||||
} else {
|
||||
return nil, false
|
||||
if tempstr != "" {
|
||||
resp, worked := processfunc(code{code: tempstr, line: 0})
|
||||
if worked {
|
||||
output = append(output, resp)
|
||||
} else {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
return output, true
|
||||
}
|
||||
|
||||
+28
-4
@@ -11,15 +11,15 @@ var vars = make(map[string]variableValue)
|
||||
|
||||
func init() {
|
||||
vars["log"] = variableValue{
|
||||
TYPE: "init",
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonLog,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["number"] = variableValue{
|
||||
TYPE: "init",
|
||||
vars["input"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonNumber,
|
||||
VAL: ArgonInput,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["yes"] = variableValue{
|
||||
@@ -40,4 +40,28 @@ func init() {
|
||||
VAL: nil,
|
||||
FUNC: false,
|
||||
}
|
||||
vars["number"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonNumber,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["whole"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonWhole,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["string"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonString,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["license"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonLicense,
|
||||
FUNC: true,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user