SlideShare ist ein Scribd-Unternehmen logo
1 von 13
University of Dammam
Girls’ College of Science
Department of Computer Science
Compiler Engineering Lab




                   COMPILER
                  ENGINEERING
         LAB # 2 : LEXICAL ANALYZER (CONT.)
• Identifiers
                            • Keywords
                            • Relational
    A LANGUAGE
        FOR
                              Operators
     SPECIFYING             • Arithmetic
      LEXICAL
     ANALYZER
                              Operators




                  Department of Computer Science -
18-22/2/12                                           2
                     Compiler Engineering Lab
IDENTIFIERS & KEYWORDS

 • if the first character isalpha..
 • It might be keyword or identifier .
 • First you have to check if it is keyword , if it
   is not it is going to be an identifier.
 • use (strcmp) to compare the string in array
   with key words.


                   Department of Computer Science -
18-22/2/12                                            3
                      Compiler Engineering Lab
IDENTIFIERS & KEYWORDS

 • If the lexeme is keyword return the value
   of the keyword
 • Store each character in array for both
   regular identifier and keywords
 • Define an array call it (lexbuf) to store the
   characters of IDs’ and keywords
 • An identifier should be..
    {alpha}({alpha}|{digit}|[ _ ])* <= BSIZE

                      Department of Computer Science -
18-22/2/12                                               4
                         Compiler Engineering Lab
• Analyzer can not process
                                    when the buffer is full,
                                    parser can not process
                                    when the buffer is empty
                                  • the interaction between
    TOKEN BUFFER
                                    the two constrained by the
    lexical analyzer                size of the buffer
    and the parser
    form a producer –             • Buffer hold just one token
    consumer pair                 • Interaction can be
                                    implemented by making
                                    the lexical analyzer a
                                    procedure called by the
                                    parser

                        Department of Computer Science -
18-22/2/12                                                       5
                           Compiler Engineering Lab
• Define these Manifest
                           Constants :
                           • BSIZE 128
    MANIFEST
    CONSTANT               • EOF ‘0’
                           • NONE - 1
                           • NUM 256
                           • ID     257



               Department of Computer Science -
18-22/2/12                                         6
                  Compiler Engineering Lab
Use these definitions:
                                        IF       310
                                        THEN     320
    KEYWORDS
    (TOKENS &                           ELSE     330
    VALUES)                             RELOP 300
    * Be careful with case-
    sensitive lexemes.
                                        AROP     250
                                        ASS      253
                                        SUM      254
                                        SUB      255
                                        MUL      259
                                        DIV      258

                              Department of Computer Science -
18-22/2/12                                                       7
                                 Compiler Engineering Lab
RELOP ( RELATION OPERATIONS )

 • Read one character if it matches one of
   the RELOP, read one more …
 • Declare a char array call it (tvl) [2] to store
   the RELOP value
 • Use (strcpy) to copy values and (strcmp)
   to compare values.



                 Department of Computer Science -
18-22/2/12                                          8
                    Compiler Engineering Lab
• Relational Operators:
                           >= , > , == , <=
                                , > , !=
    OPERATORS

                           TOKEN RELOP
                            Token Value
                       GE , GT , EQ, LE ,LT ,NE



                Department of Computer Science -
18-22/2/12                                         9
                   Compiler Engineering Lab
• Arithmetic Operators:
                           = , + , - ,* , /

    OPERATORS                             TOKEN
                                           AROP

                          Token Value
                    ASS , SUM , SUB , MUL ,
                              DIV

                Department of Computer Science -
18-22/2/12                                         10
                   Compiler Engineering Lab
ISALPHA()()

 # include <ctype.h>
 Description
 •  Classifies an alphabetical character.
 • isalpha is a macro that classifies ASCII-
  coded integer values by table lookup. For
  the default C locale, c is a letter (A to Z or
  a to z).
 Return Value:
     isalpha returns nonzero if c is a letter.
                   Department of Computer Science -
18-22/2/12                                            11
                      Compiler Engineering Lab
ISALNUM( )

 # include <ctype.h>
 Description
 • Tests for an alphanumeric character.
 • isalnum is a macro that classifies ASCII-
   coded integer values by table lookup. c is
   a letter (A to Z or a to z) or a digit (0 to 9).
 Return Value:
 •     isalnum returns nonzero if c is a letter or
     a digit.
                   Department of Computer Science -
18-22/2/12                                            12
                      Compiler Engineering Lab
QUESTIONS?

 Thank you for listening 




                   Department of Computer Science -
18-22/2/12                                            13
                      Compiler Engineering Lab

Weitere ähnliche Inhalte

Was ist angesagt?

Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
Tech_MX
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilers
Vasim Pathan
 

Was ist angesagt? (20)

Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Compiler design
Compiler designCompiler design
Compiler design
 
Unit 1 cd
Unit 1 cdUnit 1 cd
Unit 1 cd
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
Compiler
Compiler Compiler
Compiler
 
P code
P codeP code
P code
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilers
 

Andere mochten auch (6)

London
LondonLondon
London
 
Goliath presentation sergz
Goliath presentation  sergzGoliath presentation  sergz
Goliath presentation sergz
 
Education(1)
Education(1)Education(1)
Education(1)
 
Five Short stories
Five Short stories Five Short stories
Five Short stories
 
Goliath presentation albert
Goliath presentation  albertGoliath presentation  albert
Goliath presentation albert
 
X1r ads sergz
X1r ads sergzX1r ads sergz
X1r ads sergz
 

Ähnlich wie Compiler Engineering Lab#2

