The aim of this project is to create parser for C language. There are several features of this parser:
- Parser saves all comments. Each comment appends to the parent node.
- Uses grammar for C11 (see grammar.txt for more)
- Parser skip all preprocessor directives. Unfortunatelly, as a result of this, it do not build symbol table and cannot say is identificator is defined type or not.
To test program you can execute following command to generate AST tree for a test file:
git clone https://github.com/rusphantom/cparser.git
cd cparser/
python3 ./main.py ./tests/bin2hex_c
To install this lib into pip, use
pip3 install .
- lexer.py file contains lexer which transforms C code as string to list of lexer.Lexem objects.
- analyzer.py file contains Analyzer object which transform list of lexer.Lexem to AST tree. analyzer.Analyzer object takes lexer.Lexer in constructor. To generate tree call parse() method.
- Node.py file contains Node object which is element in AST tree.
- To print full AST tree with all nodes call debug.AST2String( ast_tree ). To skip garbage nodes call debug.AST2StringSkip( ast_tree )
It is easier to check an example how to use this lib in ./main.py
- Use first sets
- Make documentation