From 066fee44ac313d48815e2bcdb96f30ed12e353b4 Mon Sep 17 00:00:00 2001 From: Rusty Striker Date: Thu, 4 Apr 2024 10:06:07 +0300 Subject: [PATCH] s'more documantation --- README.md | 14 +++++++++++++- parser.py | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3499065..6d9afcb 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,16 @@ The compiler is seperated into multiple files: - items.py: contains data structs for the parser - lexer.py: lexer class - parser.py: parser class -- cpq.py: main program and cmd handling logic \ No newline at end of file +- cpq.py: main program and cmd handling logic + +## Implementation details + +First i wanted to use rust/c, but it seems sly is very easy to work with and is a lot less cryptic +than flex/bison. + +the lexer class contains the token's regular expressions and the token types + +the parser class contains functions for each possible reduction, and using each variable once (with next_temp function) +and contains the ouput code in the list lines, which in turn is to be used by +the caller (of the parsing routine) as it wished (currently, by cpq.py to write +to a text file if no errors occured) \ No newline at end of file diff --git a/parser.py b/parser.py index 1918ddd..c13c07f 100644 --- a/parser.py +++ b/parser.py @@ -14,6 +14,7 @@ class Parser(sly.Parser): last_used_temp = 0 # cpl doesnt allow _ in ids, so use t_NUM as variables def next_temp(self): + # returns the next temp variable name self.last_used_temp += 1 return f't_{self.last_used_temp}'