Skip to content

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

License

Notifications You must be signed in to change notification settings

OtmaneDaoudi/C-complex-declarations-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an exercise from the book: The ANSI C Programming Language, 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages