Mdef Example

last modified: August 24, 2012

Here is a code generation example using MDef (http://mdef.sourceforge.net):

mdef program
    program-headers
    program-main
mend

mdef program-headers
    #include <stdio.h>
mend

mdef program-main
    int main(int argc, char* argv[])
    {
        program-body
    },
mend

mdef program-body
    printf("hello world\n");
    return 0;
mend

program

Save this to hello.m. Then type

perl mdef.pl hello.m > hello.c 
gcc hello.c 
./a.out

This will print "hello world".

Note that everything here is reusable except for the program-body.


Loading...