lex file not executing

30 views Asked by At

I was tring to doing my assignment. That is "Write a program using YACC specifications to implement syntax analysis phase of compiler to validate type and syntax of variable declaration in C program." Here I have Assi6.l file with code.

Assi6.l file

%{
    #include<stdio.h>
    #include<y.tab.h>
    int a;
%}
datatype int|float|char|string|boolean
digits [0-9]
letters [A-Za-z]
identifiers {letters}({letters}|{digits})*
comma ,
SC ;
%%
{datatype}{return datatype;}
{identifiers}{return identifiers;}
{comma} {return comma;}
{SC} {return SC;}
\n {return 0;}
%%

Output: enter image description here

Can anyone tell me what is wrong at line 13. I am not getting anything

1

There are 1 answers

1
Chris Dodd On

You need a space (or tab) between the pattern and the action in the rule. As it is, lex thinks the pattern on line 13 is {datatype}{return.

Add a space after the pattern:

{datatype} {return datatype;}

which makes the pattern be just {datatype}