In function ‘yylex’: 'Variable’ undeclared

后端 未结 1 492
别那么骄傲
别那么骄傲 2021-01-14 04:45

I am working with Lexical Analysis. For this I am using Flex and I fetch following Problems.

work.l

int cnt = 0,num_l         


        
相关标签:
1条回答
  • 2021-01-14 05:28

    I'm not very sure about the tab problem but one explanation is that if you don't place tab and write in the first section something like:

    int cnt = 0;
    

    Then note that in the first section you may also write "shortcuts" like:

    Digit  [0-9] 
    

    which is a regular expression that defines what digit is instead of writing all the time [0-9] to denote digit.

    So when writing int cnt = 0; in the first column without using tab is like defining the keyword int (that's probably why the error tells you did you mean int’?). So tab is a way to distinguish the two above cases.

    According to flex in order to write c/c++ code it needs to be inside: %{ ... c/c++ code... %} so for your example:

    %{
       int cnt = 0,num_lines=0,num_chars=0;
    %}
    

    So I thing the best way is to write your c-code inside %{ %}.

    0 讨论(0)
提交回复
热议问题