我正在使用 this tool 它生成一个scala文件(而不是jFlex生成的Java文件)。
但问题是它生成的字符串文字具有如下八进制:
val ZZ_CMAP_PACKED:String =
"\11\0\1\2\1\1\2\0\1\2\22\0\1\2\7\0\4\3\1\0"+
"\1\3\1\0\1\3\12\4\44\0\1\3\uffa1\0";
但这些八进制文字已被弃用
cannot be used in scala 2.13
.我想知道有没有
scalac
可以接受八进制文字的标志。我正试图以最简单的方式解决这个问题,而不必支付回购费用。
/* The following code was generated by JFlex 1.5.0-SNAPSHOT (+scala) on 7/24/14 3:35 PM */
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.5.0-SNAPSHOT (+scala)
* on 7/24/14 3:35 PM from the specification file
* <tt>Calc.lex</tt>
*/
class CalcScanner(private var zzReader : java.io.Reader) extends Iterator[CalcTokens.YYToken] {
def this(in : java.io.InputStream) = this(new java.io.InputStreamReader(in));
/** This character denotes the end of file */
val YYEOF : Int = -1;
/** initial size of the lookahead buffer */
private val ZZ_BUFFERSIZE:Int = 16384;
/** lexical states */
val YYINITIAL:Int = 0;
/**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private val ZZ_LEXSTATE:Array[Int] = Array(
0, 0
);
/**
* Translates characters to character classes
*/
private val ZZ_CMAP_PACKED:String =
"\11\0\1\2\1\1\2\0\1\2\22\0\1\2\7\0\4\3\1\0"+
"\1\3\1\0\1\3\12\4\44\0\1\3\uffa1\0";
/**
* Translates characters to character classes
*/
private val ZZ_CMAP:Array[Char] = zzUnpackCMap(ZZ_CMAP_PACKED);
/**
* Translates DFA states to action switch labels.
*/
private val ZZ_ACTION_PACKED_0:String =
"\1\0\1\1\1\2\1\3\1\4\1\5";
private def zzUnpackAction() : Array[Int] = {
val result:Array[Int] = new Array[Int](6);
var offset:Int = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private def zzUnpackAction(packed:String,offset:Int,result:Array[Int]) : Int = {
var i:Int = 0; /* index in packed string */
var j:Int = offset; /* index in unpacked array */
val l:Int = packed.length();
while (i < l) {
var count:Int = packed.charAt(i); i+= 1;
var value:Int = packed.charAt(i); i+= 1;
do { result(j) = value; j+=1; count -= 1; } while (count > 0);
}
return j;
}
private val ZZ_ACTION:Array[Int] = zzUnpackAction();
/**
* Translates a state to a row index in the transition table
*/
private val ZZ_ROWMAP_PACKED_0:String =
"\0\0\0\5\0\12\0\17\0\12\0\24";
private def zzUnpackRowMap() : Array[Int] = {
val result:Array[Int] = new Array[Int](6);
var offset:Int = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private def zzUnpackRowMap(packed:String,offset:Int,result:Array[Int]) : Int = {
var i:Int = 0; /* index in packed string */
var j:Int = offset; /* index in unpacked array */
val l:Int = packed.length();
while (i < l) {
val high:Int = packed.charAt(i) << 16; i+= 1;
result(j) = high | packed.charAt(i); i+= 1; j += 1;
}
return j;
}
private val ZZ_ROWMAP:Array[Int] = zzUnpackRowMap();
/**
* The transition table of the DFA
*/
private val ZZ_TRANS_PACKED_0:String =
"\1\2\1\3\1\4\1\5\1\6\1\2\13\0\1\4"+
"\6\0\1\6";
private def zzUnpackTrans() : Array[Int] = {
val result:Array[Int] = new Array[Int](25);
var offset:Int = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private def zzUnpackTrans(packed:String,offset:Int,result:Array[Int]) : Int = {
var i:Int = 0; /* index in packed string */
var j:Int = offset; /* index in unpacked array */
val l:Int = packed.length();
while (i < l) {
var count:Int = packed.charAt(i); i+= 1;
var value:Int = packed.charAt(i); i+= 1;
value-= 1;
do { result(j) = value; j+=1; count -= 1; } while (count > 0);
}
return j;
}
private val ZZ_TRANS:Array[Int] = zzUnpackTrans();
/* error codes */
private val ZZ_UNKNOWN_ERROR : Int = 0;
private val ZZ_NO_MATCH : Int = 1;
private val ZZ_PUSHBACK_2BIG : Int = 2;
/* error messages for the codes above */
private val ZZ_ERROR_MSG: Array[String] = Array(
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
);
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private val ZZ_ATTRIBUTE_PACKED_0:String =
"\1\0\1\1\1\11\1\1\1\11\1\1";
private def zzUnpackAttribute() : Array[Int] = {
val result:Array[Int] = new Array[Int](6);
var offset:Int = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private def zzUnpackAttribute(packed:String,offset:Int,result:Array[Int]) : Int = {
var i:Int = 0; /* index in packed string */
var j:Int = offset; /* index in unpacked array */
val l:Int = packed.length();
while (i < l) {
var count:Int = packed.charAt(i); i+= 1;
var value:Int = packed.charAt(i); i+= 1;
do { result(j) = value; j+=1; count -= 1; } while (count > 0);
}
return j;
}
private val ZZ_ATTRIBUTE:Array[Int] = zzUnpackAttribute();
/** the current state of the DFA */
private var zzState : Int = 0;
/** the current lexical state */
private var zzLexicalState : Int = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private var zzBuffer : Array[Char] = new Array(ZZ_BUFFERSIZE);
/** the textposition at the last accepting state */
private var zzMarkedPos : Int = 0;
/** the current text position in the buffer */
private var zzCurrentPos : Int = 0;
/** startRead marks the beginning of the yytext() string in the buffer */
private var zzStartRead : Int = 0;
/** endRead marks the last character in the buffer, that has been read
from input */
private var zzEndRead : Int = 0;
/** number of newlines encountered up to the start of the matched text */
private var yyline : Int = 0;
/** the number of characters up to the start of the matched text */
private var yychar : Int = 0;
/**
* the number of characters from the last newline up to the start of the
* matched text
*/
private var yycolumn : Int = 0;
/**
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
*/
private var zzAtBOL : Boolean = true;
/** zzAtEOF == true <=> the scanner is at the EOF */
private var zzAtEOF : Boolean = false;
/* user code: */
// These features are added to the Scanner class
var lookahead : CalcTokens.YYToken = null;
override def hasNext() : Boolean = {
if (lookahead == null) lookahead = yylex();
lookahead match {
case x:CalcTokens.YYEOF => false;
case x:CalcTokens.YYToken => true;
}
};
override def next() : CalcTokens.YYToken = {
if (lookahead == null) lookahead = yylex();
var result : CalcTokens.YYToken = lookahead;
lookahead = null;
result
};
def getLineNumber() : Int = yyline+1;
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
*
* @param in the java.io.Reader to read input from.
*/
/**
* Unpacks the compressed character translation table.
*
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private def zzUnpackCMap(packed:String) : Array[Char] = {
val map:Array[Char] = new Array[Char](0x10000);
var i:Int = 0; /* index in packed string */
var j:Int = 0; /* index in unpacked array */
while (i < 34) {
var count:Int = packed.charAt(i); i+= 1;
var value:Char = packed.charAt(i); i+= 1;
do { map(j) = value; j+=1; count-=1; } while (count > 0);
}
return map;
}
/**
* Refills the input buffer.
*
* @return <code>false</code>, iff there was new input.
*/
private def zzRefill() : Boolean = {
/* first: make room (if you can) */
if (zzStartRead > 0) {
System.arraycopy(zzBuffer, zzStartRead,
zzBuffer, 0,
zzEndRead-zzStartRead);
/* translate stored positions */
zzEndRead-= zzStartRead;
zzCurrentPos-= zzStartRead;
zzMarkedPos-= zzStartRead;
zzStartRead = 0;
}
/* is the buffer big enough? */
if (zzCurrentPos >= zzBuffer.length) {
/* if not: blow it up */
val newBuffer : Array[Char] = new Array(zzCurrentPos*2);
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
zzBuffer = newBuffer;
}
/* finally: fill the buffer with new input */
val numRead : Int = zzReader.read(zzBuffer, zzEndRead,
zzBuffer.length-zzEndRead);
if (numRead > 0) {
zzEndRead+= numRead;
return false;
}
// unlikely but not impossible: read 0 characters, but not at end of stream
if (numRead == 0) {
val c : Int = zzReader.read();
if (c == -1) {
return true;
} else {
zzBuffer(zzEndRead) = c toChar;
zzEndRead += 1
return false;
}
}
// numRead < 0
return true;
}
/**
* Closes the input stream.
*/
def yyclose() : Unit = {
zzAtEOF = true; /* indicate end of file */
zzEndRead = zzStartRead; /* invalidate buffer */
if (zzReader != null)
zzReader.close();
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>ZZ_INITIAL</tt>.
*
* @param reader the new input stream
*/
def yyreset(reader : java.io.Reader) : Unit = {
zzReader = reader;
zzAtBOL = true;
zzAtEOF = false;
zzEndRead = 0; zzStartRead = 0;
zzCurrentPos = 0; zzMarkedPos = 0;
yyline = 0; yychar = 0; yycolumn = 0;
zzLexicalState = YYINITIAL;
}
/**
* Returns the current lexical state.
*/
def yystate() : Int = {
zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
def yybegin(newState : Int) : Unit = {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
def yytext() : String = {
new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
def yycharat(pos : Int) : Char = {
zzBuffer(zzStartRead+pos);
}
/**
* Returns the length of the matched text region.
*/
def yylength() : Int = {
zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
private def zzScanError(errorCode:Int) : Unit = {
var message : String = null;
try {
message = ZZ_ERROR_MSG(errorCode);
} catch {
case e:ArrayIndexOutOfBoundsException =>
message = ZZ_ERROR_MSG(ZZ_UNKNOWN_ERROR);
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
def yypushback(number:Int) : Unit = {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/** Nested class to simulate multi-level break */
private case class ZZbreak(name:String) extends Throwable;
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
def yylex() : CalcTokens.YYToken =
{
var zzInput : Int = 0;
var zzAction : Int = 0;
// cached fields:
var zzCurrentPosL : Int = 0;
var zzMarkedPosL : Int = 0;
var zzEndReadL : Int = zzEndRead;
var zzBufferL : Array[Char] = zzBuffer;
var zzCMapL : Array[Char] = ZZ_CMAP;
val zzTransL:Array[Int] = ZZ_TRANS;
val zzRowMapL:Array[Int] = ZZ_ROWMAP;
val zzAttrL:Array[Int] = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
var zzR:Boolean = false;
zzCurrentPosL = zzStartRead
while (zzCurrentPosL < zzMarkedPosL) {
(zzBufferL(zzCurrentPosL)) match {
case '\u000B'
|'\u000C'
|'\u0085'
|'\u2028'
|'\u2029' => {
yyline+=1;
zzR = false;
}
case '\r' => {
yyline+=1;
zzR = true;
}
case '\n' => {
if (zzR)
zzR = false;
else {
yyline+=1;
}
}
case _ => {
zzR = false;
}
}
zzCurrentPosL += 1;
}
if (zzR) {
// peek one character ahead if it is \n (if we have counted one line too much)
var zzPeek:Boolean = false;
if (zzMarkedPosL < zzEndReadL)
zzPeek = zzBufferL(zzMarkedPosL) == '\n';
else if (zzAtEOF)
zzPeek = false;
else {
val eof:Boolean = zzRefill();
zzEndReadL = zzEndRead;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
if (eof)
zzPeek = false;
else
zzPeek = zzBufferL(zzMarkedPosL) == '\n';
}
if (zzPeek) yyline-= 1;
}
zzAction = -1;
{ val p : Int = zzMarkedPosL;
zzCurrentPosL = p; zzCurrentPos = p; zzStartRead = p;
}
zzState = ZZ_LEXSTATE(zzLexicalState);
// set up zzAction for empty match case:
var zzAttributes:Int = zzAttrL(zzState);
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
}
/* zzForAction: */ try {
while (true) {
if (zzCurrentPosL < zzEndReadL) {
zzInput = zzBufferL(zzCurrentPosL);
zzCurrentPosL += 1;
} else if (zzAtEOF) {
zzInput = YYEOF;
throw ZZbreak("zzForAction");
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
val eof:Boolean = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
throw ZZbreak("zzForAction");
}
else {
zzInput = zzBufferL(zzCurrentPosL);
zzCurrentPosL += 1;
}
}
val zzNext:Int = zzTransL(zzRowMapL(zzState) + zzCMapL(zzInput));
if (zzNext == -1) throw ZZbreak("zzForAction");
zzState = zzNext;
zzAttributes = zzAttrL(zzState);
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) throw ZZbreak("zzForAction");
}
}
} catch { case ZZbreak("zzForAction") => () }
// store back cached position
zzMarkedPos = zzMarkedPosL;
(if ( zzAction < 0 ) zzAction; else ZZ_ACTION(zzAction)) match {
case 3 => {
{
}
}
case 6 => {}
case 1 => {
{ println("Ignored characters: " + yytext);
}
}
case 7 => {}
case 5 => {
{ return CalcTokens.NUM(Integer.parseInt(yytext));
}
}
case 8 => {}
case 2 => {
{ return CalcTokens.YYCHAR('\n');
}
}
case 9 => {}
case 4 => {
{ return CalcTokens.YYCHAR(yytext.charAt(0));
}
}
case 10 => {}
case _ =>
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
{
return CalcTokens.YYEOF();
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
throw new RuntimeException("NOT REACHED");
}
}
