-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
50 lines (47 loc) · 1.36 KB
/
main.lua
File metadata and controls
50 lines (47 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local token = require("token")
local lexer = require("lexer")
lexer.input = "struct Node {\n"
.. "\tdata: int;"
.. "\tleft: *Node;"
.. "\tright: *Node;"
.. "}\n"
.. "fn add_nums(x: int, y: int) int {\n"
.. " return x + y;\n"
.. "}\n"
.. "\n"
.. "// check if str starts with an h\n"
.. "fn starts_with_h(s: str) bool {\n"
.. " return s[0] == 'H';\n"
.. "}\n"
.. "\n"
.. "fn printNum(n: int|f32) void {\n"
.. " print(n);\n"
.. "}\n"
.. "let rootNode = Node{5, nil, nil};\n"
.. "print(rootNode.data);\n"
.. "\n"
.. "const ten: int = 5 + 5 * 4 / 2 - 5;\n"
.. "const newNum = add_nums(ten, 25);\n"
.. "const isTen = ten == 10 ? true : false;\n"
.. "const nothing = nil;\n"
.. "\n"
.. 'let mystring: str = "Hello, Lexer!";\n'
.. "for ch: str in mystring {\n"
.. " print(ch); // a comment here!\n"
.. "}\n"
.. "\n"
.. "const myfloat: f32 = 69.420;\n"
.. "\n"
.. "let counter = 0; \n"
.. "let otherCounter = 20; \n"
.. "\n"
.. "while counter < 10 or otherCounter > 10 {\n"
.. " otherCounter -= 1;\n"
.. " counter++;\n"
.. "}"
lexer:readChar()
local tok = lexer:nextToken()
while tok.type ~= token.TokenType.EOF do
print('Token{ literal: "' .. tok.literal .. '" type: ' .. tok.type .. " }")
tok = lexer:nextToken()
end