r/ProgrammingLanguages • • Oct 27 '26

a small Python language compiler that transpiles to bash and batch (learning project, written in C)

I'm building with a friend a language with Python syntax that transpiles to plain bash and batch.

The idea: if you already know Python, there's nothing new to learn. You write the script once, and the generated .sh /.bat runs on a machine with nothing installed, no Python and no PowerShell. Only the machine where you write the script needs.

Why not the existing options?

- Python isn't installed by default on Windows or some Unix-like systems. - Batsh and Amber target similar problems, but they come with their own syntax to learn (and Batsh looks unmaintained).

- PowerShell is another language to learn, and it's an extra install on Linux/macOS.

- Keeping separate .sh and .bat versions of the same script is tedious and error-prone.

Status: it's early. The lexer is done and the parser is in progress (it only handles name = value so far). The bash and batch backends haven't been started. It's a subset of Python, not a full implementation, since some features have no natural equivalent in batch.

Questions for you:

  1. For automation scripts, which features should come first: conditionals, loops, running commands, file operations?

]2. Is batch still worth targeting, or should the Windows backend be PowerShell?

on the design is very welcome, especially from anyone who has written a transpiler before.

13 Upvotes

11 comments sorted by

View all comments

Show parent comment

-4

u/Gnaxe Oct 27 '26

Not impossible, especially with AI assistance. There are already Python to JavaScript transpilers, for example.

Consider transpiling the Python bytecodes instead of the Python language. They're quite a bit simpler. The BeeWare project might be a useful reference.

2

u/snugar_i Oct 28 '26

Supporting all of Python syntax isn't that hard TBH. Supporting the whole standard library is another thing

1

u/Gnaxe Oct 28 '26

Again, BeeWare. It has a lot of the standard library C code re-implemented in pure Python. Just use the same transpiler on that.