batch

benja2998/batch

Batch compiler written in Rust

[!IMPORTANT] This compiler is incomplete. Consider contributing!

Usage

Install the compiler:

make # .cargo/bin has to be in PATH
# You can also run "make install", or "cargo install --path ." as they do the same thing

Run the compiler after installing:

make run ARGS="-h" # or "batch-compiler -h"

You can also try some of the tests:

make test<num> # where <num> is the test number. Currently, there are only 3 tests

Limitations

set command=calc.exe
%command%

will only work if it is an external command, not a built-in command

Features

Benchmarking

You can benchmark the compiler by running benchmark.bat.

Currently supported batch features

Supported OSes

Compiler itself

Compiled batch files

How it works

The compiler architecture goes like this:

flowchart TD
  A[Batch file is provided as input] --> B[Compiler reads and tokenizes the batch file]
  B --> C[Tokens]
  C --> D[Compiler grows the parse tree]
  D --> E[Parse tree]
  E --> F[Variables in the batch file are expanded]
  F --> G[Updated parse tree]
  G --> H[Compiler does two passes over the parse tree to generate assembly code]
  H --> I[Assembly code]
  I --> J[Compiler calls NASM to assemble the code]
  J --> K[Object file]
  K --> L[Compiler calls a linker to produce the executable]
  L --> M[Executable]

License

The Apache License 2.0.

FAQ

Q: How can I contact you privately?

A: You can contact me at benja2998@duck.com. Responses won’t be guaranteed as I don’t look at it often.

Q: Will you add official Linux support?

A: Yes, but currently it is not a priority.

Q: Will you add official macOS support?

A: No.

Q: How can I contribute?

A: See CONTRIBUTING.md.

Q: What is batch?

A: Batch is a Windows scripting language developed by Microsoft. It is used in .cmd files, .bat files and the Windows command prompt.