https://github.com/avik-pal/cs335-compiler
CS335 Compilers IITK Course Project
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
3 of 9 committers (33.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Repository
CS335 Compilers IITK Course Project
Basic Info
- Host: GitHub
- Owner: avik-pal
- License: mit
- Language: Python
- Default Branch: main
- Size: 1.36 MB
Statistics
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
CS335 IITK Compiler Project
Description
This project aims to develop a compiler for C language as a part of the course CS335 Compiler Design.
NOTE: To run the code for the respective Milestone, please checkout the tags. Future versions are not supposed to be backwards compatible.
Milestone 1
TAG: lexer
We develop a scanner using lex and yacc, which takes as input any C program and generates a table of tokens along with the corresponding lexeme, line no and column no of the token as output. We use the specifications for scanner and parser as mentioned in the problem statement.
We test it using the testcases present in the tests/ sub-directory. The procedure to build and run the program is as follows:
```bash
$ mkdir bin
$ cd src
$ make
$ cd ..
$ ./bin/lexer tests/testlexer1.c -o out_file
Any of the files having name testlexer*.c can be used
-o flag redirects the output to the out_file
```
Milestone 2
TAG: parser
We implemented the parser for an (extended) ANSI C version which outputs a dot file which can then be visualized using any standing dot file viewer. We expect ply and graphviz to be installed (can be setup using pip install -r requirements.txt).
We test it using the testcases present in the tests/ sub-directory. The procedure to run the program is as follows:
```bash
$ python src/parser/parser.py tests/testparser1.c --trim -o ast.dot
--trim produces a smaller AST meant for humans (though it preserves all the important information needed)
-o is used to redirect output to a file
Both are optional
```
How to visualize the AST:
bash
$ dot -Tps AST.dot -o AST.ps
$ xdg-open AST.ps
Milestone 3
TAG: semantics
Continuing with our Python based implementation of the parser in Milestone 2, we have now added the functionality for symbol table and semantic checks. Now, our program generates ASTs that are consistent with semantic checking. We expect the requirements mentioned in the requirements.txt to be installed (can be setup using pip install -r requirements.txt).
We test it using the testcases present in the tests/ sub-directory. The procedure to run the program is as follows:
```bash
$ python src/parser.py tests/testsemantics1.c -o ast.dot
-o is used to redirect output to a file (optional parameter)
How to visualize the AST:
bash
$ dot -Tps AST.dot -o AST.ps
$ xdg-open AST.ps
```
Miscellaneous
How to move from C yacc -> Python PLY yacc in < 1 mins?
It is pretty simple actually :o. Use the helper src/parser/yacc_to_ply.py file, which converts the c_yacc.y file present in that directory to the corresponding ply format. Finally, if visual aesthetics is important for you, run black -l 79 ./src/parser/ply_file.py.
Design Details
Column and Line Numbers start from 1
Features supported by the lexer in addition to the standard C specifications:
- Inheritance
public,protected,privatehave been added as keywords.<-is used to define inheritance.class Car <- public Vehicleis equivalent to theC++declaration ofclass Car : public Vehicle.- To declare variables as
public,protected,privatethey need to be enclosed in{}instead of the traditional:notation inC++.
- Inheritance
How to use the SymbolTable?
- Initialize with a parent. Global Table has no parent
insert: Takes anentry(dict), refer to the code to see what fields are needed for each kind of identifier. All these fields are mandatory. Additionally akind(int) variable must be passed to indicate what type of identifier is it (see the top of SymbolTable to find out the exact numbers).check_type: Whethertypename(str) is a valid type.translate_type: For mental sanity we shall replacestruct ___/union ___with a typedef. Call this function to get this typedef"ed" type.lookup: Returns a list/dict if the symbol being searched is found in the current table / it's parentsdisplay: Pretty Printing
Owner
- Name: Avik Pal
- Login: avik-pal
- Kind: user
- Location: Cambridge, MA
- Company: Massachusetts Institute of Technology
- Website: https://avik-pal.github.io
- Twitter: avikpal1410
- Repositories: 46
- Profile: https://github.com/avik-pal
PhD Student @mit || Prev: BTech CSE IITK
GitHub Events
Total
Last Year
Committers
Last synced: almost 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Avik Pal | a****l@i****n | 164 |
| nidhihegde001 | n****h@i****n | 36 |
| purug2000 | p****0@g****m | 23 |
| Vaibhav | v****l@g****m | 21 |
| yasharthb | y****9@g****m | 19 |
| Vaibhav Jindal | 3****l | 5 |
| Avik Pal | a****l@c****n | 1 |
| Priyanshu Gupta | 3****0 | 1 |
| nidhihegde001 | 4****1 | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: over 1 year ago
All Time
- Total issues: 0
- Total pull requests: 4
- Average time to close issues: N/A
- Average time to close pull requests: 39 minutes
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.5
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- avik-pal (3)
- yasharthb (1)