Skip to content

vkazanov/pymetaii

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

META II metacompiler

A Python 3 implementation of the famous META II metacompiler virtual machine and a compiler writing domain-specific language.

Based on the original virtual machine from the “META II: A Syntax-Oriented Compiler Writing Language” 1965 paper[1], which is also explained in a brilliant tutorial[2] by James M. Neighbors. Wikipedia also has a page on META II[3]. There are numerous implementations in different languages out there [4][5][6].

Sources:

  1. http://www.chilton-computing.org.uk/acl/literature/reports/p025.htm
  2. http://www.bayfronttechnologies.com/mc_tutorial.html
  3. https://en.wikipedia.org/wiki/META_II
  4. https://github.com/stevenbagley/metaii
  5. https://github.com/EyeBool/Meta-II-Compiler
  6. https://github.com/siraben/meta-II

Usage

The parsing virtual machine is implemented in metaiivm.py. VM code for the DSL is in metaii.masm. META II DSL implemented in META II DSL is in metaii.meta. And yes, it’s a recursive definition, thus “metacompiler”.

Having these it’s possible to regenerate the masm file:

python metaiivm.py metaii.masm < metaii.meta > metaii-copy.masm
diff metaii-copy.masm metaii.masm
# nothing here - we can reproduce all the VM code necessary from the DSL

It’s also possible to use the VM from Python code:

import metaiivm
import io

code = parse_code(open("metaii.masm"))
meta_dsl = open("metaii.meta").read()

output_file = io.StringIO()
vm = metaiivm.VM(meta_dsl, output_file)
vm.run(code)

# print a fresh META II VM code copy
print(output_file.getvalue())

Testing

Running VM tests requires the pytest package:

py.test metaiivm_test.py
# ....

About

A Python 3 implementation of the famous META II metacompiler.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published