This document provides additional information about LEX and describes several LEX patterns, variables, functions, start conditions, and examples. It explains that LEX is used for text processing and scanner generation. It also describes pattern matching symbols, special directives like ECHO and REJECT, variables like yytext, and functions like yylex(), yyless(), and yywrap(). Examples are provided for multi-file scanning, counting character sequences, and generating HTML.
Relationship Among Token, Lexeme & PatternBharat Rathore
Relationship among Token, Lexeme and Pattern
Outline
Token
Lexeme
Pattern
Relationship
Tokens : A token is sequence of characters that can be treated
as a unit/single logical entity.
Examples
Keywords
Examples : for, while, if etc.
Identifier
Examples : Variable name, function name, etc.
Operators
Examples : '+', '++', '-' etc.
Separators
Examples : ',' ';' etc.
Pattern
Pattern is a rule describing all those lexemes that can represent a particular token in a source language.
Lexeme
It is a sequence of characters in the source program that is matched by the pattern for a token.
Example : “float”, “=“, “223”, “;”
Relationship Among Token, Lexeme & PatternBharat Rathore
Relationship among Token, Lexeme and Pattern
Outline
Token
Lexeme
Pattern
Relationship
Tokens : A token is sequence of characters that can be treated
as a unit/single logical entity.
Examples
Keywords
Examples : for, while, if etc.
Identifier
Examples : Variable name, function name, etc.
Operators
Examples : '+', '++', '-' etc.
Separators
Examples : ',' ';' etc.
Pattern
Pattern is a rule describing all those lexemes that can represent a particular token in a source language.
Lexeme
It is a sequence of characters in the source program that is matched by the pattern for a token.
Example : “float”, “=“, “223”, “;”
Whenever we need to transfer XML file, we need to ensure about its quality and its error-freeness. This can be achieved through DTD (Document Type Definition).
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
Flex is a scanner generator tool for lexical analysis, which is based on finite state machine (FSM). The input is a set of regular expressions, and the output is the code to implement the scanner according to the input rules.
Whenever we need to transfer XML file, we need to ensure about its quality and its error-freeness. This can be achieved through DTD (Document Type Definition).
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
Flex is a scanner generator tool for lexical analysis, which is based on finite state machine (FSM). The input is a set of regular expressions, and the output is the code to implement the scanner according to the input rules.
TO UNDERSTAND about stdio.h in C.
TO LEARN ABOUT Math.h in C.
To learn about ctype.h in C.
To understand stdlib.h in c.
To learn about conio.h in c.
To learn about String.h in c.
TO LEARN ABOUT process.h in C.
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
Have you ever wondered how you would implement a parser for simple arithmetic expressions in C++? Faced with this problem, many C++ programmers would generate a parser using Flex and Bison, or perhaps Boost Spirit. In this talk, I introduced some alternative tools, Ragel and Lemon, showing how they can be used to build a calculator that handles simple arithmetic expressions.
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
So I am writing a CS code for a project and I keep getting \"cannot open file\" I know I put it into
my code, but I don\'t know why it won\'t execute after i input ./a.out I put in gcc -Wall
contents3.c and no errors or warnings pop up. So I figure everything is working right. But after
that, I get \"Cannot open file\". So I am wondering what I can do to get this settled out properly. I
am putting the outcome of the project and my code. Please someone help me!
#include
#include
#include
#include
#include
#include
int len = 0;
int sp = 0;
int lwrcaseCount = 0;
int uprcaseCount = 0;
int digitCount = 0;
int specialCount = 0;
char data[200];
int frequency[84];
int sortFrequency[84][2];
char string[] =
\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\\\"#$%&\'()*+,-
./:;<=>?@[/]^_`{|}~\";
//printf(\"\ \");
//To sort based on frequency of characters
/*void sort()
{
int max, loc, temp, x, y;
//Loops till end - 1 position of the frequency array
for(x = 0; x <= 84 - 1; x++)
{
//Initializes the max to the x position of the frequency array assuming it as maximum
max = frequency[x];
//Initializes of loc to x assuming location x contains the maximum value
loc = x;
//Loops through x + 1 to length - 1 of frequency array
for(y = x + 1; y <= 95 -1; y++)
{
//If current position of the frequency of the array is greater than the max
//then update the max with the current value of frequency and update the loc
if(frequency[y] > max)
{
max = frequency[y];
loc = y;
}//end of if
}//end of for loop
//If loc is not x then swap
if(loc != x)
{
temp = frequency[x];
frequency[x] = frequency[loc];
frequency[loc] = temp;
}//end of if
//Store the location of the maximum value in the zero column position of row x
sortFrequency[x][0]= loc;
//Store the maximum value in the first column position of row x
sortFrequency[x][1] = max;
}//end of for loop
}//end of function*/
void sort()
{
for(int i = 0; i < 84; i++)
{
sortFrequency[i][0] = i;
sortFrequency[i][1] = frequency[i];
}
for(int i = 0; i < 84-1; i++)
for(int j = 0; j < 84-i-1; j++)
if(sortFrequency[j][1] < sortFrequency[j+1][1])
{
int temp = sortFrequency[j][1];
sortFrequency[j][1] = sortFrequency[j+1][1];
sortFrequency[j+1][1] = temp;
temp = sortFrequency[j][0];
sortFrequency[j][0] = sortFrequency[j+1][0];
sortFrequency[j+1][0] = temp;
}
}
//To count frequency of each character
void frequencyCount()
{
int c, d;
//Loops till the length of the inputed data
for(c = 0; c < len; c++)
{
//Loops from 33 to 126 which is the ascii values of required characters range
for(d = 0; d < 84; d++)
{
//If the data in the current position is equal to the acii value
if(data[c] == string[d])
//Frequency 0 position is equal to 33 ascii.
//So 33 is deducted
frequency[d]++;
}//end of for loop
}//end of for loop
}//End of function
//Initializes the frequency array to zero
void initialize()
{
int c;
for(c = 0; c < 84; c++)
frequency[c] = 0;
}
//Read the file which contains data
void readFile()
{
//File pointer created
FILE *fptr;
char ch;
//Fi.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
2. LEX
In addition to scanner development, Lex/Flex is also used for
some other applications in system administration where text
processing is needed.
3. Patterns
r? zero or one occurrence of r
r{2,5} two to five occurrences of r
r{2,} two or more occurrences of r
r{4} exactly 4 occurrence of r
0 a NUL character (ASCII code 0)
123 the character with octal value 123
x2a the character with hexadecimal value 2a
4. Patterns
<s>r an r, but only in start condition s
<s1,s2,s3>r same, but in any of start conditions s1, s2,
or s3
<*>r an r in any start condition, even an
exclusive one.
<<EOF>> an end-of-file
<s1,s2><<EOF>> an end-of-file when in start condition s1
or s2
5. Special Directives
ECHO copies yytext to the scanner's output.
BEGIN followed by the name of a start condition places the
scanner in the corresponding start condition.
REJECT directs the scanner to proceed on to the second best rule
which matched the input (or a prefix of the input). Multiple
REJECT's are allowed, each one finding the next best choice to
the currently active rule.
6. Example %{ int s=0;
%}
%%
she {s++; REJECT;}
he {s++}
%%
main() { yylex();
printf(“%dn",s);
return 0; }
7. Lex Variables
yyin Of the type FILE*. This points to the current file
being parsed by the lexer.
yyout Of the type FILE*. This points to the location where
the output of the lexer will be written. By default,
both yyin and yyout point to standard input and
output.
yytext The text of the matched pattern is stored in this
variable (char*).
yyleng Gives the length of the matched pattern.
yylineno Provides current line number
8. Lex Functions
yylex() The function that starts the analysis.
yywrap() In the C program generated by the lex
specification file, when yylex() finished with the
first file, it calls yywrap(), which opens the next file,
and yylex() continues. When yywrap() has
exhausted all the command line arguments, it
returns 1, and yylex() returns with value 0.
unput(c) puts the character c back onto the input stream. It
will be the next character scanned.
input() reads the next character from the input stream
9. Lex functions- yyless(n)
Returns all but the first n characters of the current token back
to the input stream, where they will be rescanned when the
scanner looks for the next match.
yytext and yyleng are adjusted appropriately
An argument of 0 to yyless will cause the entire current input
string to be scanned again.
10. For example, on the input "foobar" the following will write out
"foobarbar“
%% foobar ECHO; yyless(3);
[a-z]+ ECHO;
11. Lex functions- yymore()
yymore() tells the scanner that the next time it matches a
rule, the corresponding token should be appended onto the
current value of yytext rather than replacing it.
12. For example, given the input "mega-kludge" the following will
write "mega-mega- kludge" to the output
%% mega- ECHO; yymore();
kludge ECHO;
First "mega-" is matched and echoed to the output. Then
"kludge" is matched, but the previous "mega-" is still
hanging around at the beginning of yytext so the ECHO for
the "kludge" rule will actually write "mega-kludge".
13. Start Conditions
Flex provides a mechanism for conditionally activating rules.
Any rule whose pattern is prefixed with "<sc>" will only be
active when the scanner is in the start condition named "sc".
<STRING>[^"]* { /* eat up the string body ... */ ... }
will be active only when the scanner is in the "STRING" start
condition
<INITIAL,STRING,QUOTE>. { /* handle an escape ... */ ... } will
be active only when the current start condition is either
"INITIAL", "STRING", or "QUOTE".
14. A start condition is activated using the BEGIN action.
Until the next BEGIN action is executed, rules with the given start
condition will be active and others are inactive.
Start conditions declared using %s are inclusive, then rules with
no start conditions at all will also be active.
Start conditions declared using %x are inclusive, then only rules
qualified with the start condition will be active.
Exclusive start conditions make it easy to specify "mini-scanners"
which scan portions of the input that are syntactically different
from the rest (e.g., comments).
15. Begin
BEGIN(0) returns to the original state where only the rules with no
start conditions are active.
BEGIN(INITIAL) is equivalent to BEGIN(0).
int enter_special;
%x SPECIAL
%%
if ( enter_special )
BEGIN(SPECIAL);
<SPECIAL>[a-z] {printf(“letter”);} %%
16. Example %s TABL REC DATA
%%
<INITIAL>"<table>" BEGIN TABL;
<TABL>"</table>" BEGIN INITIAL;
<TABL><tr> BEGIN REC;
<REC></tr> BEGIN TABL;
<REC><td> BEGIN DATA;
%%
<DATA></td> BEGIN REC; main()
<DATA>. ECHO; {
<DATA,REC,TABL>[ tn] ; yylex();
}
17. Line no in text file
%{
/*
*/
int lineno=1;
%}
line .*n
%%
{line} { printf("%5d %s",lineno++,yytext); }
%%
main(int argc, char*argv[])
{
extern FILE *yyin;
yyin=fopen(argv[1],"r");
yylex();
return 0;
}
18. A Lex program that finds a word from the given file and replaces
it with other word.
24. The following lex specification file is used to generate a C
program which is used to generate a html file from a data file.
A0 = "Name"
B0 = "SSN"
C0 = "HW1"
D0 = "HW2”
…
Name SSN HW1 HW2
Scott Smith 123445678 82 44.2
Sam Sneed 999887777 92 84
26. This lex specification file is used to generate a C program
which counts how many times a given alphabet is next to
another alphabet in the given input
32. "ftp://ftp.funet.fi/pub/Linux/" {
printf("ftp://ftp.monash.edu.au/pub/linux/");
BEGIN COPY;
}
"http://weather/" {
printf("http://www.bom.gov.au/");
BEGIN COPY;
}
"http://bypass." { printf("http://"); BEGIN COPY;
}
"ftp://bypass." { printf("ftp://"); BEGIN COPY; }
<COPY>[^ n] ECHO;
<COPY>" " BEGIN SKIP;
. BEGIN SKIP;
<SKIP>. ;
<*>n { putchar('n'); fflush(stdout); BEGIN 0; }
%%
33. Write a LEX program to count the
number of palindrome string in a given
file and write them into a separate file.
34. Write a LEX program to read 3 Roman
numbers and output its equivalent
numbers and sum in decimal.
Ex:
Input: VI IX L
Output: 6 + 9 + 50 = 65
35. Write a LEX program to read an
expression in postfix form and
evaluate the value of the expression
Ex: 342+* is 18
36. Write a lex program to read a text file
and reverse all words that begin with
letter ‘a’ and end with letter ‘d’. Display
the longest of such words.
37. Write a LEX program to count number
of even and odd numbers. Output the
odd numbers to odd.txt and even
numbers to even.txt files. Also display
the largest odd and even numbers
38. Write a lex program to read a text file
and remove all words that begin with
letter ‘a’ and end with letter‘d’. Write
the remaining words to a separate file.
39. Write a lex program to read a text file
and do the following
Add 1 to all integers.
Add 0.5 to all fractional numbers.
Convert all words to uppercase words
Delete all alphanumeric words
Write resulting content to a separate
file.
41. Write a Lex program that converts a file
to "Pig latin."
Specifically, assume the file is a sequence
of words (groups of letters) separated by
whitespace. Every time you encounter a
word:
1. If the first letter is a consonant, move
it to the end of the word and then add
ay.
2. If the first letter is a vowel, just add
ay to the end of the word.
All nonletters are copied intact to the
output.