commit 651c7451d176d15fba1652902a144c902ffad1f1 Author: Marvin Blum Date: Mon Sep 21 13:26:17 2015 +0200 Init, basic tokenizer setup. diff --git a/.project b/.project new file mode 100644 index 0000000..70e02e7 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + asl + + + + + + com.googlecode.goclipse.goBuilder + + + + + + com.googlecode.goclipse.core.goNature + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..8eb4ed7 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# ASL + +ASL stands for Arma Scripting Language, which is a language compiled to SQF. +This scripting language tries to simplify Arma mod development and eliminate the pain of bad syntax using SQF. + +## Syntax + +``` +... +``` diff --git a/bin/asl b/bin/asl new file mode 100755 index 0000000..556b29c Binary files /dev/null and b/bin/asl differ diff --git a/bin/main b/bin/main new file mode 100755 index 0000000..48d6cca Binary files /dev/null and b/bin/main differ diff --git a/in/simple.asl b/in/simple.asl new file mode 100644 index 0000000..084b82e --- /dev/null +++ b/in/simple.asl @@ -0,0 +1,2 @@ +var a = 1; +var b = 2; diff --git a/pkg/linux_amd64/asl.a b/pkg/linux_amd64/asl.a new file mode 100644 index 0000000..e41b4a0 Binary files /dev/null and b/pkg/linux_amd64/asl.a differ diff --git a/src/asl/parser.go b/src/asl/parser.go new file mode 100644 index 0000000..b9e061d --- /dev/null +++ b/src/asl/parser.go @@ -0,0 +1,7 @@ +package asl + +import ( + +) + + diff --git a/src/asl/tokenizer.go b/src/asl/tokenizer.go new file mode 100644 index 0000000..73fa91c --- /dev/null +++ b/src/asl/tokenizer.go @@ -0,0 +1,60 @@ +package asl + +import ( + "fmt" +) + +type Token struct{ + token string +} + +var delimiter = []byte{'=', ';'} +var keywords = []string{"var"} +var whitespace = []byte{' ', '\n', '\t'} + +func Tokenize(code []byte) []Token { + tokens := make([]Token, 0) + token := "" + + for i := range code { + c := code[i] + + if byteArrayContains(delimiter, c) { + tokens = append(tokens, Token{token}) + tokens = append(tokens, Token{string(c)}) + token = "" + } else if stringArrayContains(keywords, token) { + tokens = append(tokens, Token{token}) + token = "" + } else if !byteArrayContains(whitespace, c) { + token += string(c) + } + } + + // TEST + for i := range tokens { + fmt.Println(tokens[i].token) + } + + return tokens +} + +func byteArrayContains(haystack []byte, needle byte) bool { + for i := range haystack { + if haystack[i] == needle { + return true; + } + } + + return false +} + +func stringArrayContains(haystack []string, needle string) bool { + for i := range haystack { + if haystack[i] == needle { + return true; + } + } + + return false +} diff --git a/src/main/asl.go b/src/main/asl.go new file mode 100644 index 0000000..5398f5a --- /dev/null +++ b/src/main/asl.go @@ -0,0 +1,12 @@ +package main + +import ( + "io/ioutil" + "asl" +) + +func main(){ + // read test file + code, _ := ioutil.ReadFile("in/simple.asl") + asl.Tokenize(code) +}