forked from JavaTX/JavaCompilerCore
187 lines
8.2 KiB
Plaintext
Executable File
187 lines
8.2 KiB
Plaintext
Executable File
/********************************************
|
||
* file: JavaLexer.lex *
|
||
* *
|
||
* enth<74>lt die JLex-Spezifikation f<>r die *
|
||
* Generierung des lexical analyzers *
|
||
* *
|
||
********************************************/
|
||
|
||
// user code:
|
||
package mycompiler.myparser;
|
||
|
||
%%
|
||
|
||
%char
|
||
%line
|
||
|
||
%{
|
||
Token token;
|
||
%}
|
||
|
||
%public
|
||
%class JavaLexer
|
||
%type boolean
|
||
%eofval{
|
||
return false;
|
||
%eofval}
|
||
|
||
ws = [ \t\r\n\b\015]+
|
||
%state commentblock
|
||
%state commentsingleline
|
||
%%
|
||
|
||
abstract {this.token = new Token(JavaParser.ABSTRACT, yytext(), yyline, yychar);return true;}
|
||
boolean {this.token = new Token(JavaParser.BOOLEAN, yytext(), yyline, yychar);return true;}
|
||
break {this.token = new Token(JavaParser.BREAK, yytext(), yyline, yychar);return true;}
|
||
case {this.token = new Token(JavaParser.CASE, yytext(), yyline, yychar);return true;}
|
||
catch {this.token = new Token(JavaParser.CATCH, yytext(), yyline, yychar);return true;}
|
||
char {this.token = new Token(JavaParser.CHAR, yytext(), yyline, yychar);return true;}
|
||
class {this.token = new Token(JavaParser.CLASS, yytext(), yyline, yychar);return true;}
|
||
continue {this.token = new Token(JavaParser.CONTINUE, yytext(), yyline, yychar);return true;}
|
||
default {this.token = new Token(JavaParser.DEFAULT, yytext(), yyline, yychar);return true;}
|
||
do {this.token = new Token(JavaParser.DO, yytext(), yyline, yychar);return true;}
|
||
else {this.token = new Token(JavaParser.ELSE, yytext(), yyline, yychar);return true;}
|
||
extends {this.token = new Token(JavaParser.EXTENDS, yytext(), yyline, yychar);return true;}
|
||
final {this.token = new Token(JavaParser.FINAL, yytext(), yyline, yychar);return true;}
|
||
finally {this.token = new Token(JavaParser.FINALLY, yytext(), yyline, yychar);return true;}
|
||
for {this.token = new Token(JavaParser.FOR, yytext(), yyline, yychar);return true;}
|
||
if {this.token = new Token(JavaParser.IF, yytext(), yyline, yychar);return true;}
|
||
instanceof {this.token = new Token(JavaParser.INSTANCEOF, yytext(), yyline, yychar);return true;}
|
||
interface {this.token = new Token(JavaParser.INTERFACE, yytext(), yyline, yychar);return true;}
|
||
int {this.token = new Token(JavaParser.INT, yytext(), yyline, yychar);return true;}
|
||
implements {this.token = new Token(JavaParser.IMPLEMENTS, yytext(), yyline, yychar);return true;}
|
||
new {this.token = new Token(JavaParser.NEW, yytext(), yyline, yychar);return true;}
|
||
package {this.token = new Token(JavaParser.PACKAGE, yytext(), yyline, yychar);return true;}
|
||
import {this.token = new Token(JavaParser.IMPORT, yytext(), yyline, yychar);return true;}
|
||
private {this.token = new Token(JavaParser.PRIVATE, yytext(), yyline, yychar);return true;}
|
||
protected {this.token = new Token(JavaParser.PROTECTED, yytext(), yyline, yychar);return true;}
|
||
public {this.token = new Token(JavaParser.PUBLIC, yytext(), yyline, yychar);return true;}
|
||
return {this.token = new Token(JavaParser.RETURN, yytext(), yyline, yychar);return true;}
|
||
static {this.token = new Token(JavaParser.STATIC, yytext(), yyline, yychar);return true;}
|
||
super {this.token = new Token(JavaParser.SUPER, yytext(), yyline, yychar);return true;}
|
||
switch {this.token = new Token(JavaParser.SWITCH, yytext(), yyline, yychar);return true;}
|
||
this {this.token = new Token(JavaParser.THIS, yytext(), yyline,yychar);return true;}
|
||
throw {this.token = new Token(JavaParser.THROW, yytext(), yyline, yychar);return true;}
|
||
throws {this.token = new Token(JavaParser.THROWS, yytext(), yyline, yychar);return true;}
|
||
try {this.token = new Token(JavaParser.TRY, yytext(), yyline, yychar);return true;}
|
||
void {this.token = new Token(JavaParser.VOID, yytext(), yyline, yychar);return true;}
|
||
while {this.token = new Token(JavaParser.WHILE, yytext(), yyline, yychar);return true;}
|
||
|
||
"//" {yybegin(commentsingleline);}
|
||
"/*" {yybegin(commentblock);}
|
||
<commentblock> "*/" {yybegin(YYINITIAL);}
|
||
<commentblock> [^\*]* {}
|
||
<commentblock> "*" {}
|
||
<commentsingleline> [\t\r\n\b\015]+ {yybegin(YYINITIAL);}
|
||
<commentsingleline> [^\\t\r\n\b\015]+ {}
|
||
|
||
[1-9][0-9]*[L]? {
|
||
String lexem = yytext();
|
||
if(lexem.endsWith("L"))
|
||
{
|
||
lexem = lexem.substring(0, lexem.length() - 1);
|
||
this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
else
|
||
{
|
||
this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
}
|
||
0[xX][0-9a-fA-F]+[L]? {
|
||
String lexem = yytext();
|
||
if(lexem.endsWith("L"))
|
||
{
|
||
lexem = lexem.substring(0, lexem.length() - 1);
|
||
this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
else
|
||
{
|
||
this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
}
|
||
0[0-7]*[L]? {
|
||
String lexem = yytext();
|
||
if(lexem.endsWith("L"))
|
||
{
|
||
lexem = lexem.substring(0, lexem.length() - 1);
|
||
this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
else
|
||
{
|
||
this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true;
|
||
}
|
||
}
|
||
[1-9][0-9]*[.]?[0-9]*[f] {
|
||
this.token = new Token(JavaParser.FLOATLITERAL, yytext(), yyline, yychar);return true;
|
||
}
|
||
|
||
[1-9][0-9]*[.][0-9]* {
|
||
this.token = new Token(JavaParser.DOUBLELITERAL, yytext(), yyline, yychar);return true;
|
||
}
|
||
|
||
true|false {
|
||
this.token = new Token(JavaParser.BOOLLITERAL, yytext(), yyline, yychar);return true;
|
||
}
|
||
null {
|
||
this.token = new Token(JavaParser.JNULL, yytext(), yyline, yychar);return true;
|
||
}
|
||
\'[a-zA-Z0-9!@#$%\&*\(\),\<.\>/\?;:]\' {
|
||
this.token = new Token(JavaParser.CHARLITERAL, yytext(), yyline, yychar);return true;
|
||
}
|
||
\"[a-zA-Z0-9!@#$%^&*\(\),\<.\>/\?;:\ ]*\" {
|
||
this.token = new Token(JavaParser.STRINGLITERAL, yytext(), yyline, yychar);return true;
|
||
}
|
||
[a-zA-Z$_][a-zA-Z0-9$_]* {
|
||
this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true;
|
||
}
|
||
[()\{\}\[\];,.] {
|
||
this.token = new Token(JavaParser.BRACE,yytext().charAt(0), yyline, yychar);return true;
|
||
}
|
||
[=><!~?:] {
|
||
this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true;
|
||
}
|
||
"==" { this.token = new Token(JavaParser.EQUAL, yytext(), yyline, yychar);return true;}
|
||
"<=" { this.token = new Token(JavaParser.LESSEQUAL, yytext(), yyline, yychar);return true;}
|
||
">=" {this.token = new Token(JavaParser.GREATEREQUAL, yytext(), yyline, yychar);return true;}
|
||
"!=" {this.token = new Token(JavaParser.NOTEQUAL, yytext(), yyline, yychar);return true;}
|
||
"||" {this.token = new Token(JavaParser.LOGICALOR, yytext(), yyline, yychar);return true;}
|
||
"&&" {this.token = new Token(JavaParser.LOGICALAND, yytext(), yyline, yychar);return true;}
|
||
"++" {this.token = new Token(JavaParser.INCREMENT, yytext(), yyline, yychar);return true;}
|
||
"--" {this.token = new Token(JavaParser.DECREMENT, yytext(), yyline, yychar);return true;}
|
||
|
||
[+\-*/&|^%] {
|
||
this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true;
|
||
}
|
||
//"<<" {this.token = new Token(JavaParser.SHIFTLEFT, yytext(), yyline, yychar);return true;}
|
||
//">>" {this.token = new Token(JavaParser.SHIFTRIGHT, yytext(), yyline, yychar);return true;}
|
||
//">>>" {this.token = new Token(JavaParser.UNSIGNEDSHIFTRIGHT, yytext(), yyline, yychar);return true;}
|
||
"+=" {this.token = new Token(JavaParser.PLUSEQUAL, yytext(), yyline, yychar);return true;}
|
||
"-=" {this.token = new Token(JavaParser.MINUSEQUAL, yytext(), yyline, yychar);return true;}
|
||
"*=" {this.token = new Token(JavaParser.TIMESEQUAL, yytext(), yyline, yychar);return true;}
|
||
"/=" {this.token = new Token(JavaParser.DIVIDEEQUAL, yytext(), yyline, yychar);return true;}
|
||
"&=" {this.token = new Token(JavaParser.ANDEQUAL, yytext(), yyline, yychar);return true;}
|
||
"|=" {this.token = new Token(JavaParser.OREQUAL, yytext(), yyline, yychar);return true;}
|
||
"^=" {this.token = new Token(JavaParser.XOREQUAL, yytext(), yyline, yychar);return true;}
|
||
"%=" {this.token = new Token(JavaParser.MODULOEQUAL, yytext(), yyline, yychar);return true;}
|
||
//"<<=" {this.token = new Token(JavaParser.SHIFTLEFTEQUAL, yytext(), yyline, yychar);return true;}
|
||
//">>=" {this.token = new Token(JavaParser.SIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;}
|
||
//">>>=" {this.token = new Token(JavaParser.UNSIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;}
|
||
{ws}|\n { /* System.out.print(yytext()); */ }
|
||
\\.\n {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());}
|
||
"->" {this.token = new Token(JavaParser.LAMBDAASSIGNMENT, yytext(), yyline, yychar);return true;}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|