EPP1.0 plug-ins

(Last update: 1998-02-22)

This document explains plug-ins included in the EPP1.0 distribution package.

Some explanations of plug-ins are followed by three links, "Plug-in source code", "Test program" and "Translated code".


Contents


PRACTICAL PLUG-INS

Sample plug-ins for plug-in programmers

(These are not included in epplib.jar of the EPP distribution package.)

Plug-ins which is used for plug-in programming

(These plug-ins can not be used for ordinary Java programs because they require runtime classes.)

AutoSplitFiles

If you incorporate this plug-in, you can write multiple public classes in one file. EPP will split each classes into multiple files with adequate file names. Friendly classes (in other words, classes without "public" modifier), will be written in the file with the original file name.

Each line contained in each class will be emitted at the same line as in original file. For example, if two public classes A and C and a friendly class B are contained in a File.java, three files, File.java, A.java and B.java, will created under the directory eppout. Their contents will be as follows.

 File.java          eppout/File.java  eppout/A.java    eppout/C.java
+--------------+    +--------------+ +--------------+ +--------------+ 
|public class A|    |              | |public class A| |              | 
+--------------+    +--------------+ +--------------+ +--------------+ 
|class B       | => |class B       | |              | |              | 
+--------------+    +--------------+ +--------------+ +--------------+ 
|public class C|    |              | |              | |public class C| 
+--------------+    +--------------+ +--------------+ +--------------+ 
When javac reports error during compilation of translated files, you can find the point of error by the reported class name and the line number.

defmacro

By this plug-in, you can write macros with easy way as with #define of C pre-processor.
Examples:
        defmacro max(a, b)  (a > b ? a : b)
        defmacro swap(t, a, b) {t tmp; tmp = a; a = b; b = tmp;}
Macro expansion pattern should begin with "(" or "{". If it starts with "(", it will be parsed as an expression. If it starts with "{", it will be parsed as a block. Unlike cpp, macro expansion is done for parsed trees. (Therefore, you can not extend the Java syntax with this macro.)

Macro definition part is restricted to a function call style. Unlike #define, defmacro can not be used for constant definitions.

        defmacro  SIZE   1024            /* Not allowed. */
Unlike #define, you do not have to enclose parameters in expansion pattern with parentheses.
        #define max(a, b)  ((a) > (b) ? (a) : (b))

Plug-in source code / Test program / Translated code

EmbedCopyright

This plug-in will embed message like "Copyright 1998 ..." into all class files. Before starting EPP, write a message in a file, Copyright.txt, under the current direcoty. Then, start EPP with this plug-in like this.
        epp -plug-in EmbedCopyright *.java
The contents of Copyright.txt will be embedded in all classes as initial values of static fields.
Plug-in source code / Test program / Translated code

enum

With plug-in, you can easily define continuous integer constants.
Plug-in source code / Test program / Translated code

OptParam

This plug-in enables you to define methods with optional parameters like C++.
Plug-in source code / Test program / Translated code

UserOp

With this plug-in you can use binary operators for user defined classes. The syntax of users operators resembles the Mr. Nik Shaylor's jpp (http://www.digiserve.com/nshaylor). Binry operators listed below enclosed by parentheses will be expanded into method invocation expressions. The precedence of each operators are the same as their original operators.
       a (+)  b     a.plus(b)   
       a (-)  b     a.minus(b)
       a (*)  b     a.times(b)
       a (/)  b     a.divide(b)
       a (%)  b     a.modulus(b)
       a (<<) b     a.leftShift(b)
       a (>>) b     a.rightShift(b)
       a (>>>) b    a.unsignedRightShift(b)
       a (==) b     a.equals(b)
       a (!=) b    !a.equals(b)
       a (<)  b     a.lessThan(b)
       a (>)  b     a.greaterThan(b)
       a (<=) b    !a.greaterThan(b)
       a (>=) b    !a.lessThan(b)
       a (&) b      a.and(b)
       a (|) b      a.or(b)
       a (^) b      a.not(b)
The implementation of this plug-in is a good example which extends lexical analyzer of EPP.
Plug-in source code / Test program / Translated code

Math

With plug-in, you can use static methods of class java.lang.Math as if they are global funcitons. For example, you can write "sin(x)" instead of "Math.sin(x)" .
Plug-in source code / Test program / Translated code

assert

This plug-in provides an assert macro. If the result of conditional expression of the assert macro is false, the file name and line number where the assert macro is written will be printed to "System.err" and a instance of class Error will be thrown. In order to expand assert macros into empty-statements, use the noassert plug-in.
Plug-in source code / Test program / Translated code

noassert

This plug-in translates assert macros into empty-statements. The typical use of this plug-in will be as follows.
        epp -plug-in noassert File1.java File2.java ...
By adding noassert plug-in as a command line option of EPP, the function of assert plug-in will be overridden.
Plug-in source code / Test program / Translated code

SWAP

This plug-in provides a SWAP macro. This is the simplest example of plug-in implementation.
Plug-in source code / Test program / Translated code

CallByReference

This plug-in adds a feature of "pseudo call by reference". The caller of methods can specify a variable with a prefix unary operator &. The callee should declare the parameter as an array type. In order to assign a value to the parameter, the callee should execute an assignment like "x[0] = value" .

In the current implementation, actual parameters which can be specified with & is restricted to variables with int type. (Because current EPP does not treat type infomation at all.)
Plug-in source code / Test program / Translated code


PComp

This plug-in changes the syntax of comparison operators to the Python langauges's one. Using this plug-in, you can write
        if (0 <= x < max) ...;
instead of the following.
        if (0 <= x && x < max) ...;

The other plug-ins extends the Java language, however, this plug-in replaces a part of original grammar rules of Java. (At the top of source code of this plug-in, there are codes which remove standard Java parser system mixins.)

This plug-in restricts the arguments of comparison operators to integer type expressions.
Plug-in source code / Test program / Translated code


SystemMixin

This plug-in is for plug-in programmers.
This plug-in adds system mixin feature, that encourages modularization of programs.

Symbol

This plug-in is for plug-in programmers.
With this plug-in, you can use symbols, that is the characteristic data type in the lisp language. Symbols is written as colomn followed by a identifier or a string, such as :foo or :"+".

BackQuote

This plug-in is for plug-in programmers.
This plug-in introduce a useful feature of Lisp into Java, backquote macro feature. Using backquote macro, the programmer can easily embed abstract syntax trees in the plug-in source code.

The following code is an example of backquote macro used in the Math plug-in.

    Tree fname = tree.args()[0];
    return `(invokeLong
             (name (id java) (id lang) (id Math))
             ,fname
             (argumentList ,@args));

EppMacros

This plug-in is for plug-in programmers.
This plug-in provides the following two macros which define a non-terminal symbol and a binary operator respectively.
        defineNonTerminal(NonTerminalName, DefaultValue);
        defineBinaryOperator(SystemMixinNAME, Token, PRECEDENCE);

To Home Page of EPP