diff options
-rw-r--r-- | tnslc/ast/ast.tnsl | 4 | ||||
-rw-r--r-- | tnslc/ast/node.tnsl | 61 | ||||
-rw-r--r-- | tnslc/dummy.tnsl | 1 | ||||
-rw-r--r-- | tnslc/parse/parse.tnsl | 10 | ||||
-rw-r--r-- | tnslc/parse/token.tnsl | 16 | ||||
-rw-r--r-- | tnslc/tnslc.tnsl | 1 |
6 files changed, 22 insertions, 71 deletions
diff --git a/tnslc/ast/ast.tnsl b/tnslc/ast/ast.tnsl index 405a94a..466fe08 100644 --- a/tnslc/ast/ast.tnsl +++ b/tnslc/ast/ast.tnsl @@ -15,5 +15,5 @@ #/ /; export module ast - :import "node.tnsl" -;/
\ No newline at end of file + :include "ast/node.tnsl" +;/ diff --git a/tnslc/ast/node.tnsl b/tnslc/ast/node.tnsl index 5eeac91..d1db325 100644 --- a/tnslc/ast/node.tnsl +++ b/tnslc/ast/node.tnsl @@ -18,68 +18,9 @@ ;struct Node { tnslc.parse.Token # associated token to the node - data, + tok, ~{}Node # sub-nodes sub } - -# AST node (block) -;struct BlockNode extends Node { - super, - - ~{}Node - # block inputs and outputs - blockIn, - blockOut, - - ~{}tnslc.parse.Token - # block qualifiers - blockQs -} - -# Node methods -/; method Node - - /; operator delete - ;delete this.data, this.sub - ;/ - - /; push_sub (Node node) [uint] - ;uint len = this.sub.length - ;alloc this.sub, len + 1 - ;this.sub{len} = node - ;return len + 1 - ;/ -;/ - -# Extended block node methods -/; method BlockNode - - /; operator delete - ;super() - ;delete this.blockQs, this.blockIn, this.blockOut - ;/ - - /; push_blockQ (tnslc.parse.Token token) [uint] - ;uint len = this.blockQs.length - ;alloc this.blockQs, len + 1 - ;this.blockQs{len} = token - ;return len + 1 - ;/ - - /; push_blockIn (Node node) [uint] - ;uint len = this.blockIn.length - ;alloc this.blockIn, len + 1 - ;this.blockIn{len} = node - ;return len + 1 - ;/ - - /; push_blockOut (Node node) [uint] - ;uint len = this.blockOut.length - ;alloc this.blockOut, len + 1 - ;this.blockOut{len} = node - ;return len + 1 - ;/ -;/
\ No newline at end of file diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl index bb09483..edecab5 100644 --- a/tnslc/dummy.tnsl +++ b/tnslc/dummy.tnsl @@ -1,3 +1,4 @@ /; main [float] + ;int i = 0 ;return a.b ;/ diff --git a/tnslc/parse/parse.tnsl b/tnslc/parse/parse.tnsl index 52fd0c7..5d3bfa5 100644 --- a/tnslc/parse/parse.tnsl +++ b/tnslc/parse/parse.tnsl @@ -21,15 +21,7 @@ /; 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(dat`{i}.line) - ;tnsl.io.print(" ") - ;tnsl.io.print(dat`{i}.col) - ;tnsl.io.print(" } ") + ;dat`{i}.print() ;/ ;tnsl.io.print("\n") ;/ diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl index 6c402fd..e18ade5 100644 --- a/tnslc/parse/token.tnsl +++ b/tnslc/parse/token.tnsl @@ -40,6 +40,18 @@ /; method Token + /; print + ;tnsl.io.print("{ ") + ;tnsl.io.print(self.token_type) + ;tnsl.io.print(" ") + ;tnsl.io.print(self.data`) + ;tnsl.io.print(" ") + ;tnsl.io.print(self.line) + ;tnsl.io.print(" ") + ;tnsl.io.print(self.col) + ;tnsl.io.print(" } ") + ;/ + /; operator delete ;delete self.data ;/ @@ -310,6 +322,10 @@ ;return TOKEN_TYPE.DEFWORD ;;else if (len s` == 1) + + /; if (is_digit(s`{0})) + ;return TOKEN_TYPE.LITERAL + ;/ /; if (is_in_string(~DELIMITS, s`{0})) ;return TOKEN_TYPE.DELIMIT diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl index 90a1020..d8adc24 100644 --- a/tnslc/tnslc.tnsl +++ b/tnslc/tnslc.tnsl @@ -18,6 +18,7 @@ /; module tnslc :include "parse/parse.tnsl" + :include "ast/ast.tnsl" ;/ |