diff --git a/code.txt b/code.txt old mode 100644 new mode 100755 index a7c109e..07d050c --- a/code.txt +++ b/code.txt @@ -1,3 +1,4 @@ +#!./main.py BeginNote This is a comment and should be ignored by the parser EndNote diff --git a/main.py b/main.py old mode 100644 new mode 100755 index a610798..000f6b6 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # SPDX-License-Identifier: MIT # Copyright 2021 Jookia @@ -30,8 +31,17 @@ text += symbol return tokens -testcode = open("code.txt").read() -tokens = tokenizer(testcode) +def main(args): + if len(args) != 2: + print("Usage: main.py FILENAME") + return 1 + filename = args[1] + testcode = open(filename).read() + tokens = tokenizer(testcode) + for t in tokens: + print("TOKEN {0}: {1}".format(t[0], t[1])) + return 0 -for t in tokens: - print("TOKEN {0}: {1}".format(t[0], t[1])) +if __name__ == "__main__": + import sys + sys.exit(main(sys.argv))