summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/ast/ast.tnsl (renamed from tnslc/src/ast/ast.tnsl)0
-rw-r--r--tnslc/ast/node.tnsl (renamed from tnslc/src/ast/node.tnsl)0
-rw-r--r--tnslc/compile/arch/arch.tnsl (renamed from tnslc/src/compile/arch/arch.tnsl)0
-rw-r--r--tnslc/compile/arch/common.tnsl (renamed from tnslc/src/compile/arch/common.tnsl)0
-rw-r--r--tnslc/compile/arch/isa_arm.tnsl (renamed from tnslc/src/compile/arch/isa_arm.tnsl)0
-rw-r--r--tnslc/compile/arch/isa_risc_v.tnsl (renamed from tnslc/src/compile/arch/isa_risc_v.tnsl)0
-rw-r--r--tnslc/compile/arch/isa_x86.tnsl (renamed from tnslc/src/compile/arch/isa_x86.tnsl)0
-rw-r--r--tnslc/compile/compile.tnsl (renamed from tnslc/src/compile/compile.tnsl)0
-rw-r--r--tnslc/compile/format/elf.tnsl (renamed from tnslc/src/compile/format/elf.tnsl)0
-rw-r--r--tnslc/compile/format/format.tnsl (renamed from tnslc/src/compile/format/format.tnsl)0
-rw-r--r--tnslc/compile/format/iex.tnsl (renamed from tnslc/src/compile/format/iex.tnsl)0
-rw-r--r--tnslc/compile/format/out.tnsl (renamed from tnslc/src/compile/format/out.tnsl)0
-rw-r--r--tnslc/compile/format/pe.tnsl (renamed from tnslc/src/compile/format/pe.tnsl)0
-rw-r--r--tnslc/flags/flags.tnsl (renamed from tnslc/src/flags/flags.tnsl)0
-rw-r--r--tnslc/parse/parse.tnsl (renamed from tnslc/src/parse/parse.tnsl)8
-rw-r--r--tnslc/parse/token.tnsl (renamed from tnslc/src/parse/token.tnsl)84
-rw-r--r--tnslc/parse/tokenizer.tnsl53
-rw-r--r--tnslc/src/parse/tokenizer.tnsl38
-rw-r--r--tnslc/tnslc.tnsl (renamed from tnslc/src/tnslc.tnsl)27
19 files changed, 113 insertions, 97 deletions
diff --git a/tnslc/src/ast/ast.tnsl b/tnslc/ast/ast.tnsl
index 405a94a..405a94a 100644
--- a/tnslc/src/ast/ast.tnsl
+++ b/tnslc/ast/ast.tnsl
diff --git a/tnslc/src/ast/node.tnsl b/tnslc/ast/node.tnsl
index 5eeac91..5eeac91 100644
--- a/tnslc/src/ast/node.tnsl
+++ b/tnslc/ast/node.tnsl
diff --git a/tnslc/src/compile/arch/arch.tnsl b/tnslc/compile/arch/arch.tnsl
index 5e81673..5e81673 100644
--- a/tnslc/src/compile/arch/arch.tnsl
+++ b/tnslc/compile/arch/arch.tnsl
diff --git a/tnslc/src/compile/arch/common.tnsl b/tnslc/compile/arch/common.tnsl
index cba0d9f..cba0d9f 100644
--- a/tnslc/src/compile/arch/common.tnsl
+++ b/tnslc/compile/arch/common.tnsl
diff --git a/tnslc/src/compile/arch/isa_arm.tnsl b/tnslc/compile/arch/isa_arm.tnsl
index 0dc3468..0dc3468 100644
--- a/tnslc/src/compile/arch/isa_arm.tnsl
+++ b/tnslc/compile/arch/isa_arm.tnsl
diff --git a/tnslc/src/compile/arch/isa_risc_v.tnsl b/tnslc/compile/arch/isa_risc_v.tnsl
index 0dc3468..0dc3468 100644
--- a/tnslc/src/compile/arch/isa_risc_v.tnsl
+++ b/tnslc/compile/arch/isa_risc_v.tnsl
diff --git a/tnslc/src/compile/arch/isa_x86.tnsl b/tnslc/compile/arch/isa_x86.tnsl
index 0dc3468..0dc3468 100644
--- a/tnslc/src/compile/arch/isa_x86.tnsl
+++ b/tnslc/compile/arch/isa_x86.tnsl
diff --git a/tnslc/src/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index 263dc59..263dc59 100644
--- a/tnslc/src/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
diff --git a/tnslc/src/compile/format/elf.tnsl b/tnslc/compile/format/elf.tnsl
index 8490180..8490180 100644
--- a/tnslc/src/compile/format/elf.tnsl
+++ b/tnslc/compile/format/elf.tnsl
diff --git a/tnslc/src/compile/format/format.tnsl b/tnslc/compile/format/format.tnsl
index 2d4ed4b..2d4ed4b 100644
--- a/tnslc/src/compile/format/format.tnsl
+++ b/tnslc/compile/format/format.tnsl
diff --git a/tnslc/src/compile/format/iex.tnsl b/tnslc/compile/format/iex.tnsl
index e69de29..e69de29 100644
--- a/tnslc/src/compile/format/iex.tnsl
+++ b/tnslc/compile/format/iex.tnsl
diff --git a/tnslc/src/compile/format/out.tnsl b/tnslc/compile/format/out.tnsl
index e69de29..e69de29 100644
--- a/tnslc/src/compile/format/out.tnsl
+++ b/tnslc/compile/format/out.tnsl
diff --git a/tnslc/src/compile/format/pe.tnsl b/tnslc/compile/format/pe.tnsl
index e69de29..e69de29 100644
--- a/tnslc/src/compile/format/pe.tnsl
+++ b/tnslc/compile/format/pe.tnsl
diff --git a/tnslc/src/flags/flags.tnsl b/tnslc/flags/flags.tnsl
index bc5d43f..bc5d43f 100644
--- a/tnslc/src/flags/flags.tnsl
+++ b/tnslc/flags/flags.tnsl
diff --git a/tnslc/src/parse/parse.tnsl b/tnslc/parse/parse.tnsl
index e10ab4c..ec65f7b 100644
--- a/tnslc/src/parse/parse.tnsl
+++ b/tnslc/parse/parse.tnsl
@@ -14,9 +14,7 @@
EXPRESS OR IMPLIED
#/
-/; export module parse
- /:import
- "token.tnsl"
- "tokenizer.tnsl"
- :/
+/; module parse
+ :include "tnslc/parse/token.tnsl"
+ :include "tnslc/parse/tokenizer.tnsl"
;/ \ No newline at end of file
diff --git a/tnslc/src/parse/token.tnsl b/tnslc/parse/token.tnsl
index 21abe7b..0134483 100644
--- a/tnslc/src/parse/token.tnsl
+++ b/tnslc/parse/token.tnsl
@@ -15,7 +15,7 @@
#/
/# The various types of tokens #/
-; enum TOKEN_TYPE [uint] {
+; enum TOKEN_TYPE [int] {
LINESEP = 0,
INLNSEP = 1,
DELIMIT = 2,
@@ -28,8 +28,8 @@
}
/# Token struct definition #/
-;raw struct Token {
- uint
+; struct Token {
+ int
token_type,
line,
col,
@@ -45,10 +45,11 @@
;/
/; add_char (~{}charp part)
- ;uint l = len self.data`
- ;realloc self.data, l + len part
- /;loop (uint i = 0) [i++; i < len part]
- ;self.data`{l + i} = part{i}
+ # ;uint l = len self.data`
+ # ;realloc self.data, l + len part
+ /;loop (int i = 0; i < len part`) [i++]
+ # ;self.data`{l + i} = part{i}
+ ;self.data`.append(part`{i})
;/
;/
;/
@@ -58,7 +59,7 @@
helper funcs for checking their token types.
#/
-;const {}{}charp PREWORDS = {
+;{}{}charp PREWORDS = {
"include",
"define",
"extern",
@@ -95,7 +96,7 @@
"type"
}
-;const {}{}charp KEYWORDS = {
+;{}{}charp KEYWORDS = {
"struct",
"interface",
"enum",
@@ -133,20 +134,22 @@
"delete",
"module",
- "export",
+ "export"
}
-;const {}{}charp LITERALS = {
+;{}{}charp LITERALS = {
"true",
"false"
}
-;const {}charp DELIMITS = "()[]{}"
-;const {}charp LINESEPS = ";:#"
-;const {}charp INLNSEPS = ","
-;const {}charp AUGMENTS = "~`.&|^><!+-*/%"
+;{}charp RESERVED = "`~!#%^&*()-=+[]{}|;:,.<>/"
-;const {}{}charp MDELIMITS = {
+;{}charp DELIMITS = "()[]{}"
+;{}charp LINESEPS = ";:#"
+;{}charp INLNSEPS = ","
+;{}charp AUGMENTS = "~`.&|^><!+-*/%"
+
+;{}{}charp MDELIMITS = {
# Code block
"/;",
";/",
@@ -168,7 +171,7 @@
"#:"
}
-;const {}{}charp MAUGMENTS = {
+;{}{}charp MAUGMENTS = {
# Boolean
"==",
"&&",
@@ -207,16 +210,15 @@
"--"
}
-; const uint MAX_MRESERVED = 3
+;int MAX_MRESERVED = 3
/##
Checks if the character point p is in the string cmp
-#; is_in_string (const {}charp` cmp, charp p) [bool]
-
- /; loop (int i = 0; i < len cmp) [i++]
+#; is_in_string (~{}charp cmp, charp p) [bool]
- /; if (s == cmp{i})
+ /; loop (int i = 0; i < len cmp`) [i++]
+ /; if (s == cmp`{i})
;return true
;/
;/
@@ -224,27 +226,25 @@
;return false
;/
-
/##
Checks if the string s is in the list cmp
-#; is_in_string_list (const {}{}charp` cmp, {}charp` s) [bool]
+#; is_in_string_list (~{}{}charp cmp, ~{}charp s) [bool]
- /; loop (int i = 0; i < len cmp) [i++]
+ /; 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++]
+ /; loop (int j = 0; j < len s`) [j++]
- /; if (s{j} !== cmp{i}{j})
- ;goto cont_outer
+ /; if (s`{j} !== cmp`{i}{j})
+ ;break 1
;/
;/
;return true
;/
- ;label cont_outer
;/
;return false
@@ -253,35 +253,35 @@
/#
Get the token_type value for a given string of character points
-#; get_token_type ({}charp` s) [int]
+#; get_token_type (~{}charp s) [int]
/; if (len s > 1)
- /; if (is_in_string_list(~PREWORDS, ~s))
+ /; if (is_in_string_list(~PREWORDS, s))
;return TOKEN_TYPE.PREWORD
- ;; else if (is_in_string_list(~KEYTYPES, ~s))
+ ;; else if (is_in_string_list(~KEYTYPES, s))
;return TOKEN_TYPE.KEYTYPE
- ;; else if (is_in_string_list(~KEYWORDS, ~s))
+ ;; else if (is_in_string_list(~KEYWORDS, s))
;return TOKEN_TYPE.KEYWORD
- ;; else if (is_in_string_list(~LITERALS, ~s))
+ ;; else if (is_in_string_list(~LITERALS, s))
;return TOKEN_TYPE.LITERAL
- ;; else if (is_in_string_list(~MDELIMITS, ~s))
+ ;; else if (is_in_string_list(~MDELIMITS, s))
;return TOKEN_TYPE.DELIMIT
- ;; else if (is_in_string_list(~MAUGMENTS, ~s))
+ ;; else if (is_in_string_list(~MAUGMENTS, s))
;return TOKEN_TYPE.AUGMENT
;/
;return TOKEN_TYPE.DEFWORD
- ;;else if (len s == 1)
+ ;;else if (len s` == 1)
- /; if (is_in_string(~DELIMITS, s{0}))
+ /; if (is_in_string(~DELIMITS, s`{0}))
;return TOKEN_TYPE.DELIMIT
- ;; else if (is_in_string(~LINESEPS, s{0}))
+ ;; else if (is_in_string(~LINESEPS, s`{0}))
;return TOKEN_TYPE.LINESEP
- ;; else if (is_in_string(~INLNSEPS, s{0}))
+ ;; else if (is_in_string(~INLNSEPS, s`{0}))
;return TOKEN_TYPE.INLNSEP
- ;; else if (is_in_string(~AUGMENTS, s{0}))
+ ;; else if (is_in_string(~AUGMENTS, s`{0}))
;return TOKEN_TYPE.AUGMENT
;/
diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl
new file mode 100644
index 0000000..54671fe
--- /dev/null
+++ b/tnslc/parse/tokenizer.tnsl
@@ -0,0 +1,53 @@
+/#
+ Copyright 2021 Kyle Gunger
+
+ This file is licensed under the CDDL 1.0 (the License)
+ and may only be used in accordance with the License.
+ You should have received a copy of the License with this
+ software/source code. If you did not, a copy can be found
+ at the following URL:
+
+ https://opensource.org/licenses/CDDL-1.0
+
+ THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
+ WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
+ EXPRESS OR IMPLIED
+#/
+
+/; is_space (charp c) [bool]
+ ;return c == '\t' || c == '\n' || c == ' '
+;/
+
+/; break_token ({}charp dat, charp c) [bool]
+ /; if (len dat == 0)
+ ;return false
+
+ ;/
+ ;return is_space(c)
+;/
+
+/; parse_reserved ({}charp dat) [{}Token]
+
+;/
+
+/; tokenize (tnsl.io.File fstr) [~{}Token]
+ ;{}Token out = {}
+ ;{}charp tdat = {}
+
+ /; loop (int i = fstr.read(); i !== -1) [i = fstr.read()]
+ /; if (break_token(tdat, i))
+ /; if (len tdat > 0)
+ ;{}charp tmp = tdat
+ ;Token ttk = {0, 0, 0, ~tmp}
+ ;out.append(ttk)
+ ;tdat = {}
+ ;/
+ ;; else if ( !is_space(i) )
+ ;tdat.append(i)
+ ;/
+ ;/
+
+ ;tnsl.io.println(tdat)
+
+ ;return ~out
+;/
diff --git a/tnslc/src/parse/tokenizer.tnsl b/tnslc/src/parse/tokenizer.tnsl
deleted file mode 100644
index 4e5eeb7..0000000
--- a/tnslc/src/parse/tokenizer.tnsl
+++ /dev/null
@@ -1,38 +0,0 @@
-/#
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-:using 'tnsl'
-
-/##
- parse.numeric_literal tokenizes the next numeric literal value in a file.
- Returns a token with the proper data as well as the number of characters read
-
-#; numeric_literal (io.text_stream fstream) [Token, uint]
- ;Token out = {token_type: TOKEN_TYPE.LITERAL}
- ;uint counter = 0
-
- ;bool l, d, run = false, false, true
- ;~{}charp num
-
- ;num, run = fstream.read_number()
-
- /; loop (run) [num, run = fstream.read_number()]
- ;out.add_data(num)
- ;delete num
- ;/
-
- ;return out, counter
-;/ \ No newline at end of file
diff --git a/tnslc/src/tnslc.tnsl b/tnslc/tnslc.tnsl
index 212819e..99be327 100644
--- a/tnslc/src/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -15,24 +15,27 @@
#/
/; module tnslc
- :import "flags/flags.tnsl"
- :import "parse/parse.tnsl"
- :import "ast/ast.tnsl"
- :import "compile/compile.tnsl"
+ :include "tnslc/parse/parse.tnsl"
;/
-/; main (~{}{}char args) [int]
- ;tnslc.flags.Flags argList = tnslc.flags.parse(args)
+/; test
- ;{}tnslc.parse.Token tokenList = tnslc.parse.tokenize(argList)
+;/
+
+/; main ({}{}charp args) [int]
+ /; if (len args < 1)
+ ;tnsl.io.println("Usage: tnslc [File to compile] <path to libtnsl>")
+ ;return 1
+ ;/
- ;tnslc.ast.Node ast = ast.generate(tokenList)
+ ;tnsl.io.File src = tnsl.io.readFile(args{0})
- ;tnsl.io.File outFile = tnsl.io.open_file(argList.outPath)
- ;[]uint8 data = tnslc.compile.generate(argList, ast)
+ ;~{}tnslc.parse.Token psrc = tnslc.parse.tokenize(src)
- ;outFile.write(data)
+ ;tnsl.io.println(psrc`)
+
+ ;src.close()
- ;outFile.close()
+ ;return 0
;/