A compiler for expressions

To generate a compiler for a simple expression language, you need to do the following (assuming your system runs Windows NT or Windows 95):

  1. Install the Slim compiler onto your system. (You need the Microsoft C compiler).
  2. Create a directory for the Expression compiler.
  3. Copy expr.bnf, identifier.slm and number.slm into this directory.
  4. Copy makefile, custbld.slm, custwalk.slm, walker.slm, expr.slm and expr.lkr into this directory.
  5. Run make.
  6. Copy expr.exe and expr.lib to the same locations as slim.exe and slim.lib.

You now have a compiler which can turn expression source files (for example, test.expr) into executables.

Of the above, only expr.bnf, identifier.slm and number.slm are specific to the expression language. (expr.slm is a trivial adaptation of the standard main module). It thus takes a grand total of 46 lines of code to generate an entire compiler, albeit for a very simple language.

Explanation of expr.bnf.
Explanation of identifier.slm.
Explanation of number.slm.
Explanation of custbld.slm.
Explanation of custwalk.slm.
Explanation of walker.slm.

For further examples of languages implemented with this system, refer to the assignments set for the course I teach on Programming Language Semantics.