2
* STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
4
* Copyright (c) 1989-1998 by Lucent Technologies
6
* Permission to use, copy, modify, and distribute this software and its
7
* documentation for any purpose and without fee is hereby granted, provided
8
* that the above copyright notice appear in all copies and that both the
9
* copyright notice and this permission notice and warranty disclaimer appear
10
* in supporting documentation, and that the name of Lucent Technologies, Bell
11
* Labs or any Lucent entity not be used in advertising or publicity pertaining
12
* to distribution of the software without specific, written prior permission.
14
* Lucent disclaims all warranties with regard to this software, including all
15
* implied warranties of merchantability and fitness. In no event shall Lucent
16
* be liable for any special, indirect or consequential damages or any damages
17
* whatsoever resulting from loss of use, data or profits, whether in an action
18
* of contract, negligence or other tortious action, arising out of or in
19
* connection with the use or performance of this software.
21
* Taken from this URL:
22
* http://www.smlnj.org/license.html
24
* This license is compatible with the GNU GPL (see section "Standard ML of New
25
* Jersey Copyright License"):
26
* http://www.gnu.org/licenses/license-list.html#StandardMLofNJ
30
* Copyright 1996-1999 by Scott Hudson, Frank Flannery, C. Scott Ananian
33
package weka.core.parser.java_cup;
35
import weka.core.parser.java_cup.runtime.ComplexSymbolFactory;
36
import weka.core.parser.java_cup.runtime.ComplexSymbolFactory.Location;
37
import weka.core.parser.java_cup.runtime.Symbol;
38
import java.lang.Error;
39
import java.io.InputStreamReader;
51
public Lexer(ComplexSymbolFactory sf){
52
this(new InputStreamReader(System.in));
55
private StringBuffer sb;
56
private ComplexSymbolFactory symbolFactory;
57
private int csline,cscolumn;
58
public Symbol symbol(String name, int code){
59
// System.out.println("code:"+code+" "+yytext());
60
return symbolFactory.newSymbol(name, code,new Location(yyline+1,yycolumn+1-yylength()),new Location(yyline+1,yycolumn+1));
62
public Symbol symbol(String name, int code, String lexem){
63
// System.out.println("code:"+code+", lexem :"+lexem);
64
return symbolFactory.newSymbol(name, code, new Location(yyline+1, yycolumn +1), new Location(yyline+1,yycolumn+yylength()), lexem);
66
protected void emit_warning(String message){
67
ErrorManager.getManager().emit_warning("Scanner at " + (yyline+1) + "(" + (yycolumn+1) + "): " + message);
69
protected void emit_error(String message){
70
ErrorManager.getManager().emit_error("Scanner at " + (yyline+1) + "(" + (yycolumn+1) + "): " + message);
74
Newline = \r | \n | \r\n
75
Whitespace = [ \t\f] | {Newline}
78
Comment = {TraditionalComment} | {EndOfLineComment}
79
TraditionalComment = "/*" {CommentContent} \*+ "/"
80
EndOfLineComment = "//" [^\r\n]* {Newline}
81
CommentContent = ( [^*] | \*+[^*/] )*
83
ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
87
return symbolFactory.newSymbol("EOF",sym.EOF);
97
"?" { return symbol("QESTION",QUESTION); }
98
";" { return symbol("SEMI",SEMI); }
99
"," { return symbol("COMMA",COMMA); }
100
"*" { return symbol("STAR",STAR); }
101
"." { return symbol("DOT",DOT); }
102
"|" { return symbol("BAR",BAR); }
103
"[" { return symbol("LBRACK",LBRACK); }
104
"]" { return symbol("RBRACK",RBRACK); }
105
":" { return symbol("COLON",COLON); }
106
"::=" { return symbol("COLON_COLON_EQUALS",COLON_COLON_EQUALS); }
107
"%prec" { return symbol("PERCENT_PREC",PERCENT_PREC); }
108
">" { return symbol("GT",GT); }
109
"<" { return symbol("LT",LT); }
111
"{:" { sb = new StringBuffer(); csline=yyline+1; cscolumn=yycolumn+1; yybegin(CODESEG); }
112
"package" { return symbol("PACKAGE",PACKAGE); }
113
"import" { return symbol("IMPORT",IMPORT); }
114
"code" { return symbol("CODE",CODE); }
115
"action" { return symbol("ACTION",ACTION); }
116
"parser" { return symbol("PARSER",PARSER); }
117
"terminal" { return symbol("PARSER",TERMINAL); }
118
"non" { return symbol("NON",NON); }
119
"nonterminal" { return symbol("NONTERMINAL",NONTERMINAL); }
120
"init" { return symbol("INIT",INIT); }
121
"scan" { return symbol("SCAN",SCAN); }
122
"with" { return symbol("WITH",WITH); }
123
"start" { return symbol("START",START); }
124
"precedence" { return symbol("PRECEDENCE",PRECEDENCE); }
125
"left" { return symbol("LEFT",LEFT); }
126
"right" { return symbol("RIGHT",RIGHT); }
127
"nonassoc" { return symbol("NONASSOC",NONASSOC); }
128
"extends" { return symbol("EXTENDS",EXTENDS); }
129
"super" { return symbol("SUPER",SUPER); }
130
{ident} { return symbol("ID",ID,yytext()); }
135
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn),new Location(yyline+1,yycolumn+1+yylength()), sb.toString()); }
136
.|\n { sb.append(yytext()); }
140
.|\n { emit_warning("Unrecognized character '" +yytext()+"' -- ignored"); }