Pascal Grammar Tokenizer is a simple python program that reads a pascal file and generate two files.
- token_list.csv
- symboltable.csv
1. python3 project.py (Run project.py)
Note: ensure all python files and .pas file are in the same directory
def main():
with open("pascalCode.pas", "r", encoding='utf-8') as fileReader:
for line_number, line in enumerate(fileReader):
lp = Processor.LineProcessor(line_number + 1, line)
lp.process()
print("token_list.csv File Generated")
print("symboltable.csv File Genearated")
- project.py reads the pascal file
- for each line it creates an object of LineProcessor
- and then calls its process method.
- LineProcessor process method does the following
def process(self):
idx = 0
position = 0
while idx < len(self.line):
position += 1
if self.line[idx] == '"':
processor = StringProcessor(self.line[idx + 1:], self.line_number, idx + 1)
elif self.line[idx].isdigit():
processor = NumberProcessor(self.line[idx:], self.line_number, idx + 1)
elif self.line[idx] in sym:
processor = SymbolProcessor(self.line[idx:], self.line_number, idx + 1)
elif self.line[idx].isspace():
idx += 1
continue
else:
processor = WordProcessor(self.line[idx:], self.line_number, idx + 1)
x = processor.process()
if x:
idx += x
else:
idx += 1