Search code examples
bisonflex-lexeryacc

Flex scan only the first one


So i have this piece of code ,im trying to make it repeatedly scaning a file , line after line but it scan only for the first one.

Any clue why this happens ? Thanks.

%option noyywrap
%option yylineno

%{

#include <stdio.h>
#include <cstdio>
#include "token.h"
using namespace std;
#include <iostream>

void yyerror(char *s);

%}

%%
([0,1,8,9]{1})([0-9]{2})([0,1,2]{1})([0-9]{2})  { printf("CSE  Line : %d \n",yylineno); return NUMBER;}
([5-9]|10)["."][0-9]{1,2}   { printf("MO : \n"); return MO;}
\t  { printf("Tab \n"); return TAB;}
\n  { printf("Line cutter \n"); return ALGR;}
%%

void yyerror (char *s) {

   fprintf (stderr, "%s\n", s);

 }

int main(){

    FILE *myFile = fopen("input.txt","r");
    if(!myFile){
        printf("Error Opening \n") ; 
        return -1;
    }
    yyin = myFile; 
    yylex();

}

Solution

  • yyin = myFile; 
    while(yylex());
    fclose(yyin);
    

    Found the solution.Needed a while outside of lex();