Coder Social home page Coder Social logo

p6-c-parser's Introduction

p6-c-parser

Grammar for Parsing C in Perl6

Introduction

WARNING This parser is not production ready. It is experimental, and a work in progress. If you would like to try it out, the recommended way is:

my $ast = C::Parser.parse($source);

Another thing to note is that it doesn't provide any understanding of C preprocessor directives, so you will have to use gcc -E (or the like) before parsing it. This can usually be accomplished by:

gcc -E FILE.c | grep -v '^#' | bin/cdump.pl6

Typedefs

Probably the major surprizing thing about this parser is that it doesn't work for obvious inputs, such as GHashTable hash;. The reason for this is that the parser has built-in rules that match based on whether an identifier has been previously involved in a typedef declaration. So if your source code compiles with a fully functional compiler, then it should also parse with this parser. But if your source code just happens to match the syntactic definition of C, but not the semantics, then good luck, dude.

For this reason, there are a lot of types that are pre-declared to help ease the pain associated with this issue. Most of them are types that are usually found in system-supplied libraries, such as libc and POSIX. For example, types such as FILE and int64_t are pre-declared. If you feed a preprocessed source that had include "stdint.h" in it, then the parser will see a typedef for int64_t at some point. This is perfectly fine. A type can be typedefed multiple times and it will still parse, but not 0 times.

Conclusion

Don't write a compiler with this just yet.

p6-c-parser's People

Contributors

andydude avatar zoffixznet avatar raydiak avatar jjatria avatar froggs avatar

Stargazers

Kamil Adam avatar Alesya Huzik avatar Ștefan Suciu avatar Chris Fields avatar Michal Jurosz avatar  avatar Alexander Moquin avatar

Watchers

 avatar James Cloos avatar Rúbio Terra avatar

p6-c-parser's Issues

Can't parse png.h from libpng 1.2

Things which don't work seem to include extension and declarations like "typedef unsigned (*in_func) (void *, unsigned char * *);". Also seeing "unknown condition in typedef!" 6 times, though the error doesn't point to exactly what causes it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.