initial commit
This commit is contained in:
commit
94695c20e7
3 changed files with 75 additions and 0 deletions
4
Project.toml
Normal file
4
Project.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "TComp"
|
||||||
|
uuid = "b858fc1c-1812-4b3c-a2e6-a1a64b2d44f1"
|
||||||
|
authors = ["Tan Kian-ting <chenjt30@gmail.com>"]
|
||||||
|
version = "0.1.0"
|
7
src/TComp.jl
Normal file
7
src/TComp.jl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module TComp
|
||||||
|
include("./parser.jl")
|
||||||
|
using .Parser
|
||||||
|
|
||||||
|
greet() = print("Hello World!")
|
||||||
|
|
||||||
|
end # module
|
64
src/parser.jl
Normal file
64
src/parser.jl
Normal file
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue