JFlex is an open source grammar language created in 2003.
#465on PLDB | 21Years Old | 2Repos |
git clone https://github.com/jflex-de/jflex
JFlex is a lexical analyzer generator (also known as scanner generator) for Java, written in Java.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright (C) 1998-2015 Gerwin Klein <lsf@jflex.de> *
* All rights reserved. *
* *
* License: BSD *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Java 1.2 language lexer specification */
/* Use together with unicode.flex for Unicode preprocesssing */
/* and java12.cup for a Java 1.2 parser */
/* Note that this lexer specification is not tuned for speed.
It is in fact quite slow on integer and floating point literals,
because the input is read twice and the methods used to parse
the numbers are not very fast.
For a production quality application (e.g. a Java compiler)
this could be optimized */
import java_cup.runtime.*;
%%
%public
%class Scanner
%implements sym
%unicode
%line
%column
%cup
%cupdebug
%{
StringBuilder string = new StringBuilder();
private Symbol symbol(int type) {
return new JavaSymbol(type, yyline+1, yycolumn+1);
}
private Symbol symbol(int type, Object value) {
return new JavaSymbol(type, yyline+1, yycolumn+1, value);
}
/**
* assumes correct representation of a long value for
* specified radix in scanner buffer from <code>start</code>
* to <code>end</code>
*/
private long parseLong(int start, int end, int radix) {
long result = 0;
long digit;
for (int i = start; i < end; i++) {
digit = Character.digit(yycharat(i),radix);
result*= radix;
result+= digit;
}
return result;
}
%}
/* main character classes */
LineTerminator = \r|\n|\r\n
InputCharacter = [^\r\n]
WhiteSpace = {LineTerminator} | [ \t\f]
/* comments */
Comment = {Tradi
Feature | Supported | Example | Token |
---|---|---|---|
Comments | ✓ | /* A comment */ | |
MultiLine Comments | ✓ | /* A comment */ | /* */ |
Semantic Indentation | X |