[03 - JFlex Scanner] Get TestASScanner1 to work
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex 4
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.jflexasscanner;
|
||||
|
||||
%%
|
||||
|
||||
%class JFlexASScanner
|
||||
%function nextToken
|
||||
%type Token
|
||||
|
||||
%unicode
|
||||
%line
|
||||
%column
|
||||
%public
|
||||
%final
|
||||
|
||||
%xstate FRAC, EXP, STR, NULL, ID, NUM
|
||||
|
||||
%{
|
||||
String idValue = "";
|
||||
int intValue = 0;
|
||||
%}
|
||||
|
||||
WhiteSpace = [ \t\b\r\n]+
|
||||
SmallChars = [a-z]
|
||||
CapitalChars = [A-Z]
|
||||
Numbers = [0-9]
|
||||
AllChars = [a-zA-Z0-9]
|
||||
|
||||
%eofval{
|
||||
return new Token(Token.EOF, "", yyline+1, yycolumn+1);
|
||||
%eofval}
|
||||
|
||||
%%
|
||||
//[^] { return new Token(Token.INVALID, yytext(), yyline+1, yycolumn+1); }
|
||||
{WhiteSpace} { /* Ignore */ }
|
||||
<YYINITIAL> {
|
||||
"null" { return new Token(Token.NULL, yytext(), yyline+1, yycolumn+1); }
|
||||
{AllChars} { yybegin(ID);
|
||||
idValue = yytext(); System.out.println("BEGIN ID <"+idValue+">"); }
|
||||
{Numbers} { yybegin(NUM);
|
||||
intValue = yycharat(0)-'0'; }
|
||||
[\[] { return new Token(Token.LSBR, yytext(), yyline+1, yycolumn+1); }
|
||||
[\]] { return new Token(Token.RSBR, yytext(), yyline+1, yycolumn+1); }
|
||||
[,] { return new Token(Token.COMMA, yytext(), yyline+1, yycolumn+1); }
|
||||
}
|
||||
|
||||
<NUM> {
|
||||
{Numbers} { intValue = intValue * 10 + yycharat(0) - '0'; }
|
||||
{SmallChars} | {CapitalChars} { yybegin(ID); idValue = String.valueOf(intValue); yypushback(1); }
|
||||
[^] { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new NumToken(String.valueOf(intValue), yyline+1, yycolumn+1); }
|
||||
|
||||
<ID> {
|
||||
{AllChars} { idValue += yytext(); }
|
||||
}
|
||||
<ID> [^] { yybegin(YYINITIAL);System.out.println("PUSHBACK BEFORE <"+yytext()+">");
|
||||
yypushback(1); System.out.println("PUSHBACK AFTER <"+yytext()+">"); System.out.println("LINE <"+yyline+"> / COLUMN <"+yycolumn+">");
|
||||
return new Token(Token.ID, idValue, yyline+1, yycolumn); }
|
||||
|
||||
|
||||
[^] { return new Token(Token.INVALID, yytext(), yyline+1, yycolumn+1);
|
||||
/*throw new Error("Illegal character <" + yytext() + ">"); */}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user