Skip to content

A macro processor is a program that copies a stream of text from one place to another, making a systematic set of replacements as it does so. Macro processors are often embedded in other programs, such as assemblers and compilers. Sometimes they are standalone programs that can be used to process any kind of text.

Notifications You must be signed in to change notification settings

Vishnu-Kota/Macro-Processors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Macro-Processors

stmp

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

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/Vishnu-Kota/Macro-Processor.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 here

About

A macro processor is a program that copies a stream of text from one place to another, making a systematic set of replacements as it does so. Macro processors are often embedded in other programs, such as assemblers and compilers. Sometimes they are standalone programs that can be used to process any kind of text.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages