/* just like Unix wc */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
\n { chars++; lines++; }
. { chars++; }
%%
main(int argc, char **argv)
{
yylex();
printf("%8d%8d%8d\n", lines, words, chars);
}
command on terminal Example
$ flex wordcount.l
$ cc lex.yy.c -lfl/ gcc 0r g++ lex.yy.c -lfl
$ ./a.out
The boy stood on the burning deck
shelling peanuts by the peck
^D
2 12 63
$
/*valid mobile no*/
{%
#include<iostream>
using namespace std;
%}
%%
[1-9][0-9]{9} { cout<<Mobile Number Valid ;}
.+ {cout<<Mobile Number Invalid ;}
%%
void main() {
cout<<Enter Mobile Number ;
yylex();
cout<<\n ;
}
%%
/*valid url check*/
{%
#include<iostream>
using namespace std;
%}
((http)|(ftp))s?:\/\/[a-zA-Z0-9]{2,}(\.[a-z]{2,})+(\/[a-zA-Z0-9+=?]*)* { cout<<URL Valid ;}
.+ {cout<<URL Invalid ;}
%%
void main() {
cout<<Enter URL : ;
yylex();
cout<<\n ;
}
/* recognize tokens for the calculator and print them out */
%%
"+" { printf("PLUS\n"); }
"-" { printf("MINUS\n"); }
"*" { printf("TIMES\n"); }
"/" { printf("DIVIDE\n"); }
"|" { printf("ABS\n"); }
[0-9]+ { printf("NUMBER %s\n", yytext); }
\n { printf("NEWLINE\n"); }
[ \t] { }
. { printf("Mystery character %s\n", yytext); }
%%
For Unzip:
tar zxvf fileNameHere.tgz
Command For running Calculator: (within the same directory where file exist.)
yacc -b parse -dv calc.y
flex calc.l
g++ lex.yy.c parse.tab.c -ly -ll
Book for Developing calculator
http://web.iitd.ac.in/~sumeet/flex__bison.pdf
Lab ViVA from Next week. Prepare yourself and write the problem not understand in lab.
To write a program for implementing Symbol Table using C++.
ALGORITHM:
Step1: Start the program for performing insert, display, delete, search and modify option in symbol table
Step2: Define the structure of the Symbol Table
Step3: Enter the choice for performing the operations in the symbol Table
Step4: If the entered choice is 1, search the symbol table for the symbol to be inserted. If the symbol is
already present, it displays “Duplicate Symbol”. Else, insert the symbol and the corresponding address in
the symbol table.
Step5: If the entered choice is 2, the symbols present in the symbol table are displayed.
Step6: If the entered choice is 3, the symbol to be deleted is searched in the symbol table.
Step7: If it is not found in the symbol table it displays “Label Not found”. Else, the symbol is deleted.
Step8: If the entered choice is 5, the symbol to be modified is searched in the symbol table.
article.nadiapub.com/IJDTA/vol10_no7/3.pdfhttp://article.nadiapub.com/IJDTA/vol10_no7/3.pdf