SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingMukesh Tekwani
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler designhari2010
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab MashaelQ
 
Compiler design
Compiler designCompiler design
Compiler designsanchi29
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler designDHARANI BABU
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recoveryTech_MX
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compilerMahesh Kumar Chelimilla
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture NotesFellowBuddy.com
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)guest251d9a
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionRicha Sharma
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilersVasim Pathan
 

La actualidad más candente (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
 

Destacado

Destacado (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
 

Similar a Compiler Engineering Lab#2

6 compiler lab - Flex
6 compiler lab - Flex6 compiler lab - Flex
6 compiler lab - FlexMashaelQ
 
(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
 
10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdfAnimeshMani4
 
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 ArchitectureJason Riedy
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with EpsilonSina Madani
 
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
 
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAs
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAsPROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAs
PROGRAMMABLE LOGIC DEVICES-PAL, PROM,PLAsDianaD43
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic libraryAdaCore
 
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 ArchitectureJason Riedy
 
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 SharingDatabricks
 
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 LibraryIntel IT Center
 
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 ToolMashaelQ
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Tom Lee
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature EngineeringHJ van Veen
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmerselliando dias
 
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 OverviewSethCopeland
 

Similar a 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
 

Último

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
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 PractiseAnaAcapella
 
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...Association for Project Management
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
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.pptxDr. Sarita Anand
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
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 17Celine George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
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Ữ Â...Nguyen Thanh Tu Collection
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Último (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
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...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
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Ữ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

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