1 // JFlex parser specification written by
4 // University of California, Irvine
6 // Technische Universitaet Muenchen
7 // Fakultaet fuer Informatik
9 import java_cup.runtime.Symbol;
10 import java_cup.runtime.ComplexSymbolFactory;
11 import java_cup.runtime.ComplexSymbolFactory.Location;
24 StringBuffer string = new StringBuffer();
25 public Lexer(java.io.Reader in, ComplexSymbolFactory sf){
29 ComplexSymbolFactory symbolFactory;
31 private Symbol symbol(String name, int sym) {
32 return symbolFactory.newSymbol(name, sym, new Location(yyline+1,yycolumn+1,yychar), new Location(yyline+1,yycolumn+yylength(),yychar+yylength()));
35 private Symbol symbol(String name, int sym, Object val) {
36 Location left = new Location(yyline+1,yycolumn+1,yychar);
37 Location right= new Location(yyline+1,yycolumn+yylength(), yychar+yylength());
38 return symbolFactory.newSymbol(name, sym, left, right,val);
40 private Symbol symbol(String name, int sym, Object val,int buflength) {
41 Location left = new Location(yyline+1,yycolumn+yylength()-buflength,yychar+yylength()-buflength);
42 Location right= new Location(yyline+1,yycolumn+yylength(), yychar+yylength());
43 return symbolFactory.newSymbol(name, sym, left, right,val);
45 private void error(String message) {
46 System.out.println("Error at line "+(yyline+1)+", column "+(yycolumn+1)+" : "+message);
51 return symbolFactory.newSymbol("EOF", EOF, new Location(yyline+1,yycolumn+1,yychar), new Location(yyline+1,yycolumn+1,yychar+1));
55 Ident = [a-zA-Z$_] [a-zA-Z0-9$_\[\]]*
57 new_line = \r|\n|\r\n;
59 white_space = {new_line} | [ \t\f]
67 "int" { return symbol("int",TYPE, "int" ); }
68 "short" { return symbol("short",TYPE, "short" ); }
69 "byte" { return symbol("byte",TYPE, "byte" ); }
70 "long" { return symbol("long",TYPE, "long" ); }
71 "float" { return symbol("float",TYPE, "float" ); }
72 "double" { return symbol("double",TYPE, "double" ); }
73 "char" { return symbol("char",TYPE, "char" ); }
74 "string" { return symbol("string",TYPE, "String" ); }
75 "String" { return symbol("String",TYPE, "String" ); }
76 "boolean" { return symbol("boolean",TYPE, "boolean" ); }
77 "void" { return symbol("void",TYPE, "void" ); }
78 "public" { return symbol("public",PUBLIC); }
79 "interface" { return symbol("interface",INTERFACE); }
80 "capability" { return symbol("capability",CAPABILITY); }
81 "description" { return symbol("description",DESCRIPTION); }
82 "method" { return symbol("method",METHOD); }
83 "requires" { return symbol("requires",REQUIRES); }
84 "with" { return symbol("with",WITH); }
85 "as" { return symbol("as",AS); }
86 "enum" { return symbol("enum",ENUM); }
87 "struct" { return symbol("struct",STRUCT); }
90 {Ident} { return symbol("Identifier",IDENT, yytext()); }
104 \" { string.setLength(0); yybegin(STRING); }
105 ";" { return symbol("semicolon",SEMICOLON); }
106 "," { return symbol("comma",COMMA); }
107 "(" { return symbol("(",LPAR); }
108 ")" { return symbol(")",RPAR); }
109 "<" { return symbol("<",LANG); }
110 ">" { return symbol(">",RANG); }
111 "{" { return symbol("{",BEGIN); }
112 "}" { return symbol("}",END); }
113 "=" { return symbol("=",ASSIGN); }
115 {white_space} { /* ignore */ }
120 \" { yybegin(YYINITIAL);
121 return symbol("StringConst",STRINGCONST,string.toString(),string.length()); }
122 [^\n\r\"\\]+ { string.append( yytext() ); }
123 \\t { string.append('\t'); }
124 \\n { string.append('\n'); }
126 \\r { string.append('\r'); }
127 \\\" { string.append('\"'); }
128 \\ { string.append('\\'); }
133 .|\n { /* throw new Error("Illegal character <"+ yytext()+">");*/
134 error("Illegal character <"+ yytext()+">");