Skip to main content

MetaProgramming

rascal-0.34.0

Synopsis

Analysis or transformation of one program by another program.

Description

All programs take data as input and produce other data as output. A typical example is a desktop calculator program: after entering some numbers and operators, the program displays an answer. For most programs the data are numeric (calculator, spreadsheet) or textual (text editor, word processor).

A metaprogram is a program that uses programs as data. Writing metaprograms is called metaprogramming.

A metaprogram has to be written in some programming language itself. This is called the metalanguage.

The program that is manipulated by the metaprogram is called the source program (also: object program) and is written in the source language (also: object language).

In some cases the metaprogram transforms the source program into a target program in a target language.

Examples

A Refactoring tool for restructuring Java code:

  • Metaprogram: the refactoring tool.
  • Metalanguage: in most cases Java.
  • Source program: the user's Java program to be refactored.
  • Source language: Java.
  • Target program: the refactored user's program.
  • Target language: Java.

A Java Compiler:

  • Metaprogram: the Java compiler.
  • Metalanguage: in most cases Java.
  • Source program: the user's Java program to be compiled.
  • Source language: Java.
  • Target program: the code that is generated by the compiler.
  • Target language: instructions for the JVM (Java Virtual Machine) or machine code, depending on the hardware platform.

A tool to compute Software Metrics of Java programs

  • Metaprogram: the metrics tool.
  • Metalanguage: varies per tool: Java, Rascal.
  • Source program: the user's Java program for metrics will be computed.
  • Source language Java.
  • Target program: the value of the computed metric.
  • Target language: number.