This is a very naive attempt at implementing a C frontend compiler. The implemented frontend architecture is described in the following diagram:
The symbol table is implemented using a finite state machine as described below:
- make sure
flex
is installed in your machine - make sure to have python 3.8+ installed and install package dependancies in
requirements.txt
- generate C lexer code from
lexer.lex
flex lexer/lexer.lex
- compile previously generated C code file (make sure you have a C compiler installed in your machine):
gcc lex.yy.c -lfl
- pipe a C source code into the previously compiled lexer then pipe the output of the lexer to the Python parser:
cat examples/example3.c | ./a.out | python3 parser/symbol_table.py
- Preprocessor should be run on source C code before attempting to tokenize it. Not doing so will result in a lot of undefined-variable errors
- Name of scope isn't specified (should be implemented easily).
- Pointers are not yet properly handled.
- String literal tokenizer
- Ignore single line comments
- Ignore multiple line comments
MIT License as specified in the LICENSE.txt
file.