Files
compiler-the-translators/README.MD
2025-05-06 21:22:39 -04:00

74 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# The Translators α Compiler
#### Members: Annie Slenker, Meyer Simon, Partho Bhattacharya, & Scarlett Kadan
## Alpha Compiler Flags & Expected Results
### -tok
Prints the token stream provided by the Lexical Analyzer to a `.tok` file. Output can be found in `/out/<file>.tok`. Tokenization follows the specified format found in the alpha language spec.
### -st
Prints the symbol table to a file. Follows the format provided in the alpha language spec. if the `-ir` flag is also present, the symbol table will print out temporary variables. Output can be found in `out/<file>.st`.
### -asc
Prints the annotated alpha source code to a file. Will display any syntax errors that are present below the line they occur on. If more than one error is present, the messages will stack. Output can be found in `out/<file>.asc`.
### -tc
Throws type check errors to the asc output file. If the `-asc` flag is not present, no errors will be displayed. Output can be found in `out/<file>.asc`
### -ir
Prints the intermediate code representation stream to a file. Output can be found in `out/<file>.ir`. This flag modifies the `-st` flag, allowing for temporary variables to print out.
### -cg
Prints the alpha program's unique x86 assembly to a `.s` file. Assembly stream is valid x86 code that can be assembled and linked with other .s files. Output can be found in `out/<file>.s`
### -debug
Prints debug messages to the console if present. Our debug messages utilizes a wrapper function for `printf()` called `printdebug()`. This allows for us to file names, code lines, and colors!
### -help
Prints a general help message. (If you read this far, you probably won't need this flag)
## Testing
**Arguments:**
-exp Generate expected output files
-diff Compare output files with expected output files
-help Show this help message
**Usage:**
./test.sh <file.alpha> [flags] Run the test on a single file
./test.sh <directory> [flags] Run the test on all files in a directory
**Examples:**
- ./test.sh test.alpha
- - Runs test flags in header on test.alpha
- ./test.sh test/
- - Runs test flags in header on all .alpha files in test/
- ./test.sh test/ -exp
- - Runs test flags in header on all .alpha files in test/ and generates expected output files
- ./test.sh test/ -diff
- - Runs test flags in header on all .alpha files in test/ and compares output files with expected output files
- ./test.sh test/ -exp -diff
- - Runs test flags in header on all .alpha files in test/ and generates expected output files and compares output files with expected output files
**Notes:**
To create a test file, on the first line of the .alpha file, add:
(* TEST: [ <test_flags> ] *)
where <test_flags> are the alpha flags to be used. Ex:
(* TEST: [ -debug -asc -tc ] *)
## Lexical Analyzer
* **Undefined Behavior:**
* Spaces are not required between tokens. For instance, an INTEGER and an ID are valid even if there is no space between them
```
Input: *5variable*
Output: 2 14 301 "5"
1 1 101 "variable"
```
## Syntax Analyzer
* *Incomplete*
## Symbol Table
* *TODO: Create diagram.*