0% found this document useful (0 votes)
13 views2 pages

Adobe Scan 18 Nov 2022

The document discusses applications of regular expressions including in Unix and lexical analysis. It provides examples of using regular expressions in grep commands and defines tokens as strings of symbols in a program. Lexical analysis converts a source program into tokens and the lex utility can be used to write programs for lexical analysis.

Uploaded by

super market
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Adobe Scan 18 Nov 2022

The document discusses applications of regular expressions including in Unix and lexical analysis. It provides examples of using regular expressions in grep commands and defines tokens as strings of symbols in a program. Lexical analysis converts a source program into tokens and the lex utility can be used to write programs for lexical analysis.

Uploaded by

super market
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3.

10 Applications of RE
MU Dec. 2012, May 2014, May 2015, Dec. 2017
3.10.1 R.E. in Unix
The UNX regular expression lets us specify a group of characters using a pair of square
brackets [ 1. The rules for character classes are
1. [ab] Stand for a + b
2. [0-9 Stand for a digit from 0 to 9
3 [A-Z Stands for an upper-case letter
4. [a-z] Stands for a lower-case letter
5.
[0-9A-Za-z1 Stands for a letter or a digit.
The grep utility in UNIX, scans a file for the occurrence of a pattern and displays those
lines in which the given pattern is found.

For example:
grep president emp.txt
3-74 Regular Expressions
Theory of Comp. Sci. (MU-Sem. 5-Comp.) and Lano
file emp.txt which has the pattern
It will list those lines from the
pattern in grep command can be specified using
regular expression. dent'. Te
6. matches zero or more
occurrences of previous character.
7. matches a single character.
is not a p, q orr.
8. pqrl Matches a single character which
Matches pattern pat at the beginning of a line
9. pat
10. pat $ Matches pattern at end of line.

Example
(a) The regular expression [aA] g [ar] [ar] wal stands for either "Agarwal" or'aren
(b) gstands for zero or more occurrences of g.
Sgrep "A * thakur" emp.txt will look for a pattern starting with A. and endingwi
(C)
thakur in the file emp.txt.

3.10.2 Lexical Analysls


Lexrical analysis is an important phase of a compiler. The lexical analyser scans t
source program and converts it into a steam of tokens. A token is a string of consecutive
symbol defining an entity.
For example a C statement x = y +z has the following tokens

An identifier
Assignment operator
Y An identifier
Arithmetic operator+
Z An identifier
Keywords, identifiers and operators are common examples of tokens.
The UNIX to l
utility lex can be used for writing of a lexical analysis program. p
for
is a set of
regular expressions for each type of token and output of lex is a Cprog
lexical analysis.

You might also like