My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

JELAN is an embedded language analyzer for Java.

It provides facilities for constructing and invoking LL(1) language lexical analyzers and parsers. These are embedded in the sense that a language can be specified and then used for textual analysis within the same java program. This avoids the need for a separate generation phase to write and compile a lexical analyzer and parser from the language specification.

The current version is an early release that is not used for any production projects but is basically functional. It has been developed to explore an embedded approach to language analysis. See the page UsingJelan for basic JELAN usage.

The following is an example specification of a simple arithmentic expression grammar that supports '+-*/%^' operators and 'min' and 'max' functions using JELAN:

        SeqRule expression = new SeqRule("expression");  // forward
        Rule number = NumberToken.TYPE_RULE;
        Rule signedNumber = choice(
                seq(MINUS, save(NEG_NUMBER, number)),
                seq(opt(PLUS), save(NUMBER, number)));
        Rule functionOp = save(OPERATOR, choice(MAX,MIN));
        Rule function = call(seq(functionOp, OPEN, expression, COMMA, expression, CLOSE));
        Rule primary = choice(signedNumber, function, seq(OPEN, expression, CLOSE)); 
        Rule exponentiationOp = save(OPERATOR, EXP);
        Rule factor  = seq(primary, repeat(call(seq(exponentiationOp, primary))));
        Rule multiplicativeOp = save(OPERATOR, choice(STAR, DIV, MOD));
        Rule term  = seq(factor, repeat(call(seq(multiplicativeOp, factor))));
        Rule additiveOp = save(OPERATOR, choice(PLUS,MINUS));
        expression.seq(term, repeat(call(seq(additiveOp, term))));
        grammar = new ParseGrammar(seq(start(), expression, end()));
Powered by Google Project Hosting