Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/otmanedaoudi/c-complex-declarations-parser

A program that converts a complex C declaration into a human readable text.
https://github.com/otmanedaoudi/c-complex-declarations-parser

c compiler-design syntax-analysis syntax-tree

Last synced: about 2 months ago
JSON representation

A program that converts a complex C declaration into a human readable text.

Awesome Lists containing this project

README

        

This is an exercise from the book: [The ANSI C Programming Language](https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628), but with a more advanced implementation.

I extended the grammar by eliminating left recursivity and applying left factoring.
# Grammer:
```
dcl ==> A dirdcl
A ==> * A | epsilon
dirdcl ==> id dirdcl1 | ( dcl ) dirdcl1
dirdcl1 ==> ( ) dirdcl1 | [ dirdcl2 | epsilon
dirdcl2 ==> ] dirdcl1 | number ] dirdcl1

```
# LL(1) table:
| | * | ( | ) | [ | ] | number | id | $ |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| dcl | dcl ==> A dirdcl | dcl ==> A dirdcl | | | | | dcl ==> A dirdcl | |
| A | A ==> * A | A ==> epsilon | | | | | A ==> epsilon | |
| dirdcl | | dirdcl ==> ( dcl ) dirdcl1 | | | | | dirdcl ==> id dirdcl1 | |
| dirdcl1 | | dirdcl1 ==> ( ) dirdcl1 | dirdcl1 ==> epsilon | dirdcl1 ==> [ dirdcl2 | | | | dirdcl1 ==> epsilon |
| dirdcl2 | | | | | dirdcl2 ==> ] dirdcl1 | dirdcl2 ==> number ] dirdcl1 | | |

# Notes:
- The program only supports identifiers with one character.

- Supports one-digit array lengths.

- No support for function args.

- No support for constants declaration.

# Examples:
![examples](https://user-images.githubusercontent.com/63020343/201544807-5da66464-ce43-4afc-87b6-eecb0c3550ca.png)