-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher.py
59 lines (42 loc) · 1.17 KB
/
watcher.py
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
51
52
53
54
55
56
57
58
59
# The module for system-specific parameters and functions
import sys
# Import SymbolTable class
from symbol_table_class import SymbolTable
# Import scanner
from pulse_scanner import scanner
def readFile(path):
"""
Reads a file and returns the contents as a string
Params
======
path (string) : Path to file which is to be read
Returns
=======
buffer (string) : Contents of the file
"""
try:
# open the file in read mode
file = open(path, "r")
except:
# if file cannot be opened
sys.stderr.write("Could not open %s" % (path))
exit(74)
# reading the file
if file.mode == "r":
buffer = file.read()
# Add a EOF token to end of source code
buffer += "\0"
file.close()
return buffer
# Read file path from command line
file_path = sys.argv[1]
# Get the source code form code file
source_code = readFile(file_path)
# Create symbol table
table = SymbolTable()
# Pass source code to lexical analyzer
tokens = scanner(source_code, table)
for token in tokens:
print(token)
# TODO: Pass tokens into parser and compiler
# TODO: Pass bytecode into VM for execution