[Flex-help] Fwd: how to read input from a file in the scanner?
flex is a tool for generating scanners
Brought to you by:
wlestes
From: pranay a. <str...@gm...> - 2010-01-28 17:17:58
|
hi, i am using lex for the first time , i am trying to take input from a file and not from the terminal , however i am facing problem please help here is my lex file : %{ #include <stdio.h> int x=0,y=0; %} %% '\n' ++x,++y; '.' ++y; %% main() { extern FILE * yyin; yyin= fopen("/home/username/example_test","r"); yyrestart(yyin); printf("No. of lines is %d and no. of characters are %d\n",x,y); } the name of this file is test.l and the name of the input file is example_test i tried the following in command line in linux: lex test.c cc lex.yy.c -o test -ll ./test and the output is 0 for both x and y when it should be 2 and 20 respectively . Is there a mistake in declaring the global variables x ,y? -- pranay agarwal Information Technology Nit Durgapur I blog at: www.streetfi8er.blogspot.com |