sardarnajam - PowerPoint PPT Presentation

About This Presentation
Title:

sardarnajam

Description:

Flex for Compiler design – PowerPoint PPT presentation

Number of Views:1
Slides: 10
Provided by: sardarnajam

less

Transcript and Presenter's Notes

Title: sardarnajam


1
Lab lec 01 FLex
  • Ahsan Khan

2
Compilation process
3
Lex
  • Lex is a program that generates lexical analyzer.
  • The lexical analyzer is a program that transforms
    an input stream into a sequence of tokens
  • It reads the input stream and produces the source
    code as output through implementing the lexical
    analyzer in the C program.

4
How Lex Tool Work
  • Firstly lexical analyzer creates a program lex.1
    in the Lex language. Then Lex compiler runs the
    lex.1 program and produces a C program lex.yy.c.
  • Finally C compiler runs the lex.yy.c program and
    produces an object program a.out.
  • a.out is lexical analyzer that transforms an
    input stream into a sequence of tokens.

5
Lex file format
  • A Lex program is separated into three sections by
    delimiters. The formal of Lex source is as
    follows
  • Definitions include declarations of constant,
    variable and regular definitions.
  • Rules define the statement of form p1 action1
    p2 action2....pn action.

6
(No Transcript)
7
Identifying pattern in lex
8
Sample Program
  • includeltstdio.hgt
  • int uppercase0
  • int lowercase0
  • A-Z printf("Uper case letter\t")uppercase
  • a-z printf("lowercasee letter\t")lowercase
  • int main()
  • printf("please enter string\n")
  • yylex()
  • printf("upercased and lower case
    d",uppercase,lowercase)

9
Today Task
  • PROGRAM LOGIC
  • Write a java or c/c program that take stream
    input and identify the characters , digits and
    symbols along with number count and also identify
    the uppercase and lower case letters
  • For example I will input the following text HI!
    I am john , I am 25 years old , lives in Street
    02 Holland
  • Output
  • Symboll
  • Capital AlphabetH
  • Capital AlphabetI
  • Symboll !
Write a Comment
User Comments (0)
About PowerShow.com