clex

How to end input in lex when executing on CMD win7


how to execute code after yylex(); command

I have the same problem as the above question, not able to execute anything below the yylex()

    %{
       #include<stdio.h>
       int vowel=0;
       int cons=0;
    %}
    %%
   "a"|"e"|"i"|"o"|"u"|"A"|"E"|"I"|"O"|"U" {printf("is a VOWEL");vowel++;}
    [a-zA-z] {printf("Is a Consonant");cons++;}
    %%
  int yywrap()
  {
   return 1;
  }
  main()
  {
   printf("Enter String\n");
  yylex();
   printf("vowel=%d and Consonent=%d",vowel,cons);//how to execute this statement?
    }

I am on win7 and the answer says to end your input using Ctrl+d(tried does not work in CMD).

So how to end your input which enables the next statement to execute?


Solution

  • So how to end your input which enables the next statement to execute?

    yylex() will continue to wait on and process input until it sees end-of-file or it executes an action that performs an explicit return.

    The Windows analog of Ctrl+D is Ctrl+Z, so you could try that, but it would be much better to configure the lexer with a rule that makes it return. For example, if you only need to lex a single line of input (per call), then you might make it return when it reads a newline. Do note, however, that yylex() may buffer input characters, which can cause some unprocessed input to be lost if you attempt to read the same input file after yylex() returns, except by calling yylex() itself again.