Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java JLex

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
CA
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top