The fast scanner generator for Java
Clone or download
Permalink
Failed to load latest commit information.
.mvn/wrapper Format java code automatically with google-java-format (#226) Nov 4, 2017
cup-maven-plugin Minor: XML codestyle on POM (#333) Sep 18, 2018
cup Minor: XML codestyle on POM (#333) Sep 18, 2018
docs update version instructions in docs Sep 16, 2018
jflex-maven-plugin Minor: XML codestyle on POM (#333) Sep 18, 2018
jflex-unicode-maven-plugin Cleanup code for Java 7 (#253) Nov 9, 2017
jflex adjust whitespace for character reporting Sep 20, 2018
scripts Fix maven-site-plugin NoClassDefFoundError: org/apache/maven/doxia/si… Sep 18, 2018
src Let Travis deploy Maven site for jflex-maven-plugin (#266) Nov 15, 2017
testsuite Minor: XML codestyle on POM (#333) Sep 18, 2018
.gitignore Let Travis update the aggregated-java-sources branch (#318) Sep 16, 2018
.travis.yml Fix maven-site-plugin NoClassDefFoundError: org/apache/maven/doxia/si… Sep 18, 2018
CONTRIBUTING.md Update CONTRIBUTING with code style Nov 4, 2017
LICENSE.md more markdown friendly Feb 21, 2015
README.md update version instructions in docs Sep 16, 2018
RELEASE.md Document website update Sep 18, 2018
mvn-deploy.sh Minor: XML codestyle on POM (#333) Sep 18, 2018
mvnw Format java code automatically with google-java-format (#226) Nov 4, 2017
mvnw.cmd Format java code automatically with google-java-format (#226) Nov 4, 2017
pom.xml Fix maven-site-plugin NoClassDefFoundError: org/apache/maven/doxia/si… Sep 18, 2018
post-release.pl Release.md Remove deprecated sourceforge deploy (#322) Sep 17, 2018
prepare-release.pl release scripts: do not replace version info in cup-maven-plugin Sep 16, 2018

README.md

Build Status

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,

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.

Sample project: simple-maven

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 in CLI

You can also use JFlex directly from the command line:

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

Build from source

./mvnw install

Contributing

JFlex is free software, contributions are welcome. See the file CONTRIBUTING.md for instructions.