From 94695c20e763b780aa883c43e4724270491f7702 Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Mon, 28 Jul 2025 22:40:06 +0800 Subject: [PATCH] initial commit --- Project.toml | 4 ++++ src/TComp.jl | 7 ++++++ src/parser.jl | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 Project.toml create mode 100644 src/TComp.jl create mode 100644 src/parser.jl diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..c314b2c --- /dev/null +++ b/Project.toml @@ -0,0 +1,4 @@ +name = "TComp" +uuid = "b858fc1c-1812-4b3c-a2e6-a1a64b2d44f1" +authors = ["Tan Kian-ting "] +version = "0.1.0" diff --git a/src/TComp.jl b/src/TComp.jl new file mode 100644 index 0000000..6845b58 --- /dev/null +++ b/src/TComp.jl @@ -0,0 +1,7 @@ +module TComp +include("./parser.jl") +using .Parser + +greet() = print("Hello World!") + +end # module diff --git a/src/parser.jl b/src/parser.jl new file mode 100644 index 0000000..537585a --- /dev/null +++ b/src/parser.jl @@ -0,0 +1,64 @@ +module Parser + +patternList = [("int", "\\d+"), + ("id", "[_a-zA-Z][_0-9a-zA-Z]*"), + ("l_paren", "[\\(]"), + ("r_paren", "[\\)]"), + ("plus", "[+]"), + ("minus", "[\\-]"), + ("mul", "[\\*]"), + ("div", "[\\\\]"), + ("sp", "\\s+"), + ("comma", "[,]"), + ("amp", "[&]"), + ("assign", "[=]"), + ("lambda", "[=][>]"), + ] + +function combineUnit(tup) + retString = "(?P<" * tup[1] * ">" * tup[2] * ")" + #retStringRegex = Regex(retString) + return retString +end + +tmp = join(map(combineUnit, patternList), "|") +matchEachItem = Regex(tmp) + +matchAll = "^(" * tmp * ")+\$" +matchEntirely = Regex(matchAll) + +print(matchEntirely) + + +inp = "123 + 345 - 456 * a ^^^" + +print("~~~\n") +isEntirelyMatched = match(matchEntirely, inp) + +if isEntirelyMatched == false + print("illegal tokens contained.") + +end + + + +mI = eachmatch(matchEachItem, inp) + +function processKeys(x) + keys_ = keys(x) + return filter((i) -> x[i] != nothing, keys_)[1] +end + +matchedList = map((x)->x.match, collect(mI)) + +groupNameList = map(processKeys, collect(mI)) + +list1 = [1, 2, 3] +list2 = ["a", "b", "c"] + +zippedTokenList = collect(zip(matchedList, groupNameList)) + +print(zippedTokenList) + +end +