compilation_course_compiler/README.md

31 lines
955 B
Markdown
Raw Permalink Normal View History

2024-04-04 06:56:28 +00:00
# CPQ
2024-03-26 19:02:54 +00:00
2024-04-04 06:56:28 +00:00
cpq.py compiles a cpl source file (.ou) into a quad ir file (.qud) using sly as the lexer and parser.
## Usage
```
python cpq.py source_file.ou
```
## Structure
The compiler is seperated into multiple files:
- helper.py: contains a helper function (print_err)
- items.py: contains data structs for the parser
- lexer.py: lexer class
- parser.py: parser class
2024-04-04 07:06:07 +00:00
- 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)