BEX a BNF to Java source compiler

BEX compiles LL(k) grammars to Java source code. The parser is designed to operate on "literal non-literal" or "literal white-space literal" grammars. That means grammars as for Java, C++ or other programming languages. Furthermore there are built in functions to detect strings, characters, numbers and comments.

BEX consists from two parts:

Both is in one archive, since the compiler uses the same classes.

All software is published under our NON COMMERCIAL LICENSE. If you plan to use any of this software in a commercial product, contact the author for conditions and permissions.

Read, understand and accept the disclaimer before download db_bex.zip.

To get it work properly read the provided document and understand the examples.

DateDescription
2000-08-31version 1.7
  • bugfix: all functions using unwind(), which puts the last token back into input (char) stream, and parses the token again, did not modify the top of the token stack.
  • 2000-08-10version 1.6
  • bugfix: source tracking for error reports tracked not only last line, but all lines.
  • bugfix: redesigned tokenizer:
    since any alpha-literal is accepted and a new tokens are generated,
    there was a problem with keywords consisting from alpha and non-alpha characters.
    e.g. having 'div' and 'div=' as keywords:
      'div=' was recognized as 'div' since the alpha-literal was used.
    now:
      'div=' is recognized correctly
  • new: added IMPORT = <nonterminal>; to add import statements to generated source.
  • 2000-07-18version 1.5
  • change: enableStrings() disableStrings() also affects useChar
  • 2000-06-12version 1.4
  • bugfix: sometimes EOF was unread as char 0xff.
  • 2000-05-21version 1.3
  • bugfix: sometimes a white space was not properly unread.
  • 2000-04-29version 1.2
  • some internal redesign to enhance the parsers capabilities
  • 2000-02-20version 1.1
  • first public release
  • A short introduction

    /*
     * 1st example how to evaluate simple mathematic expressions
     */
    
    Expression = Number            // starts with a number
                 ( ( '+'           // accept operator +, -, *, / and ^
                   | '-'
                   | '*'
                   | '/'
                   | '^'
                   )
                   Expression     // followed by an expression
                 ) ?
    ;
    
    You will miss the definition for Number. There is none: Number is a function which accepts integer values in decimal, hexadecimal or octal format. We consider Number to be a terminal.
    The shortest input data for an Expression is a single Number. Using a recursion, the grammar also accepts a Number followed by an Operator and an Expression again.

    This example is provided as file Calc1.bnf. To get it compiled use

    You'll get a new file named Calc1Lex.java. To get it compiled you need the base class Calc1.java for Calc1Lex.java. Calc1.java contains:
    class Calc1 extends de.bb.bex.BnfLex
    {
      boolean isNumber() throws Exception
      {
        if (type != LX_INT) // is current token an integer value?
          return false;     // no -> return false
        next();             // consume current token, setup next token!
        return true;        // success!
      }
    }
    
    Now you are able to compile both classes and you get an program which verifies the content of files: A valid input is:
    data.txt:
    	1+2 ^ 3*4-4
    
    java -classpath %CLASSPATH%;bex.zip Calc1Lex data.txt
    
    An invalid input is:
    data.txt:
    	1+2 ^ 3%4-4
    
    java -classpath %CLASSPATH%;bex.zip Calc1Lex data.txt
    error: java.io.IOException: unexpected '%' at line 1(8): 1+2 ^ 3%
    
    Note: Any white spaces are accepted!

    You are ready to browse through the other examples.

    DateGrammars
    2000-06-25Grammar for WmlScript is available here
    2000-04-29Grammar for JAVA is available here

    Disclaimer of Warranty

    Limitation of Liability

    Copyright