ahorn / bf-compiler

32-bit BF compiler written in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

License:      GPL
Authors:      A. Horn, S. Pal
Description:  32-bit BF compiler written in C
Installation: make install

About:

bfc is a compiler for a Turing-complete language with the acronym BF.
The compiler is written in C. It compiles BF source code into ELF
machine code for GNU/Linux running on x86-32 Intel or AMD microprocessors.
It generates assembly code in the Intel format and then uses GNU as and
GNU ld programs to assemble and link it to generate the ELF file.

Acknowledgement:

An earlier 8-bit version of this compiler that produces the assembly code in
the AT&T format can be found on S. Pal's website: [http://susam.in/bfc/].

BF commands:

  >   increment the data pointer (to point to the next cell to the right).
  <   decrement the data pointer (to point to the next cell to the left).
  +   increment (increase by one) the byte at the data pointer.
  -   decrement (decrease by one) the byte at the data pointer.
  .   output the value of the byte at the data pointer.
  ,   accept one byte of input, storing its value in the byte at the data pointer.
  [   if the byte at the data pointer is zero, then instead of moving the instruction
      pointer forward to the next command, jump it forward to the command after
      the matching ] command*.
  ]   if the byte at the data pointer is nonzero, then instead of moving the instruction
      pointer forward to the next command, jump it back to the command after the
      matching [ command*.

Example:

+++++ +++++             // initialize counter (cell #0) to 10
[                       // use loop to set the next four cells to 70/100/30/10
    > +++++ ++          //    add  7 to cell #1
    > +++++ +++++       //    add 10 to cell #2 
    > +++               //    add  3 to cell #3
    > +                 //    add  1 to cell #4
    <<<< -              //    decrement counter (cell #0)
]                       //
> ++ .                  // print 'H'
> + .                   // print 'e'
+++++ ++ .              // print 'l'
.                       // print 'l'
+++ .                   // print 'o'
> ++ .                  // print ' '
<< +++++ +++++ +++++ .  // print 'W'
> .                     // print 'o'
+++ .                   // print 'r'
----- - .               // print 'l'
----- --- .             // print 'd'
> + .                   // print '!'
> .                     // print '\n'

About

32-bit BF compiler written in C

License:GNU General Public License v3.0


Languages

Language:C 100.0%