HIGHER SUBLEQ

Compiler into OISC language

Last update      Notes on making Higher Subleq      Try it online

Higher Subleq is a simplified typeless C language. It supports the C function call model and statement and expression grammar. It does not support structs, unions, bitfields, abstract declarations, and any types. There is only one type integer, which sintacticly can be wrtten as int, char or void and their pointers. It does not have preprocessor. It supports pointer arithmetic, but all pointers are just the same basic type. It also has a few C++ ticks:
  • local variable can be declared at any point inside function
  • for has the statement in the grammar: for( int i=0; i<3; i++ )
  • C++ comments
  • functions must be declared to be used

The compiler and the emulator can handle bignum arithmetics. The following program calculates the factorial (use option -b for bugnum arithmetic since 20! is greater than 4 byte integer)
int printf(char * s);
int fact(int a)
{
   if( a==1 ) return 1;
   return a*fact(a-1);
}
int main()
{
   printf( "%d", fact(20) );
}

Multiplication operations are realized through the algorithm based on subtractions [O(logN)].

Download
  Source     hsq.cpp  
  Last update March 2011  
  • Compiler and emulator, all in 1 file
  • Written in standard C++
  • Does not depend on any 3rd paty library or tool   
  Tests     testhsq.zip  
  • Small programs testing different features

Below are examples of the commands:
> hsq file.hsq     (compile and run)
> hsq -a file.hsq  (produces assembly code)
> hsq -q file.asq  (produces subleq code)
> hsq file.sq      (run subleq)
> hsq file.asq     (compile assembly and run)
> hsq -ao file.asq (compile and output to stdout)
> hsq -ha file     (compile as hsq and save assembly)
> cat file.hsq | hsq.exe -iao | hsq -imqo | hsq -is (piped)
Usage: hsq [options] [files]
options:
 -e execute/emulate (defalut)
 -q output subleq code
 -a output assebmly
 -d output ITR
 -h  input HSQ (defalut, default for *.hsq)
 -m  input assembly (default for *.asm)
 -s  input subleq code (default for *.sq)
 -i input from stdin
 -o output to stdout
 -n nologo (defalut with -o)
 -b use bignum on emulation (default int)


See also Low Cost Subleq Supercomputer

Home