Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: olalonde on March 03, 2014, 11:01:14 AM



Title: Working on a language and compiler for Bitcoin scripts
Post by: olalonde on March 03, 2014, 11:01:14 AM
I've never written a compiler before and wanted to give it a shot so I decided to write a high level language and compiler for Bitcoin's stack based script
language. So far, the parser kind of works but the compilation step is still work in progress. The language (bitscript) uses a Javascript like syntax.

The following script should compile to a standard transaction script (eventually):

Code:
// standardtransaction.bitscript
function main(sig, pubKey) {
  pubKeyHash = '1eHhgW6vquBYhwMPhQ668HPjxTtpvZGPC';
  pubKeyHashA = hash160(pubKey);

  // should be optimized to OP_EQUALVERIFY
  assert(pubKeyHash == pubKeyHashA);

  // should be optimized to OP_CHECKSIGVERIFY
  assert(checksig(sig, pubkey));
}

I'm posting this here mainly to keep me motivated and in case anyone wants to participate. I'm writing the compiler using Node.js + Jison. https://github.com/olalonde/compiler/