Matt Wette writes: > On Dec 30, 2015, at 6:35 AM, Ludovic Courtès <l...@gnu.org> wrote: >>> Demo: >>> Use C parser and pretty printer to clean up C expressions (e.g., remove >>> unneeded paren’s): >> >> The demo is already quite impressive! > > Thanks.
I agree. Holy damn, this looks incredible. >> What subset of C99 and GNU99 is currently supported? > > I can’t remember if any C99 items are not in. I do not have any GNU99 > extensions in there. However, this is not a faithful parser for C99. > The purpose is not to compile, but to generate translators and > auto-coders. I have built the parser with the following features: > 1) The c-preprocessor parsing is merged in with the lexical analyzer. > 2) The parse tree is “file oriented”, so that you can track what > elements are in the top-level file. > 3) The parser will parse comments. > > so > #ifdef ABC > #include “xyz.h” > #endif > foo_t x; /* this is a decl */ > > comes out > (trans-unit > (cpp-stmt (if (defined "ABC"))) > (cpp-stmt > (include > "\"xyz.h\"" > (trans-unit > (decl (decl-spec-list > (stor-spec (typedef)) > (type-spec (fixed-type "int"))) > (init-declr-list (init-declr (ident "foo_t"))))))) > (cpp-stmt (endif)) > (decl (decl-spec-list (type-spec (typename "foo_t"))) > (init-declr-list (init-declr (ident "x"))) > (comment " this is a decl "))) > > and the pretty-printer generates > #if defined(ABC) > #include "xyz.h" > #endif > foo_t x; /* this is a decl */ Still super cool. >> What are you aiming for with the tree-il conversion? That sounds >> interesting. :-) > > The purpose of the tree-il conversion is to support “,L <langauge>” at > the guile prompt. And the tree-il code is done for javascript and a > simple calculator, not C. I just tried the javascript and it is not > working, but here is a small demo with the simple calculator. The > calc files (parser, compiler and spec) are included below. > > scheme@(guile-user)> ,L calc > Happy hacking with calc! To switch back, type `,L scheme'. > calc@(guile-user)> a = 3 + 4 > calc@(guile-user)> ,L scheme > Happy hacking with Scheme! To switch back, type `,L calc'. > scheme@(guile-user)> a > $1 = 7 That's really interesting. Do you have more specific applications in mind beyond this?