summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tnslc/README.md8
-rw-r--r--tnslc/dummy.tnsl3
-rw-r--r--tnslc/parse/parse.tnsl17
-rw-r--r--tnslc/parse/token.tnsl6
-rw-r--r--tnslc/parse/tokenizer.tnsl20
-rwxr-xr-xtnslc/run.sh5
-rw-r--r--tnslc/tnslc.tnsl6
7 files changed, 54 insertions, 11 deletions
diff --git a/tnslc/README.md b/tnslc/README.md
index d09edc9..fa19eb6 100644
--- a/tnslc/README.md
+++ b/tnslc/README.md
@@ -2,6 +2,14 @@
The reference compiler for the TNSL programming language. The compiler is written in TNSL.
+## Usage:
+
+Place the interpreter `tint` in the parent folder and execute `run.sh` with the argument being the flags for the compiler.
+
+Examples:
+- `./run.sh dummy.tnsl` - Run the compiler on the dummy file
+- `./run.sh "dummy.tnsl ../libtnsl/libtnsl.tnsl"` - Run the compiler on the dummy file but also link libtnsl
+
### Credits
Copyright 2021 Kyle Gunger
diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl
new file mode 100644
index 0000000..da9003a
--- /dev/null
+++ b/tnslc/dummy.tnsl
@@ -0,0 +1,3 @@
+/; main [float]
+ ;return .342
+;/
diff --git a/tnslc/parse/parse.tnsl b/tnslc/parse/parse.tnsl
index ec65f7b..4983e13 100644
--- a/tnslc/parse/parse.tnsl
+++ b/tnslc/parse/parse.tnsl
@@ -15,6 +15,17 @@
#/
/; module parse
- :include "tnslc/parse/token.tnsl"
- :include "tnslc/parse/tokenizer.tnsl"
-;/ \ No newline at end of file
+ :include "parse/token.tnsl"
+ :include "parse/tokenizer.tnsl"
+;/
+
+/; print_tokens(~{}parse.Token dat)
+ /;loop (int i = 0; i < len dat`) [i++]
+ ;tnsl.io.print("{ ")
+ ;tnsl.io.print(dat`{i}.token_type)
+ ;tnsl.io.print(" ")
+ ;tnsl.io.print(dat`{i}.data`)
+ ;tnsl.io.print(" } ")
+ ;/
+ ;tnsl.io.print("\n")
+;/
diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl
index 0134483..668312b 100644
--- a/tnslc/parse/token.tnsl
+++ b/tnslc/parse/token.tnsl
@@ -218,7 +218,7 @@
#; is_in_string (~{}charp cmp, charp p) [bool]
/; loop (int i = 0; i < len cmp`) [i++]
- /; if (s == cmp`{i})
+ /; if (p == cmp`{i})
;return true
;/
;/
@@ -233,7 +233,7 @@
/; loop (int i = 0; i < len cmp`) [i++]
- /; if (len s == len cmp`{i})
+ /; if (len s` == len cmp`{i})
/; loop (int j = 0; j < len s`) [j++]
@@ -255,7 +255,7 @@
#; get_token_type (~{}charp s) [int]
- /; if (len s > 1)
+ /; if (len s` > 1)
/; if (is_in_string_list(~PREWORDS, s))
;return TOKEN_TYPE.PREWORD
diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl
index 54671fe..0b80a15 100644
--- a/tnslc/parse/tokenizer.tnsl
+++ b/tnslc/parse/tokenizer.tnsl
@@ -18,10 +18,22 @@
;return c == '\t' || c == '\n' || c == ' '
;/
+/; is_digit (charp c) [bool]
+ ;return c !< '0' && c !> '9'
+;/
+
/; break_token ({}charp dat, charp c) [bool]
/; if (len dat == 0)
;return false
+ ;; else if (is_in_string(~RESERVED, dat{len dat - 1}))
+ /; if (is_in_string(~RESERVED, c))
+ ;dat.append(c)
+ ;return get_token_type(~dat) == TOKEN_TYPE.DEFWORD
+ ;; else if (len dat == 1 && dat{0} == '.')
+ ;return !is_digit(c)
+ ;/
+ ;return true
;/
;return is_space(c)
;/
@@ -38,15 +50,19 @@
/; if (break_token(tdat, i))
/; if (len tdat > 0)
;{}charp tmp = tdat
- ;Token ttk = {0, 0, 0, ~tmp}
+ ;Token ttk = {get_token_type(~tmp), 0, 0, ~tmp}
;out.append(ttk)
;tdat = {}
;/
- ;; else if ( !is_space(i) )
+ ;/
+ /; if ( !is_space(i) )
;tdat.append(i)
;/
;/
+ /; if (len tdat > 0)
+ ;/
+
;tnsl.io.println(tdat)
;return ~out
diff --git a/tnslc/run.sh b/tnslc/run.sh
new file mode 100755
index 0000000..982ebf7
--- /dev/null
+++ b/tnslc/run.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+echo $1
+
+../tint -in tnslc.tnsl -flags "$1"
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 99be327..b1c4b0a 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -15,7 +15,7 @@
#/
/; module tnslc
- :include "tnslc/parse/parse.tnsl"
+ :include "parse/parse.tnsl"
;/
@@ -25,7 +25,7 @@
/; main ({}{}charp args) [int]
/; if (len args < 1)
- ;tnsl.io.println("Usage: tnslc [File to compile] <path to libtnsl>")
+ # ;tnsl.io.println("Usage: tnslc [File to compile] <path to libtnsl>")
;return 1
;/
@@ -33,7 +33,7 @@
;~{}tnslc.parse.Token psrc = tnslc.parse.tokenize(src)
- ;tnsl.io.println(psrc`)
+ ;tnslc.print_tokens(psrc)
;src.close()