(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
Naoki Shibata
 
Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
George Ang
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmers
elliando dias
 

Ähnlich wie Compiler Engineering Lab#2 (20)

6 compiler lab - Flex
6 compiler lab - Flex6 compiler lab - Flex
6 compiler lab - Flex
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Unit1.ppt
Unit1.pptUnit1.ppt
Unit1.ppt
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
(Paper) Efficient Evaluation Methods of Elementary Functions Suitable for SIM...
 
10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf
 
Reproducible Linear Algebra from Application to Architecture
Reproducible Linear Algebra from Application to ArchitectureReproducible Linear Algebra from Application to Architecture
Reproducible Linear Algebra from Application to Architecture
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with Epsilon
 
Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
 
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAs
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAsPROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAs
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAs
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
 
ICIAM 2019: Reproducible Linear Algebra from Application to Architecture
ICIAM 2019: Reproducible Linear Algebra from Application to ArchitectureICIAM 2019: Reproducible Linear Algebra from Application to Architecture
ICIAM 2019: Reproducible Linear Algebra from Application to Architecture
 
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
 
Unleash performance through parallelism - Intel® Math Kernel Library
Unleash performance through parallelism - Intel® Math Kernel LibraryUnleash performance through parallelism - Intel® Math Kernel Library
Unleash performance through parallelism - Intel® Math Kernel Library
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Inside Python
Inside PythonInside Python
Inside Python
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature Engineering
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmers
 
Chap2 - ADSP 21K Manual - Processor and Software Overview
Chap2 - ADSP 21K Manual - Processor and Software OverviewChap2 - ADSP 21K Manual - Processor and Software Overview
Chap2 - ADSP 21K Manual - Processor and Software Overview
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Compiler Engineering Lab#2

  • 1. University of Dammam Girls’ College of Science Department of Computer Science Compiler Engineering Lab COMPILER ENGINEERING LAB # 2 : LEXICAL ANALYZER (CONT.)
  • 2. • Identifiers • Keywords • Relational A LANGUAGE FOR Operators SPECIFYING • Arithmetic LEXICAL ANALYZER Operators Department of Computer Science - 18-22/2/12 2 Compiler Engineering Lab
  • 3. IDENTIFIERS & KEYWORDS • if the first character isalpha.. • It might be keyword or identifier . • First you have to check if it is keyword , if it is not it is going to be an identifier. • use (strcmp) to compare the string in array with key words. Department of Computer Science - 18-22/2/12 3 Compiler Engineering Lab
  • 4. IDENTIFIERS & KEYWORDS • If the lexeme is keyword return the value of the keyword • Store each character in array for both regular identifier and keywords • Define an array call it (lexbuf) to store the characters of IDs’ and keywords • An identifier should be.. {alpha}({alpha}|{digit}|[ _ ])* <= BSIZE Department of Computer Science - 18-22/2/12 4 Compiler Engineering Lab
  • 5. • Analyzer can not process when the buffer is full, parser can not process when the buffer is empty • the interaction between TOKEN BUFFER the two constrained by the lexical analyzer size of the buffer and the parser form a producer – • Buffer hold just one token consumer pair • Interaction can be implemented by making the lexical analyzer a procedure called by the parser Department of Computer Science - 18-22/2/12 5 Compiler Engineering Lab
  • 6. • Define these Manifest Constants : • BSIZE 128 MANIFEST CONSTANT • EOF ‘0’ • NONE - 1 • NUM 256 • ID 257 Department of Computer Science - 18-22/2/12 6 Compiler Engineering Lab
  • 7. Use these definitions: IF 310 THEN 320 KEYWORDS (TOKENS & ELSE 330 VALUES) RELOP 300 * Be careful with case- sensitive lexemes. AROP 250 ASS 253 SUM 254 SUB 255 MUL 259 DIV 258 Department of Computer Science - 18-22/2/12 7 Compiler Engineering Lab
  • 8. RELOP ( RELATION OPERATIONS ) • Read one character if it matches one of the RELOP, read one more … • Declare a char array call it (tvl) [2] to store the RELOP value • Use (strcpy) to copy values and (strcmp) to compare values. Department of Computer Science - 18-22/2/12 8 Compiler Engineering Lab
  • 9. • Relational Operators: >= , > , == , <= , > , != OPERATORS TOKEN RELOP Token Value GE , GT , EQ, LE ,LT ,NE Department of Computer Science - 18-22/2/12 9 Compiler Engineering Lab
  • 10. • Arithmetic Operators: = , + , - ,* , / OPERATORS TOKEN AROP Token Value ASS , SUM , SUB , MUL , DIV Department of Computer Science - 18-22/2/12 10 Compiler Engineering Lab
  • 11. ISALPHA()() # include <ctype.h> Description • Classifies an alphabetical character. • isalpha is a macro that classifies ASCII- coded integer values by table lookup. For the default C locale, c is a letter (A to Z or a to z). Return Value: isalpha returns nonzero if c is a letter. Department of Computer Science - 18-22/2/12 11 Compiler Engineering Lab
  • 12. ISALNUM( ) # include <ctype.h> Description • Tests for an alphanumeric character. • isalnum is a macro that classifies ASCII- coded integer values by table lookup. c is a letter (A to Z or a to z) or a digit (0 to 9). Return Value: • isalnum returns nonzero if c is a letter or a digit. Department of Computer Science - 18-22/2/12 12 Compiler Engineering Lab
  • 13. QUESTIONS? Thank you for listening  Department of Computer Science - 18-22/2/12 13 Compiler Engineering Lab