The fast scanner generator for Java with full Unicode support
Clone or download
regisd Move a few classes in their modules (#504)
* Move MacroException in jflex.exceptions

* Move IntPair in jflex.base

* Move LexicalStates in jflex.scanner
Latest commit d77b7b6 Oct 21, 2018
Permalink
Failed to load latest commit information.
.mvn/wrapper Update maven wrapper 0.4.2 (#382) Sep 27, 2018
cup-maven-plugin Move classes from jflex-testsuite-... and cup-maven-plugin in package… Oct 16, 2018
cup Add java_test targets (#484) Oct 20, 2018
docs Move testsuite/manual-ex to examples (#452) Oct 17, 2018
jflex-maven-plugin Move all but Main in package jflex.core (#496) Oct 21, 2018
jflex-unicode-maven-plugin Move all but Main in package jflex.core (#496) Oct 21, 2018
jflex Move a few classes in their modules (#504) Oct 21, 2018
report-module Add README files on all root directories. (#437) Oct 11, 2018
scripts Move all but Main in package jflex.core (#496) Oct 21, 2018
src Add README files on all root directories. (#437) Oct 11, 2018
testsuite Move all but Main in package jflex.core (#496) Oct 21, 2018
third_party Update README for third_party (#459) Oct 16, 2018
.bazelproject Add .bazelproject to easily import the project in IntelliJ (#473) Oct 18, 2018
.bazelrc Add java_test targets (#484) Oct 20, 2018
.ci.bazelrc Add @SuppressWarnings("FallThrough") on generated lexer. (#454) Oct 17, 2018
.cirrus.yml Minor cirrus: rename "check" task to "bazel_version" (#503) Oct 21, 2018
.gitignore Create jflex rule for bazel (#401) Oct 2, 2018
.lgtm.yml Fix more PMD violations (#418) Oct 7, 2018
.travis.yml Fix Travis Oct 16, 2018
CODEOWNERS Add owners file (#423) Oct 8, 2018
LICENSE.md Copy JFlex license to root directory. Sep 30, 2018
README.md Add Cirrus-CI badge on README (#465) Oct 17, 2018
RELEASE.md update release instructions Sep 21, 2018
WORKSPACE Use cup.bzl from bazel_rules (#466) Oct 18, 2018
mvn-deploy.sh Fix lint violations on *.sh (#427) Oct 10, 2018
mvnw Update maven wrapper 0.4.2 (#382) Sep 27, 2018
mvnw.cmd Update maven wrapper 0.4.2 (#382) Sep 27, 2018
pom.xml Revert "Use Autovalue (#433)" Oct 14, 2018
post-release.pl Create module jflex.base (#502) Oct 21, 2018
prepare-release.pl Create module jflex.base (#502) Oct 21, 2018

README.md

Build status Bazel build status Maven central

JFlex

JFlex is a lexical analyzer generator (also known as scanner generator) for Java.

JFlex takes as input a specification with a set of regular expressions and corresponding actions. It generates Java source of a lexer that reads input, matches the input against the regular expressions in the spec file, and runs the corresponding action if a regular expression matched. Lexers usually are the first front-end step in compilers, matching keywords, comments, operators, etc, and generating an input token stream for parsers.

JFlex lexers are based on deterministic finite automata (DFAs). They are fast, without expensive backtracking.

Modules

The top level directory of the JFLex git repository contains:

  • cup A copy of the CUP runtime
  • cup-maven-plugin A simple Maven plugin to generate a parser with CUP.
  • docs the Markdown sources for the user manual
  • jflex JFlex, the scanner/lexer generator for Java
  • jflex-maven-plugin the JFlex maven plugin, that helps to integrate JFlex in your project
  • jflex-unicode-plugin the JFlex unicode maven plugin, used for compiling JFlex
  • testsuite the regression test suite for JFlex,
  • third_party third-party librairies used by examples of the Bazel build system

Usage

For documentation and more information see the JFlex documentation and the wiki.

Usage with Maven

  1. Place grammar files in src/main/flex/ directory.

  2. Extend the project POM build section with the maven-jflex-plugin

  <build>
    <plugins>
      <plugin>
        <groupId>de.jflex</groupId>
        <artifactId>jflex-maven-plugin</artifactId>
        <version>1.7.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  1. Voilà: Java code is produced in target/generated-sources/ during the generate-sources phase (which happens before the compile phase) and included in the compilation scope.

Usage with ant

  1. Define ant task
<taskdef classname="jflex.anttask.JFlexTask" name="jflex"
         classpath="path-to-jflex.jar"/>
  1. Use it
<jflex file="src/grammar/parser.flex" destdir="build/generated/"/>
<javac srcdir="build/generated/" destdir="build/classes/"/>

Usage with Bazel

We provide a jflex rule

load("@jflex_rules//jflex:jflex.bzl", "jflex")
jflex(
    name = "",           # Choose a rule name
    srcs = [],           # Add input lex specifications
    outputs = [],        # List expected generated files
)

Usage in CLI

You can also use JFlex directly from the command line:

jflex/bin/jflex src/grammar/parser.flex

Or:

java -jar jflex-full-1.7.0.jar -d output src/grammar/parser.flex

Other build tools

See Build tool plugins.

Examples

Have a look at the sample project: simple and other examples.

Build from source

./mvnw install

Contributing

JFlex is free software, contributions are welcome. See the Contributing page for instructions.