-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: undeclared identifier: 'TK_UNKNOWN' #1
Comments
Thanks! Just updated the README. Call settings proc before static:
Program.settings(
uppercase = true,
prefix = "Tk_"
) For more inspiration you can check Tim Engine https://github.com/openpeep/tim |
There also seems to be an error with adding values. I added "LColon" and "RColon" into the token list: tokens:
Plus > '+'
Minus > '-'
Multi > '*'
Div > '/'
LCol > '('
RCol > ')' However, when it outputs values: it doesn't recognize it.
The file contents are:
|
Seems fine to me, you have If you're talking about the empty |
Ah I didn't notice the "pos" / .col syntax. In that case, it works perfectly! |
Is there a Program.settings for removing whitespace? |
No. Whitespaces are counted and stored in |
Not added in docs, but here is how you can handle 2 or more characters for multiple use cases So for example tokens:
GT > '>':
GTE ? '='
LT > '<':
LTE ? '='
# string based tokens TK_AT, TK_INCLUDE and TK_MIXIN
At > '@':
Include ? "include"
Mixin ? "mixin" |
I mean if I had: echo "Test"
echo "Test2" How do you seperate multi-line when it doesn't even tokenize NEWLINE ("\n") |
There is no need for tokenizing new lines or whitespaces. Imagine how many useless tokens would be. So based on your example will be (kind: TK_ECHO, value: "echo", wsno: 0, line: 1, col: 0, pos: 0)
(kind: TK_STRING, value: "Test", wsno: 1, line: 1, col: 5, pos: 5)
(kind: TK_ECHO, value: "echo", wsno: 0, line: 2, col: 0, pos: 0)
(kind: TK_STRING, value: "Test", wsno: 1, line: 2, col: 5, pos: 5) |
Anything else should be implemented at Parser level and AST |
That is smart but there is the challenge of telling the code that "This is a new line." |
edit: My man you truly have won the internet. |
Haha. Glad you like this! There are still many things to do. And this would be a minimal parser for your toktok type
Parser* = object
lex: Lexer
prev, current, next: TokenTuple
error: string
proc setError(p: var Parser, msg: string) =
## Set parser error
p.error = "Error ($2:$3): $1" % [msg, $p.current.line, $p.current.pos]
proc walk(p: var Parser, offset = 1) =
var i = 0
while offset != i:
p.prev = p.current
p.current = p.next
p.next = p.lex.getToken()
inc i
var p = Parser(lex: Lexer.init(fileContents = readFile("sample.txt")))
p.current = p.lex.getToken()
p.next = p.lex.getToken()
while p.current.kind != TK_EOF and p.error.len == 0:
case p.current.kind:
of TK_LET, TK_VAR, TK_CONST:
let this = p.current
if p.next.kind == TK_IDENTIFIER:
discard # handle var declaration
else:
p.setError("Invalid variable declaration expect identifier")
break
of TK_PLUS, TK_MINUS, TK_MULTI, TK_DIV:
discard # handle math
else: discard # and so on
walk(p) # walk to next token
if p.error.len != 0:
echo p.error |
There also seems to be an error with the comment. When I put:
I get:
However, the "#" seems to work perfectly.
|
Yep. That does not work right now. I hope will be fixed soon |
Ok, now this should work. Reinstall your toktok package. tokens:
Div > '/':
BlockComment ? '*' .. "*/" # everything starting from /* to */ (tail should be a string)
InlineComment ? '/' .. EOL # everything starting from // to EOL (end of line) This is work in progress (markdown use case) tokens:
H1 > '#' .. EOL:
H2 ? '#' .. EOL
H3 ? '#' .. EOL |
Signed-off-by: George Lemon <georgelemon@protonmail.com>
The reason why I was asking was because I am having trouble on trying to design a truly functioning if statement / white statement. The tokenizer needs to have some form of indicator of which part of the code is INSIDE another part of the code.
The {} can be used but in a situation where we put 2 If statements inside another, that becomes complicated. That's why I asked if there was a way to strip whitespace or merge lines similiar to: |
This is a generic lexer, that's why you should write this kind of logic at parser level. By the way, instead of tables, I recommend you implement AST nodes using Nim objects. I made a functional Parser + AST nodes, based on current toktok Lexer that does what you need. You can start from this.
will produce the following ast {
"nodes": [
{
"nodeName": "NTCondition",
"nodeType": 3,
"ifCond": {
"nodeName": "NTInfix",
"nodeType": 6,
"infixOp": 1,
"infixLeft": {
"nodeName": "NTInt",
"nodeType": 0,
"intVal": 2
},
"infixOpSymbol": "EQ",
"infixRight": {
"nodeName": "NTInt",
"nodeType": 0,
"intVal": 2
}
},
"ifBody": {
"nodeName": "NTStmtList",
"nodeType": 7,
"stmtList": [
{
"nodeName": "NTBlockComment",
"nodeType": 5,
"comment": " something cool "
}
]
},
"elseBody": null,
"elifBranch": []
}
]
} While this can't be valid
so will throw an error
Pretty simple |
Oh damn that's beautiful. I started working on a side-project programming lang called "Barcelona" that was suppose to make database/statistics/requests data much easier and straight to the point. I am going to be having a 6-week college break so I plan to severally work on Barcelona but I am new to understanding how a program. language works. Any advice would be appreciated. |
Nim is a good start. Also thanks for trying toktok. Hobby projects are awesome. Maybe you don't have to write a micro language, you have Nim macros! Also, check Computer Programming with the Nim Programming Language |
Nim is an interesting language, I started learning a few days ago and it looks pretty good. I love how it's a mixture of Python's Simplicity, C's Performance and Lisp's flexibility. In addition to the fact that you can compile code to C, C++, Obj C is really cool. (also JS) The only problem I am having is trying to make a function CERTAIN elements in a list. Also Windows Defender seems to find it as a virus after version 1.4.0 (idk why). Cool and unique language to learn. |
Regarding Windows Defender, that's a false positive. nim-lang/Nim#17820. Report as a false positive, if is possible. You mean something like this? var a = @["bread", "cake", "tomorrow"]
echo a[1 .. ^1] # output @["cake", "tomorrow"]
echo a[2 .. ^1] # output @["tomorrow"] Bookmark this String Functions: Nim vs Python. Most of these examples work with |
Ah that would make a lot of sense tbh. I recall there was a time where you can trigger people's windows defenders via discord just by sending pictures / videos.
Something like that! Thank you! |
Update it appears the error is being created because I am importing std/strutils from the 2nd file (not the main file) |
Do you think you can add the token for float numbers? The token for: Would be: |
Thanks for that! Update your local toktok |
Another suggestion I would offer is the idea of multi-threading. Do you think it would be possible for it to be implemented? |
try use toktok in a separate file, let's say "tokens.nim", there you will define your tokens. Then import
import toktok
tokens:
# here
import ./tokens |
I get these errors when just running the default sample code
The text was updated successfully, but these errors were encountered: