Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

A compiler for my own simple low-level programming language, built in JavaScript using the Duktape framework. Produces code compatible with FlatAssembler. Superseded by AECforWebAssembly.

FlatAssembler/ArithmeticExpressionCompiler

Repository files navigation

ArithmeticExpressionCompiler

A compiler for my own simple low-level programming language, built in JavaScript using the Duktape framework.

You can try it using this shell script:

mkdir ArithmeticExpressionCompiler
cd ArithmeticExpressionCompiler
if [ $(command -v wget > /dev/null 2>&1 ; echo $?) -eq 0 ] # Check if "wget" exists, see those StackOverflow answers for more details:
                                                                                        # https://stackoverflow.com/a/75103891/8902065
                                                                                        # https://stackoverflow.com/a/75103209/8902065
then
  wget https://flatassembler.github.io/Duktape.zip
else
  curl -o Duktape.zip https://flatassembler.github.io/Duktape.zip
fi
unzip Duktape.zip
if [ $(command -v clang > /dev/null 2>&1 ; echo $?) -eq 0 ] # We prefer "clang" to "gcc" because... what if somebody tries to run this in CygWin terminal? GCC will not work then, CLANG might.
then
  c_compiler="clang"
else
  c_compiler="gcc"
fi
$c_compiler -o aec aec.c duktape.c -lm # The linker that comes with recent versions of Debian Linux insists that "-lm" is put AFTER the source files, or else it outputs some confusing error message.
if [ "$OS" = "Windows_NT" ]
then
  ./aec analogClockForWindows.aec
  $c_compiler -o analogClockForWindows analogClockForWindows.s -m32
  ./analogClockForWindows
else
  ./aec analogClock.aec
  $c_compiler -o analogClock analogClock.s -m32
  ./analogClock
fi

If everything is fine, the Analog Clock program should now print the current time in the terminal. I think this would work on the vast majority of Linux machines, as well as on many non-Linux (FreeBSD, Solaris...) machines, and on some Windows machines with a Unix shell (such as Git Bash).

See this link for more information: https://flatassembler.github.io/compiler.html (The back-end of the website doesn't work now when the website is hosted on GitHub, but the core of the compiler is written in JavaScript and is still usable)

"ArithmeticExpressionCompiler.zip" contains the 32-bit Windows, 32-bit DOS (runnable under FreeDOS, and I guess under MS-DOS with a DPMI) and 32-bit Linux executables of the compiler and some example programs written in AEC for Windows, Linux and DOS, together with their executables. The source code of the compiler, together with the source code of the Duktape framework, is available at: https://flatassembler.github.io/Duktape.zip
The Duktape.zip file contains no executable files (the JavaScript programs there can only be run in the Duktape JavaScript engine, which is not pre-installed on any OS), so you can be sure they are free of malware.

The file "compiler.html" contains the not-minified JavaScript of the file "compiler.js", present in those ZIP archives and necessary for ArithmeticExpressionCompiler to work. The "control.js" file shows a primitive way to deal with "If", "Else", "EndIf", "While" and similar directives, it's also present in the ZIP archives and necessary for ArithmeticExpressionCompiler to work.

I've made a YouTube video about how you can set up a modern computer to program it in your own programming language, you can see it here: https://youtu.be/N2C1i8CW7Io

"trigonometry.c" is an example of how to include assembly code generated by ArithmeticExpressionCompiler into C. In case somebody fails to compile it, I've included the 32-bit Windows executable ("trigonometry.exe"), the 32-bit Linux executable ("trigonometry.elf") and 64-bit Linux executable ("trigonometry.elf64"), your computer can hopefully open at least one of them.

"NppSyntaxHighlightingScript.xml" is a script for Notepad++ to syntax-highlight that language.

code style: prettier

Update

If you find this piece of work interesting, you will probably also like my ArithmeticExpressionCompiler for WebAssembly, which is significantly more professionally made: https://github.com/FlatAssembler/AECforWebAssembly