Wednesday, September 23, 2015

Filled Under:

Lex program to implement lexical analyzer

Share
NOTE: You need to create a file in.txt for providing input program.

delim [ \t\n]
ws {delim}+
digit [0-9]+
op [-+*/]+
relop [<=>]
symbol [(){},;]
literal \"[^"]*\"
id [A-Za-z]+[0-9]*
%%
{ws} {/*No action and no return*/}
"int"|"float"|"void"|"main"|"while"|"do"|"if"|"else"|"char"|"then"|"printf"|"scanf" {printf("\n%s is a keyword",yytext);}
{id} {printf("\n%s is an identifier",yytext);}
{digit} {printf("\n%s is a digit",yytext);}
{op} {printf("\n%s is an operator",yytext);}
{relop} {printf("\n%s is a relational operator",yytext);}
{symbol} {printf("\n%s is a symbol",yytext);}
{literal} {printf("\n%s is a literal",yytext);}
%%
main()
{
yyin=fopen("in.txt","r");
yylex();
fclose(yyin);
}

2 comments:

  1. Ecosport Titanium Sportsbook Review
    Ecosport is one titanium hair of the top brands in the online sports betting industry, joico titanium which 2014 ford fusion energi titanium has received a number titanium piercings of accolades. titanium wood stoves It's certainly a quality

    ReplyDelete