Skip to content

Simple macro processor. It will expand MACROs defined in source code.

License

Notifications You must be signed in to change notification settings

ParadoxZero/stmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stmp

Codacy Badge License: MIT Build Status

Simple macro processor. It will expand MACROs defined in source code and create a new source file.

example

Notice

stmp will change the layout of code, especially spacing and tabs hence it should not be used along with languages like python.

Macro Definition Language Syntax

The syntax of defining a macro:

  <macro_name> MACRO <arg1> <arg2> ..... <arg n>
  statement1
  statement2
    .   .
    .   .
    .   .
  MEND

Example:

  add_and_check MACRO arg1 arg2
  add(arg1,arg2);
  check(arg2,arg1);
  MEND

  sum MACRO a b
  a=a+b;
  MEND

  void test_function(int a, int b){
      int c=5;
      add_and_check a b
      sum c b
      return c;
  }

stmp would yield an output:

void test_function ( int a ,  int b )  {  
int c = 5 ;  
add ( a , b ) ;
check ( b , a ) ; 

c = c + b ;

return c; 
 }  

Comments

stmp recognizes comments and doesn't expand them. Currently only line comments supported.

Syntax of comment: # or //

eg:

int c = 6;
//will be ignored
# will be ignored

If comment is placed within the macro, it will be copied when expanded.

Why use MACRO ?

MACROs are useful when you want to manipulate source code. Repeat certain lines of code, but each copy is slightly different from the last.

For example, suppose you want the following functions:

double getDoubleSize () { 
return sizeof(type); 
} 

int getIntSize () { 
return sizeof(type); 
} 

void printDouble ( double x ) { 
printf( "%lf" , x ); 
} 

void printInt ( int x ) { 
printf( "%d" , x ); 
} 

Instead of repeating code, you simply use MACRO:

create_size_function getDoubleSize double
create_size_function getIntSize int
create_print_function printDouble "%lf" double
create_print_function printInt "%d" int

How to use

  • Basic usage:
  $ ./stmp source_file.extension
  • Help
  $ ./stmp -h
  $ ./stmp --help
  Usage:
    stmp [FLAGS]... [PATH]

  Flags available to use:
  1) -v, --version    Output version details and exit.
  2) -h, --help    Output this help and exist.

  Exapmle: stmp example.asm

How to build

prerequisite

  • CMake
  • Gcc/Clang
  1. Download source
  $ git clone https://github.com/ParadoxZero/stmp.git
  $ cd stmp
  1. Create build directory
  $ mkdir build  
  $ cd build
  1. Build
  $ cmake ..
  $ make

How to run tests

  $ chmod +x run_test.sh
  $ ./run_test.sh

Contributing

Feel free to send a pull request.

In case of any questions contact me at [email protected]