7 comments

  • kelsey98765431 5 hours ago
    Would be a lot better if it came with tests. Please do this justice and dont let it rot as a gist, make a real repo and add some docs and at least smoke tests or some kind. Thanks
    • gaigalas 21 minutes ago
      This gist is a concatenation of several shell script modules which form a comprehensive parser library for the portable shell.

      The main parser and emitter are BFN-generated (that's why they look so mechanical). The BNF parser generator is also written in portable shell.

      All modules have comprehensive tests, but it is still lacking documentation and not ready for prime time!

    • fuhsnn 3 hours ago
      Don't understand why you were downvoted. An untested C compiler is simply worthless.
      • nananana9 1 hour ago
        The 2026 brain simply cannot comprehend recreational programming.
        • fuhsnn 1 hour ago
          Well, I happen to have been recreationally maintaining a hobbyist C compiler for three years, adding tests is part of the fun.
  • JackSmith_YC 1 hour ago
    Pure shell. Love the minimalism here... especially when every tiny CLI tool these days seems to require a 50MB node_modules folder just to run. There’s a certain Zen in doing things with zero dependencies. Reminds me of why I got into Unix in the first place.
    • tho2u3i4o23497 37 minutes ago
      Node stuff atleast "works" - you've not seen real dependency hell until you've seen the horrible world of the Python ML ecosystem.
  • _ache_ 3 hours ago
    I'm tempted to execute it, but it may as well be shellcode I couldn't tell.
  • jey 4 hours ago
    It targets x86-64/ELF? I thought it would target `sh` to be portable?
  • gaigalas 1 day ago
    Single standalone file, no external tools used, PATH='' (empty), portable (bash, dash, ksh, zsh), produces x86 ELF executables, has mini-libc builtin.

    Usage:

    printf 'int main(){puts("hello");return 0;}' | sh c89cc.sh > hello

    chmod +x hello

    ./hello

    • angry_octet 5 hours ago
      I can't think of a reason to use c89cc.sh, but I salute this effort nonetheless.
    • t-3 2 hours ago
      Why not POSIX or some common external tools where it makes sense? Most of those big switch statements could be easily replaced with some standard programs that already exist everywhere.
      • gaigalas 3 minutes ago
        One main reason is performance. Forking for other tools is very expensive.

        That said, using larger sed or awk programs instead of ad-hoc calls for small snippets would perhaps be net-positive for performance and readability.

        I'm currently working on very strict bootstrap scenarios in which sed and awk might not be available, but a shell might be (if I'm able to write it). It is possible that in such scenarios, the fist send and awk versions will be shell-written polyfills anyway.

    • jonahx 2 hours ago
      gorgeous!
  • self_awareness 8 minutes ago
    "Claude please generate me a C compiler in bash"

    I mean, today it's possible to generate it in Tcl, Elisp, Windows BAT, Powershell.

    The effort is just 1 prompt.

    The WHY question is much more important today -- "because I can" no longer makes sense, because we all can do much, much more with minimum effort today than before LLMs.

  • dmitrygr 5 hours ago
    Many parts of this are clearly autogenerated, but that in no way diminishes the sickening impressiveness of it!
    • userbinator 4 hours ago
      It would be far more interesting to look at what this was "compiled" from; it looks like the output of a state-machine generator.
    • gaigalas 16 minutes ago
      Yes! The main parser and emitter come from a BNF parser generator, also written in portable shell (to be released though).
    • phire 4 hours ago
      It does make it a little hard to understand how the parser/ast_builder works.

      But the rest seems easy enough to understand.

      • gaigalas 10 minutes ago
        This is a hand-written parser for the shell itself (portable shell parsing portable shell):

        https://gist.github.com/alganet/23df53c567b8a0bf959ecbc7b689...

        It's an incomplete idea from around a year ago. The approach taken here (aliases as macro-like evals, AST generation using shell variables) became the backbone for the BNF parser generator.

        This one is much simpler to understand. Simpler grammars tend to produce parser code that looks more like this one.

      • fuhsnn 3 hours ago
        > It does make it a little hard to understand

        Or much easier to backdoor...