i'm trying to use JLex to define some regex.
i want it to read a text and return how many char and line there is inthe file....
////////////////////////////////////////////////////////
%%
%{ public static void main(String argv[]) throws java.io.IOException {
MyLexer yy = new MyLexer(System.in);
while (true){
yy.yylex();
}
}
%}
%notunix
%type void
%class MyLexer
%eofval{ return;
%eofval}
IDENTIFIER = [a-zA-z_][a-zA-Z0-9_]*
%%
"int" { System.out.println("INT recognized"}
{IDENTIFIER} { System.out.println("ID is ..." + yytext());}
\r\n {}
. {}
////////////////////////////////////////////////////////
i wrote a simple lex that just reads from user input to outputs the identifier and when int is typed
1)i know i have to use %char and %line in the JLex directive to output the number of char and line
idunno what to code in the regular expression rule part
2)two how do i read from a file in the java code section
idon't know how to do stream
plz help
i want it to read a text and return how many char and line there is inthe file....
////////////////////////////////////////////////////////
%%
%{ public static void main(String argv[]) throws java.io.IOException {
MyLexer yy = new MyLexer(System.in);
while (true){
yy.yylex();
}
}
%}
%notunix
%type void
%class MyLexer
%eofval{ return;
%eofval}
IDENTIFIER = [a-zA-z_][a-zA-Z0-9_]*
%%
"int" { System.out.println("INT recognized"}
{IDENTIFIER} { System.out.println("ID is ..." + yytext());}
\r\n {}
. {}
////////////////////////////////////////////////////////
i wrote a simple lex that just reads from user input to outputs the identifier and when int is typed
1)i know i have to use %char and %line in the JLex directive to output the number of char and line
idunno what to code in the regular expression rule part
2)two how do i read from a file in the java code section
idon't know how to do stream
plz help