Package org.jsesoft.jpp


org.jsesoft.jpp: A Java macro preprocessor Title: A Java macro preprocessor. See:
          Description

Class Summary
AnyButMacros The AnyButMacros terminal.
Comment A comment terminal.
CommentSlashState Scans comments or a single slash from the reader
Default The default terminal.
DefaultState Implements handling of tokens otherwise not recognized.
DocumentationCommentState Scans a documentation comment from the reader.
Identifier The identifier terminal.
IdentifierState An identifier state returns an identifier from the reader.
Keyword The keyword terminal.
KeywordIdentifierState Checks for keyword, otherwise identifier.
MacroArgAssembler An assembler for a macro argument.
MacroBodyAssembler An assembler for collecting a macro body.
MacroCall The macro call terminal.
MacroCallAssembler An assembler for a macro call.
MacroDefinition A macro definition.
MacroElseAssembler An assembler for collecting a #else.
MacroEndifAssembler An assembler for collecting a #endif.
MacroExpandAssembler An assembler for expanding a macro.
MacroHeaderAssembler An assembler for collecting a macro header.
MacroIfdefAssembler An assembler for collecting a macro #ifdef/#ifndef.
MacroIncludeAssembler An assembler for #include.
MacroOperator The macro operator terminal.
MacroOperatorMacroCallState The macro operator or macro call state.
MacroTable The macro definition table.
MacroTokenizer The tokenizer for the macro processor.
MacroUndefAssembler An assembler for #undef.
Node A node in a symbol tree.
Number The number terminal.
NumberState Scans numbers from the reader.
Operator The operator terminal.
OperatorState Scans the operators from the reader
Preprocessor A Java preprocessor.
Quoted The quoted terminal.
QuotedState Scans quoted tokkens from reader
RootNode The root node of a symbol tree.
Separator The seperator terminal.
SeparatorState Scans the separators from the reader
SingleLineCommentState Scans a single line comment from the reader.
SpecificTerminal Terminal with specific type and possibly value.
State Subclasses represent the states of the tokenizer.
SymbolState Baseclass for different states consisting of symbols.
TerminalAssembler An assembler for collecting a macro header.
Token A token of the indicated type and associated value.
Tokenizer Customizable tokenizer fitting Java requirements.
TokenType Instances of the class describe types of tokens.
TraditionalCommentState Scans a traditional comment from the reader.
Whitespace The whitespace terminal.
WhitespaceState Scans white spaces from the reader.
 

Package org.jsesoft.jpp Description


org.jsesoft.jpp: A Java macro preprocessor


Title: A Java macro preprocessor.

Author: JSESoft

Company: JSESoft

Description:

This is a simple preprocessor for Java (and other languages). It provides for macros and simple conditional compilation. Unicode is supported. The preprocessed code is written to a file which can be used as input for the Java compiler.

The implementation uses the sjm.parse.* packages by Steven John Metsker as described in his book "Building Parsers with Java" Addison Wesley 2001. This book comes with a CD containing the complete source code. This CD exposes the following readme:

This directory contains software and documentation associated with the book
"Building Parsers with Java," written by Steven John Metsker and published by
Addison-Wesley.

Copyright
---------
The code on the CD is free. It is copyrighted, so you may not claim that you
wrote the code. Otherwise you may use the code as you wish.

Disclaimer
----------
Neither the author nor the publisher warrants the code on this CD or in its
accompanying book to be free from defects. The author and publisher make no
representations or warranties about the fitness of this software for any
particular purpose, including the implied warranty of merchantability.

The preprocessor exposes the following weaknesses/features:

A sample include file:
#ifndef TEST_INCL
#define TEST_INCL() #{#}

// --- file test.incl
#ifdef DEBUG
#define ENTER( name )
#{
        System.out.println("Enter " + name );
#}
#define LEAVE( name )
#{
        System.out.println("Leave " + name );
        return#}
#else
#define ENTER( name ) #{#}
#define LEAVE( name ) #{ return#}
#endif

#endif

A sample Java class:
// --- file MacroTest.java

#define DEBUG() #{#}
#include "test.incl"

class MacroTest
{

    #define MAX( a, b ) #{(a)>(b)?(a):(b)#}

    int max( int n1, int n2, int n3 )
    {
        #ENTER("max")
        // do something useful
        #LEAVE("max") #MAX(n1,#MAX(n2,n3));
    }
}

The result (DEBUG defined):
// --- file MacroTest.java





// --- file test.incl







class MacroTest
{



    int max( int n1, int n2, int n3 )
    {

        System.out.println("Enter " + "max" );

        // do something useful

        System.out.println("Leave " + "max" );
        return (n1)>((n2)>(n3)?(n2):(n3))?(n1):((n2)>(n3)?(n2):(n3));
    }
}

The result (DEBUG undefined):
// --- file MacroTest.java

// #define DEBUG() #{#}



// --- file test.incl







class MacroTest
{



    int max( int n1, int n2, int n3 )
    {

        // do something useful
         return (n1)>((n2)>(n3)?(n2):(n3))?(n1):((n2)>(n3)?(n2):(n3));
    }
}

The recognized grammar:

program = definition | macroCall | macroIfdef | macroIfndef | macroUndef
          macroElse | macroEndif | anyButMacros | macroInclude ;
macroIfdef = "#ifdef"  Identifier ;
macroIfndef = "#ifndef"  Identifier ;
macroUndef = "#undef"  Identifier ;
macroElse = "#else"  ;
macroEndif = "#endif"  ;
macroInclude = "#include" String ;
definition = "#define" blanks header blanks body ;
header = Identifier paramlist ;
paramlist = "(" ( params | Empty ) ")" ;
params = blanks Identifier ( blanks "," blanks Identifier )* ;
body = "#{" ( macroCall | anyButMacros )* "#}" ;
macroCall = "#" Identifier  arglist ;
arglist = "(" args | Empty ")" ;
args = blanks arg ( blanks "," blanks arg )* ;
arg = macroCall | anyButMacros ;
anyButMacros = anything but a # token ;
blanks = Whitespace;

Copyright: (c) 2002 JSESoft


Hosted by SourceForge Logo

Package Specification

Related Documentation

For overviews, tutorials, examples, guides, and tool documentation, please see: