The document discusses lexical analysis in compilers. It defines lexical analysis as the first phase of compilation that reads the source code characters and groups them into meaningful tokens. It describes how a lexical analyzer works by generating tokens in the form of <token name, attribute value> from the source code lexemes. Examples of tokens generated for a sample program are provided. Methods for handling lexical errors, buffering input, specifying tokens with regular expressions and recognizing tokens using transition diagrams are also summarized.
The document discusses the different phases of a compiler:
1) The front end checks the syntax and semantics of the source code and the back end translates it to assembly code.
2) The front end contains lexical analysis, preprocessing, syntax analysis, and semantic analysis. The back end contains analysis, optimization, and code generation.
3) Optimization aims to improve the intermediate code to increase performance by reducing complexity and leading to faster execution.
The document discusses the role and implementation of a lexical analyzer in compilers. A lexical analyzer is the first phase of a compiler that reads source code characters and generates a sequence of tokens. It groups characters into lexemes and determines the tokens based on patterns. A lexical analyzer may need to perform lookahead to unambiguously determine tokens. It associates attributes with tokens, such as symbol table entries for identifiers. The lexical analyzer and parser interact through a producer-consumer relationship using a token buffer.
The document discusses the structure and process of a compiler. It has two major phases - the front-end and back-end. The front-end performs analysis of the source code by recognizing legal/illegal programs, understanding semantics, and producing an intermediate representation. The back-end translates the intermediate representation into target code. The general structure includes lexical analysis, syntax analysis, semantic analysis, code generation and optimization phases.
The document discusses the different phases of a compiler and storage allocation strategies. It describes:
1. The phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation.
2. Storage allocation strategies for activation records include static allocation, stack allocation, and heap allocation. Languages like FORTRAN use static allocation while Algol uses stack allocation.
3. Parameter passing mechanisms include call-by-value, call-by-reference, copy-restore, and call-by-name. Call-by-value passes the actual parameter values while call-by-reference passes their locations.
The document discusses lexical analysis, which is the first phase of compilation. It involves reading the source code and grouping characters into meaningful sequences called lexemes. Each lexeme is mapped to a token that is passed to the subsequent parsing phase. Regular expressions are used to specify patterns for tokens. A lexical analyzer uses finite automata to recognize tokens based on these patterns. Lexical analyzers may also perform tasks like removing comments and whitespace from the source code.
This document discusses flex and bison tools for lexical analysis and parsing. It covers:
1. How flex returns tokens with values and bison assigns token numbers starting from 258.
2. The basics of writing flex rules and scanners, and bison grammars, rules, and parsers.
3. An example bison calculator grammar and combining the flex scanner and bison parser.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two main parts - a front end that handles language-dependent tasks like lexical analysis, syntax analysis, and semantic analysis, and a back end that handles language-independent tasks like code optimization and final code generation. Compiler design involves techniques from programming languages, theory, algorithms, and computer architecture. Regular expressions are used to describe the tokens in a programming language.
The document discusses the different phases of a compiler:
1) The front end checks the syntax and semantics of the source code and the back end translates it to assembly code.
2) The front end contains lexical analysis, preprocessing, syntax analysis, and semantic analysis. The back end contains analysis, optimization, and code generation.
3) Optimization aims to improve the intermediate code to increase performance by reducing complexity and leading to faster execution.
The document discusses the role and implementation of a lexical analyzer in compilers. A lexical analyzer is the first phase of a compiler that reads source code characters and generates a sequence of tokens. It groups characters into lexemes and determines the tokens based on patterns. A lexical analyzer may need to perform lookahead to unambiguously determine tokens. It associates attributes with tokens, such as symbol table entries for identifiers. The lexical analyzer and parser interact through a producer-consumer relationship using a token buffer.
The document discusses the structure and process of a compiler. It has two major phases - the front-end and back-end. The front-end performs analysis of the source code by recognizing legal/illegal programs, understanding semantics, and producing an intermediate representation. The back-end translates the intermediate representation into target code. The general structure includes lexical analysis, syntax analysis, semantic analysis, code generation and optimization phases.
The document discusses the different phases of a compiler and storage allocation strategies. It describes:
1. The phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation.
2. Storage allocation strategies for activation records include static allocation, stack allocation, and heap allocation. Languages like FORTRAN use static allocation while Algol uses stack allocation.
3. Parameter passing mechanisms include call-by-value, call-by-reference, copy-restore, and call-by-name. Call-by-value passes the actual parameter values while call-by-reference passes their locations.
The document discusses lexical analysis, which is the first phase of compilation. It involves reading the source code and grouping characters into meaningful sequences called lexemes. Each lexeme is mapped to a token that is passed to the subsequent parsing phase. Regular expressions are used to specify patterns for tokens. A lexical analyzer uses finite automata to recognize tokens based on these patterns. Lexical analyzers may also perform tasks like removing comments and whitespace from the source code.
This document discusses flex and bison tools for lexical analysis and parsing. It covers:
1. How flex returns tokens with values and bison assigns token numbers starting from 258.
2. The basics of writing flex rules and scanners, and bison grammars, rules, and parsers.
3. An example bison calculator grammar and combining the flex scanner and bison parser.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two main parts - a front end that handles language-dependent tasks like lexical analysis, syntax analysis, and semantic analysis, and a back end that handles language-independent tasks like code optimization and final code generation. Compiler design involves techniques from programming languages, theory, algorithms, and computer architecture. Regular expressions are used to describe the tokens in a programming language.
The document discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
This document discusses compilers, tokenizers, and parsers. It defines a compiler as having two main components: a lexer (tokenizer) that reads input and generates tokens, and a parser that converts tokens into a structured data format. It describes how a tokenizer works by defining states, scanning for patterns, and returning a list of tokens. It recommends optimizations for tokenizers like using little memory, partial reading, and avoiding unnecessary function calls. Finally, it states that the parser analyzes the token stream and constructs an object-oriented tree structure, avoiding non-tail recursion to prevent hitting stack limits.
The document discusses the different phases of a compiler: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It explains that a compiler takes source code as input and translates it into an equivalent language. The compiler performs analysis and synthesis in multiple phases, with each phase transforming the representation of the source code. Key activities include generating tokens, building a syntax tree, type checking, generating optimized intermediate code, and finally producing target machine code. Symbol tables are also used to store identifier information as the compiler runs.
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
The document discusses code generation for expressions. It describes determining an evaluation order based on operator precedence, selecting instructions based on operand type and addressability, and using register descriptors to track partial results in registers. Register descriptors indicate which operand is in each register. Partial results are saved to a temporary memory location when registers are occupied. The code generation routine generates code based on the operand descriptors.
Lex is a program generator designed for lexical processing of character input streams. It works by translating a table of regular expressions and corresponding program fragments provided by the user into a program. This program then reads an input stream, partitions it into strings matching the given expressions, and executes the associated program fragments in order. Flex is a fast lexical analyzer generator that is an alternative to Lex. It generates scanners that recognize lexical patterns in text based on pairs of regular expressions and C code provided by the user.
The document discusses the functions and purposes of translators in computing. It describes:
1) Interpreters and compilers translate programs from high-level languages to machine code. Compilers translate the entire program at once, while interpreters translate instructions one at a time as the program runs.
2) Translation from high-level languages to machine code involves multiple stages including lexical analysis, syntax analysis, code generation, and optimization.
3) Linkers and loaders are used to combine separately compiled modules into a complete executable program by resolving addresses and linking the modules together.
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
Pseudocode is an artificial and informal language that helps developers to create algorithms. In this papera software tool is described, for translating the pseudocode into a particular source programminglanguage. This tool compiles the pseudocode given by the user and translates it to a source programminglanguage. The scope of the tool is very much wide as we can extend it to a universal programming toolwhich produces any of the specified programming language from a given pseudocode. Here we present thesolution for translating the pseudocode to a programming language by using the different stages of acompiler
This document provides a 2 mark question and answer review for the Principles of Compiler Design subject. It includes 40 questions and answers covering topics like the definitions and phases of a compiler, lexical analysis, syntax analysis, parsing, grammars, ambiguity, error handling and more. The questions are multiple choice or short answer designed to assess understanding of key compiler design concepts and techniques.
JLex is a lexical analyzer generator for Java that takes a specification file as input and generates a Java source file for a lexical analyzer. It performs lexical analysis faster than a comparable handwritten lexical analyzer. SAX and DOM are XML parser APIs that respectively use event-based and tree-based models to read and process XML documents, with SAX using less memory but DOM allowing arbitrary navigation and modification of the document tree.
We have learnt that any computer system is made of hardware and software.
The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember.
These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine.
This is known as Language Processing System.
The document discusses the major phases of a compiler:
1. Syntax analysis parses the source code and produces an abstract syntax tree.
2. Contextual analysis checks the program for errors like type checking and scope and annotates the abstract syntax tree.
3. Code generation transforms the decorated abstract syntax tree into object code.
This document provides an overview of compilers, including their structure and purpose. It discusses:
- What a compiler is and its main functions of analysis and synthesis.
- The history and need for compilers, from early assembly languages to modern high-level languages.
- The structure of a compiler, including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Different types of translators like interpreters, assemblers, and linkers.
- Tools that help in compiler construction like scanner generators, parser generators, and code generators.
This document provides an overview of programming in C. It discusses the importance of C as the base language for other programming languages and its efficiency. The basic structure of a C program is outlined as having documentation, include, define, global declaration, and main sections. Interpreters and compilers are explained as the two methods for running C programs, with compilers producing faster executable programs. Key aspects of C as a language are covered such as variables, data types, and constants.
The document discusses C preprocessors and user-defined data types in C like structures and unions. It explains that the preprocessor is a program that processes code before compilation. Key preprocessor directives include #include, #define, #ifdef, and #line. Structures allow grouping of different data types while unions allocate space for the largest member. Typedefs create aliases for existing types. Enumerations define sets of named integer constants.
This document discusses the principles of compiler design. It describes the different phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses other language processing systems like preprocessors, assemblers, linkers, and loaders. The overall goal of a compiler is to translate a program written in one language into another language like assembly or machine code.
This document provides an overview of Lex and Yacc. It describes Lex as a tool that generates scanners to tokenize input streams based on regular expressions. Yacc is described as a tool that generates parsers to analyze tokens based on grammar rules. The document outlines the compilation process for Lex and Yacc, describes components of a Lex source file including regular expressions and transition rules, and provides examples of Lex and Yacc usage.
This document discusses the role and implementation of a lexical analyzer. It begins by explaining that the lexical analyzer is the first phase of a compiler that reads source code characters and produces tokens for the parser. It describes how the lexical analyzer interacts with the parser by returning tokens when requested. The document then discusses several tasks of the lexical analyzer, including stripping comments and whitespace, tracking line numbers for errors, and preprocessing macros. It also covers concepts like tokens, patterns, lexemes, and attributes. Finally, it provides an example input and output of a lexical analyzer tokenizing a C program.
The document discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
This document discusses compilers, tokenizers, and parsers. It defines a compiler as having two main components: a lexer (tokenizer) that reads input and generates tokens, and a parser that converts tokens into a structured data format. It describes how a tokenizer works by defining states, scanning for patterns, and returning a list of tokens. It recommends optimizations for tokenizers like using little memory, partial reading, and avoiding unnecessary function calls. Finally, it states that the parser analyzes the token stream and constructs an object-oriented tree structure, avoiding non-tail recursion to prevent hitting stack limits.
The document discusses the different phases of a compiler: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It explains that a compiler takes source code as input and translates it into an equivalent language. The compiler performs analysis and synthesis in multiple phases, with each phase transforming the representation of the source code. Key activities include generating tokens, building a syntax tree, type checking, generating optimized intermediate code, and finally producing target machine code. Symbol tables are also used to store identifier information as the compiler runs.
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
The document discusses code generation for expressions. It describes determining an evaluation order based on operator precedence, selecting instructions based on operand type and addressability, and using register descriptors to track partial results in registers. Register descriptors indicate which operand is in each register. Partial results are saved to a temporary memory location when registers are occupied. The code generation routine generates code based on the operand descriptors.
Lex is a program generator designed for lexical processing of character input streams. It works by translating a table of regular expressions and corresponding program fragments provided by the user into a program. This program then reads an input stream, partitions it into strings matching the given expressions, and executes the associated program fragments in order. Flex is a fast lexical analyzer generator that is an alternative to Lex. It generates scanners that recognize lexical patterns in text based on pairs of regular expressions and C code provided by the user.
The document discusses the functions and purposes of translators in computing. It describes:
1) Interpreters and compilers translate programs from high-level languages to machine code. Compilers translate the entire program at once, while interpreters translate instructions one at a time as the program runs.
2) Translation from high-level languages to machine code involves multiple stages including lexical analysis, syntax analysis, code generation, and optimization.
3) Linkers and loaders are used to combine separately compiled modules into a complete executable program by resolving addresses and linking the modules together.
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
Pseudocode is an artificial and informal language that helps developers to create algorithms. In this papera software tool is described, for translating the pseudocode into a particular source programminglanguage. This tool compiles the pseudocode given by the user and translates it to a source programminglanguage. The scope of the tool is very much wide as we can extend it to a universal programming toolwhich produces any of the specified programming language from a given pseudocode. Here we present thesolution for translating the pseudocode to a programming language by using the different stages of acompiler
This document provides a 2 mark question and answer review for the Principles of Compiler Design subject. It includes 40 questions and answers covering topics like the definitions and phases of a compiler, lexical analysis, syntax analysis, parsing, grammars, ambiguity, error handling and more. The questions are multiple choice or short answer designed to assess understanding of key compiler design concepts and techniques.
JLex is a lexical analyzer generator for Java that takes a specification file as input and generates a Java source file for a lexical analyzer. It performs lexical analysis faster than a comparable handwritten lexical analyzer. SAX and DOM are XML parser APIs that respectively use event-based and tree-based models to read and process XML documents, with SAX using less memory but DOM allowing arbitrary navigation and modification of the document tree.
We have learnt that any computer system is made of hardware and software.
The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember.
These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine.
This is known as Language Processing System.
The document discusses the major phases of a compiler:
1. Syntax analysis parses the source code and produces an abstract syntax tree.
2. Contextual analysis checks the program for errors like type checking and scope and annotates the abstract syntax tree.
3. Code generation transforms the decorated abstract syntax tree into object code.
This document provides an overview of compilers, including their structure and purpose. It discusses:
- What a compiler is and its main functions of analysis and synthesis.
- The history and need for compilers, from early assembly languages to modern high-level languages.
- The structure of a compiler, including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Different types of translators like interpreters, assemblers, and linkers.
- Tools that help in compiler construction like scanner generators, parser generators, and code generators.
This document provides an overview of programming in C. It discusses the importance of C as the base language for other programming languages and its efficiency. The basic structure of a C program is outlined as having documentation, include, define, global declaration, and main sections. Interpreters and compilers are explained as the two methods for running C programs, with compilers producing faster executable programs. Key aspects of C as a language are covered such as variables, data types, and constants.
The document discusses C preprocessors and user-defined data types in C like structures and unions. It explains that the preprocessor is a program that processes code before compilation. Key preprocessor directives include #include, #define, #ifdef, and #line. Structures allow grouping of different data types while unions allocate space for the largest member. Typedefs create aliases for existing types. Enumerations define sets of named integer constants.
This document discusses the principles of compiler design. It describes the different phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses other language processing systems like preprocessors, assemblers, linkers, and loaders. The overall goal of a compiler is to translate a program written in one language into another language like assembly or machine code.
This document provides an overview of Lex and Yacc. It describes Lex as a tool that generates scanners to tokenize input streams based on regular expressions. Yacc is described as a tool that generates parsers to analyze tokens based on grammar rules. The document outlines the compilation process for Lex and Yacc, describes components of a Lex source file including regular expressions and transition rules, and provides examples of Lex and Yacc usage.
This document discusses the role and implementation of a lexical analyzer. It begins by explaining that the lexical analyzer is the first phase of a compiler that reads source code characters and produces tokens for the parser. It describes how the lexical analyzer interacts with the parser by returning tokens when requested. The document then discusses several tasks of the lexical analyzer, including stripping comments and whitespace, tracking line numbers for errors, and preprocessing macros. It also covers concepts like tokens, patterns, lexemes, and attributes. Finally, it provides an example input and output of a lexical analyzer tokenizing a C program.
The document discusses the differences between compilers and interpreters. It states that a compiler translates an entire program into machine code in one pass, while an interpreter translates and executes code line by line. A compiler is generally faster than an interpreter, but is more complex. The document also provides an overview of the lexical analysis phase of compiling, including how it breaks source code into tokens, creates a symbol table, and identifies patterns in lexemes.
This document provides an overview of the key components and phases of a compiler. It discusses that a compiler translates a program written in a source language into an equivalent program in a target language. The main phases of a compiler are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and symbol table management. Each phase performs important processing that ultimately results in a program in the target language that is equivalent to the original source program.
The phases of a compiler are:
1. Lexical analysis breaks the source code into tokens
2. Syntax analysis checks the token order and builds a parse tree
3. Semantic analysis checks for type errors and builds symbol tables
4. Code generation converts the parse tree into target code
The document discusses the phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It describes the role of the lexical analyzer in translating source code into tokens. Key aspects covered include defining tokens and lexemes, using patterns and attributes to classify tokens, and strategies for error recovery in lexical analysis such as buffering input.
In this PPT we covered all the points like..Introduction to compilers - Design issues, passes, phases, symbol table
Preliminaries - Memory management, Operating system support for compiler, Compiler support for garbage collection ,Lexical Analysis - Tokens, Regular Expressions, Process of Lexical analysis, Block Schematic, Automatic construction of lexical analyzer using LEX, LEX features and specification.
The document discusses the role and process of a lexical analyzer in compiler design. A lexical analyzer groups input characters into lexemes and produces a sequence of tokens as output for the syntactic analyzer. It strips out comments and whitespace, correlates line numbers with errors, and interacts with the symbol table. Lexical analysis improves compiler efficiency, portability, and allows for simpler parser design by separating lexical and syntactic analysis.
The document summarizes the key phases of a compiler:
1. The compiler takes source code as input and goes through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation to produce machine code as output.
2. Lexical analysis converts the source code into tokens, syntax analysis checks the grammar and produces a parse tree, and semantic analysis validates meanings.
3. Code optimization improves the intermediate code before code generation translates it into machine instructions.
The document defines different phases of a compiler and describes Lexical Analysis in detail. It discusses:
1) A compiler converts a high-level language to machine language through front-end and back-end phases including Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code Generation, Code Optimization and Code Generation.
2) Lexical Analysis scans the source code and groups characters into tokens by removing whitespace and comments. It identifies tokens like identifiers, keywords, operators etc.
3) A lexical analyzer generator like Lex takes a program written in the Lex language and produces a C program that acts as a lexical analyzer.
System software module 4 presentation filejithujithin657
The document discusses the various phases of a compiler:
1. Lexical analysis scans source code and transforms it into tokens.
2. Syntax analysis validates the structure and checks for syntax errors.
3. Semantic analysis ensures declarations and statements follow language guidelines.
4. Intermediate code generation develops three-address codes as an intermediate representation.
5. Code generation translates the optimized intermediate code into machine code.
This document describes the different phases of a compiler: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides examples of each phase. Lexical analysis scans the source code and groups characters into lexemes and tokens. Syntax analysis builds a parse tree from the tokens. Semantic analysis checks for semantic errors. Intermediate code generation outputs an abstract representation. Code optimization improves the intermediate code. Code generation selects memory locations and translates to machine instructions. The document also defines lexemes, tokens, and patterns used in lexical analysis. It describes the role of the lexical analyzer and different buffer schemes (one buffer vs two buffer) used in lexical analysis.
The document discusses the roles of compilers and interpreters. It explains that a compiler translates an entire program into machine code in one pass, while an interpreter translates and executes code line-by-line. The document also covers the basics of lexical analysis, including how it breaks source code into tokens by removing whitespace and comments. It provides an example of tokens identified in a code snippet and discusses how the lexical analyzer works with the symbol table and syntax analyzer.
The document describes the structure and process of a compiler. It discusses the major phases of a compiler including scanning, parsing, semantic analysis, code generation and optimization. It also summarizes the key data structures used in a compiler like the symbol table and syntax tree. The document uses the TINY programming language and its compiler for the TM machine as an example to illustrate the compiler construction process.
The document provides an overview of compiler design and the different phases involved in compiling a program. It discusses:
1) What compilers do by translating source code into machine code while hiding machine-dependent details. Compilers may generate pure machine code, augmented machine code, or virtual machine code.
2) The typical structure of a compiler which includes lexical analysis, syntactic analysis, semantic analysis, code generation, and optimization phases.
3) Lexical analysis involves scanning the source code and grouping characters into tokens. Regular expressions are used to specify patterns for tokens. Scanner generators like Lex and Flex can generate scanners from regular expression definitions.
This document provides an introduction to compilers, including definitions of key terms like translator, compiler, interpreter, and assembler. It describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses related concepts like the front-end and back-end of a compiler, multi-pass compilation, and different types of compilers.
The compiler is software that converts source code written in a high-level language into machine code. It works in two major phases - analysis and synthesis. The analysis phase performs lexical analysis, syntax analysis, and semantic analysis to generate an intermediate representation from the source code. The synthesis phase performs code optimization and code generation to create the target machine code from the intermediate representation. The compiler uses various components like a symbol table, parser, and code generator to perform this translation.
The document provides an overview of the compilation process and the different phases involved in compiler construction. It can be summarized as follows:
1. A compiler translates a program written in a source language into an equivalent program in a target language. It performs analysis, synthesis and error checking during this translation process.
2. The major phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and linking. Tools like Lex and Yacc are commonly used to generate lexical and syntax analyzers.
3. Regular expressions are used to specify patterns for tokens during lexical analysis. A lexical analyzer reads the source program and generates a sequence of tokens by matching character sequences to patterns
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfBalvir Singh
Sri Guru Hargobind Ji (19 June 1595 - 3 March 1644) is revered as the Sixth Nanak.
• On 25 May 1606 Guru Arjan nominated his son Sri Hargobind Ji as his successor. Shortly
afterwards, Guru Arjan was arrested, tortured and killed by order of the Mogul Emperor
Jahangir.
• Guru Hargobind's succession ceremony took place on 24 June 1606. He was barely
eleven years old when he became 6th Guru.
• As ordered by Guru Arjan Dev Ji, he put on two swords, one indicated his spiritual
authority (PIRI) and the other, his temporal authority (MIRI). He thus for the first time
initiated military tradition in the Sikh faith to resist religious persecution, protect
people’s freedom and independence to practice religion by choice. He transformed
Sikhs to be Saints and Soldier.
• He had a long tenure as Guru, lasting 37 years, 9 months and 3 days
3rd International Conference on Artificial Intelligence Advances (AIAD 2024)GiselleginaGloria
3rd International Conference on Artificial Intelligence Advances (AIAD 2024) will act as a major forum for the presentation of innovative ideas, approaches, developments, and research projects in the area advanced Artificial Intelligence. It will also serve to facilitate the exchange of information between researchers and industry professionals to discuss the latest issues and advancement in the research area. Core areas of AI and advanced multi-disciplinary and its applications will be covered during the conferences.
Open Channel Flow: fluid flow with a free surfaceIndrajeet sahu
Open Channel Flow: This topic focuses on fluid flow with a free surface, such as in rivers, canals, and drainage ditches. Key concepts include the classification of flow types (steady vs. unsteady, uniform vs. non-uniform), hydraulic radius, flow resistance, Manning's equation, critical flow conditions, and energy and momentum principles. It also covers flow measurement techniques, gradually varied flow analysis, and the design of open channels. Understanding these principles is vital for effective water resource management and engineering applications.
Accident detection system project report.pdfKamal Acharya
The Rapid growth of technology and infrastructure has made our lives easier. The
advent of technology has also increased the traffic hazards and the road accidents take place
frequently which causes huge loss of life and property because of the poor emergency facilities.
Many lives could have been saved if emergency service could get accident information and
reach in time. Our project will provide an optimum solution to this draw back. A piezo electric
sensor can be used as a crash or rollover detector of the vehicle during and after a crash. With
signals from a piezo electric sensor, a severe accident can be recognized. According to this
project when a vehicle meets with an accident immediately piezo electric sensor will detect the
signal or if a car rolls over. Then with the help of GSM module and GPS module, the location
will be sent to the emergency contact. Then after conforming the location necessary action will
be taken. If the person meets with a small accident or if there is no serious threat to anyone’s
life, then the alert message can be terminated by the driver by a switch provided in order to
avoid wasting the valuable time of the medical rescue team.
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...PriyankaKilaniya
Energy efficiency has been important since the latter part of the last century. The main object of this survey is to determine the energy efficiency knowledge among consumers. Two separate districts in Bangladesh are selected to conduct the survey on households and showrooms about the energy and seller also. The survey uses the data to find some regression equations from which it is easy to predict energy efficiency knowledge. The data is analyzed and calculated based on five important criteria. The initial target was to find some factors that help predict a person's energy efficiency knowledge. From the survey, it is found that the energy efficiency awareness among the people of our country is very low. Relationships between household energy use behaviors are estimated using a unique dataset of about 40 households and 20 showrooms in Bangladesh's Chapainawabganj and Bagerhat districts. Knowledge of energy consumption and energy efficiency technology options is found to be associated with household use of energy conservation practices. Household characteristics also influence household energy use behavior. Younger household cohorts are more likely to adopt energy-efficient technologies and energy conservation practices and place primary importance on energy saving for environmental reasons. Education also influences attitudes toward energy conservation in Bangladesh. Low-education households indicate they primarily save electricity for the environment while high-education households indicate they are motivated by environmental concerns.
We have designed & manufacture the Lubi Valves LBF series type of Butterfly Valves for General Utility Water applications as well as for HVAC applications.
Impartiality as per ISO /IEC 17025:2017 StandardMuhammadJazib15
This document provides basic guidelines for imparitallity requirement of ISO 17025. It defines in detial how it is met and wiudhwdih jdhsjdhwudjwkdbjwkdddddddddddkkkkkkkkkkkkkkkkkkkkkkkwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwioiiiiiiiiiiiii uwwwwwwwwwwwwwwwwhe wiqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq gbbbbbbbbbbbbb owdjjjjjjjjjjjjjjjjjjjj widhi owqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq uwdhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhwqiiiiiiiiiiiiiiiiiiiiiiiiiiiiw0pooooojjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj whhhhhhhhhhh wheeeeeeee wihieiiiiii wihe
e qqqqqqqqqqeuwiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiqw dddddddddd cccccccccccccccv s w c r
cdf cb bicbsad ishd d qwkbdwiur e wetwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww w
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffw
uuuuhhhhhhhhhhhhhhhhhhhhhhhhe qiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii iqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ccccccccccccccccccccccccccccccccccc bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum
m
m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm m i
g i dijsd sjdnsjd ndjajsdnnsa adjdnawddddddddddddd uw
This study Examines the Effectiveness of Talent Procurement through the Imple...DharmaBanothu
In the world with high technology and fast
forward mindset recruiters are walking/showing interest
towards E-Recruitment. Present most of the HRs of
many companies are choosing E-Recruitment as the best
choice for recruitment. E-Recruitment is being done
through many online platforms like Linkedin, Naukri,
Instagram , Facebook etc. Now with high technology E-
Recruitment has gone through next level by using
Artificial Intelligence too.
Key Words : Talent Management, Talent Acquisition , E-
Recruitment , Artificial Intelligence Introduction
Effectiveness of Talent Acquisition through E-
Recruitment in this topic we will discuss about 4important
and interlinked topics which are
Properties of Fluids, Fluid Statics, Pressure MeasurementIndrajeet sahu
Properties of Fluids: Density, viscosity, surface tension, compressibility, and specific gravity define fluid behavior.
Fluid Statics: Studies pressure, hydrostatic pressure, buoyancy, and fluid forces on surfaces.
Pressure at a Point: In a static fluid, the pressure at any point is the same in all directions. This is known as Pascal's principle. The pressure increases with depth due to the weight of the fluid above.
Hydrostatic Pressure: The pressure exerted by a fluid at rest due to the force of gravity. It can be calculated using the formula P=ρghP=ρgh, where PP is the pressure, ρρ is the fluid density, gg is the acceleration due to gravity, and hh is the height of the fluid column above the point in question.
Buoyancy: The upward force exerted by a fluid on a submerged or partially submerged object. This force is equal to the weight of the fluid displaced by the object, as described by Archimedes' principle. Buoyancy explains why objects float or sink in fluids.
Fluid Pressure on Surfaces: The analysis of pressure forces on surfaces submerged in fluids. This includes calculating the total force and the center of pressure, which is the point where the resultant pressure force acts.
Pressure Measurement: Manometers, barometers, pressure gauges, and differential pressure transducers measure fluid pressure.
Build the Next Generation of Apps with the Einstein 1 Platform.
Rejoignez Philippe Ozil pour une session de workshops qui vous guidera à travers les détails de la plateforme Einstein 1, l'importance des données pour la création d'applications d'intelligence artificielle et les différents outils et technologies que Salesforce propose pour vous apporter tous les bénéfices de l'IA.
3. Compilers
• “Compilation”
Translation of a program written in a source language into a semantically
equivalent program written in a target language
Compiler
Error messages
Source
Program
Target
Program
Input
Output
5. Preprocessors, Compilers, Assemblers,
and Linkers
Preprocessor
Compiler
Assembler
Linker
Skeletal Source Program
Source Program
Target Assembly Program
Relocatable Object Code
Absolute Machine Code
Libraries and
Relocatable Object Files
6. Phases
of
Compiler lexical analyzer
syntax analyzer
semantic analyzer
source program
tokens
parse trees
parse trees
intermediate code generator
code optimizer
code generator
intermediate code
optimized intermediate code
target program
7. Lexical Analysis
• The first phase of compiler is called as lexical analysis or
scanning
• The lexical analyser news live stream of characters making of
the source program and groups the character into meaningful
sequence of lexemes.
• The lexical analyser produces has an output of a token in the
form
<token name, attribute value>
• In the token the first component token name is the abstract
sample that is used during the syntax analysis and the
component attribute value points to the entry in the simple
table for this token
• Ex: Source input is
position =initial + rate * 60
8. • Position : the lexeme will match this as <id, 1>
• = : the lexeme will match this as <=>, because = is an abstract
symbol.
• Initial : the lexeme will match this as <id, 2>
• + : the lexeme will match this as <+>
• Rate: the lexeme will match this as <id, 3>
• * : the lexeme will match this as <*>
• 60: the lexeme will match this as <60>
<id,1> <=> <id, 2> <+> <id, 3> <*> <60> => lexmes
16. Qualities of a Good Compiler
What qualities would you want in a compiler?
• generates correct code (first and foremost!)
• generates fast code
• conforms to the specifications of the input language
• copes with essentially arbitrary input size, variables, etc.
• compilation time (linearly)proportional to size of source
• good diagnostics
• consistent optimisations
• works well with the debugger
17. The Evolution of Programing
Language
• The Move to High Level Language
1. A major step towards higher-level languages was nade in the
lat the 1930's with the development of Fortran for scientiic co
for business data processing, and Lisp for symbollc
computation.
2. Classification based on generation
a) First generation : machine languages
b) Second Generation : assembly languages
c) Third generation : high level languages like fortran, Cobol,C,C++
and Java
d) Fourth Generation : languages designed for specific applications
like SQL for database, NOMAD for report generation etc
e) Fifth generation : languages applied to logic and constraints based
like prolog andOPS5
18. 3. Classification of languages uses the term imperative and
declarative
a) imperative in which a program specifies how a computation is to
be done
b) declarative for languages in which a program specifies what
computation is to be done
c) Languages such as C. C++, C#, and Java are imperative languages
d) Functional languages such as ML and Haskell and constrain
languages such as Prolog are often considered to be declarative
languages
4. The term on Neumann language is applied to programming a whose
computational mode is based on the von Neumann computer
architecture , Many of today's languages, such as Fortran and C are von
Neumann languages
5. Based object oriented languages and scripting languages
20. Lexical Analysis
The first phase of the compiler, the main task of the lexical analyser is
to read the input characters of the source program,
group them into lexemes
produce the output as a sequence of tokens for each lexeme in the
source program
• As shown in the figure the call suggested by get next token command
causes the lexical analyser to read the characters from its input until it can
identify the next legs and produce for it the next token which in returns to
the parser.
Lexical
analyzer
symbol
table
parser
Source
program
token
getNexttoken()
21. Some Terminology
• A token is a pair consisting of a token name and optional
attribute value
• A pattern is a description of the form that the lexemes of a
token may take
• A Lexeme is a sequence of characters in the source program that
matches the pattern for a token and is identified by the lexical
analyser has a instance of that token
22. Lexical analyser is divided into cascade of two processor scanning
and lexical analysis
• Scanning: consists of a multiple processes that do not require
tokenization of the input such as deletion of comments
compaction of consecutive whitespace characters into one
• Lexical analysis: is a proper is the more complex portion which
produces the tokens from the output of the scanner
• Token syntax is
<token name, attribute value>
23. Ex: E = M * C ** 2
• For the above source program, the tokens are generated as by
using attribute value itself.
• <id, E>
• < assign_op>
• <id, M>
• < multi_op>
• <id, C>
• <exp_op>
• <number, 2>
Or
• <2>
24. Lexical Errors
• It is hard for a lexical analyzer to tell, without the aid of other
components, that there is a source-code error. For instance, if
the string fi is encountered for the first time in a C program in
the context:
Ex: fi (a=s f(x))
• a lexical analyzer cannot tell whether fi is a misspelling of the
keyword if or an undeclared function identifier.
• Since fi is a valid lexeme for the token id, the lexical analyzer
must return the token id to the parser and let some other
phase of the compiler—probably the parser in this case handle
an error due to transposition of the letters.
25. • The simplest recovery strategy is "panic mode recovery”.
• We delete successive characters from the remaining input,
until the lexical analyzer can find a well-formed token at the
beginning of what input is left.
• This recover technique may confuse the parser, but in an
interactive computing environment it may be quite adequate.
• Other possible error-recovery actions are:
1. Delete one character from the remaining input.
2. Insert a missing character into the remaining input.
3. Replace a character by another character.
4. Transpose two adjacent characters.
26. Input Buffering
• For instance we cannot be sure we've seen the end of an
identifier until we see a character that is not a letter or digit, and
therefore is not part of the lexeme for id.
• In C. single-character operators like -, , or < could also be the
beginning of a two-character operator like ->, s, or <#.
• Thus, we shall introduce a two-buffer scheme that handles large
lookhead safely and sentinels that saves the time checking for
the end of buffers.
27. Buffer Pair
• Specialized buffering techniques have been developed to reduce
the amount of overhead required to process a single input
character.
• An important scheme involves two buffers that are alternately
reloaded, as suggested in Fig.
forward
lexemeBegin
Fig: using a pair of input buffer
E = M * C * * 2 eof
28. • Two pointers to the input are maintained:
1. Pointer lexemeBegin, marks the beginning of the current lexeme,
whose extent we are attempting to determine.
2. Pointer forward scans ahead until a pattern match is found.
• Once the next lexeme is determined, forward is set to the
character at its right end. Then, after the lexeme is recorded as an
attribute value of a token returned to the parser, lexemebegin is
set to character immediately after the lexeme just found
29. Sentinels
• We must check, each time we advance forward, that we have not
moved off one of the buffers; if we do, then we must also reload the
other buffer.
• Thus for each character read, we make two tests:
one for the end of the buffer, &
one to determine what character is read.
• We can combine the buffer-end test with the test for the current
character if we extend each buffer to hold a sentinel character at the
end.
• The sentinel is a special character that cannot be part of the source
program, and a natural choice is the character eof.
E = M eof * C * * 2 eof eof
lexemeBegin forward
30. Specification of Tokens
Strings and Languages
1. {0, 1} is an binary alphabet.
2. A string over alphabet is a finite sequence of symbols drawn from that
alphabet.
3. The empty string is denoted by , the sting length is zero.
4. A language is any countable set of strings over some fixed alphabets
5. The language L containing an empty string is represented by { }
31. Specification of Tokens
Regular Expression
• Given an alphabet ,
1. is a regular expression and L { } is { }, the language whose member is
an empty string.
2. For each a , a is a regular expression denote {a}, the set containing
the string a.
3. r and s are regular expressions denoting the language L(r ) and L(s ). Then
( r ) | ( s ) is a regular expression denoting L( r ) U L( s )
( r ) ( s ) is a regular expression denoting L( r ) L ( s )
( r )* is a regular expression denoting (L ( r )) *
32. • Let = {a, b}
• a *
• a +
• a | b
• (a | b) (a | b)
• (a | b)*
• a | a*b
• The Grammar a|b identifies the language {a,b}
• The Grammar (a|b) (a|b) identifies the language {aa,ab,ba,bb}
• The Grammar a* identifies the language consisting string of zero or
more occurrences of a {, a, aa,aaaa,aaaa,aaaaa,}
• The Grammar a+ identifies the language consisting string of one or
more occurrences of a { a,aa,aaaa,aaaa,aaaaa,}
• The Grammar (a|b)* identifies the language {, a,b, aa, ab, ba, bb….}
• The Grammar a|a*b identifies the language {a, ab,aab,aaaab,….}
33. • Ex 1: To identify letters, digits, underscore
letters A|B|……|Z|a|b|…..|z|_
digit 0|1|2|…|9
id letter (letter|digit)*
34. • Ex 2: To identify unsigned numbers (integers or floating point)
such as 48618, 516.14,166.2-4e13, 0.15456E9
digit 0|1|2|….|9
digits digit digit*
optionalFraction . digits |
optinalExponent (e|E(+|-| )) digits |
number digits optionalFraction optinalExponent
36. Ex 2:
digit 0|1|2|….|9
digits digit digit*
optionalFraction . digit |
optinalExponent (e|E(+|-| )digits) |
number digits optionalFraction optinalExponent
Updated to
• digit [0-9]
• digits digit+
• number digits(.digits)? (e|E[+-]? digits )?
37.
38. • For the given regular expression grammar , describe the language
1. a(a|b)*a
2. (a|b)*a(a|b)(a|b)
3. a*ba*ba*ba*
39. Recognition of Token
• In our discussion we will make use of Dandling if loop statement.
stmt if expr then stmt
| if expr then stmt else stmt
|
expr term relop term
| term
term id
| number
A grammar for branching statement
40. • The grammar fragment describes a simple form of branching
statements and conditional expressions.
• For relop, we use the comparison operators of languages like
Pascal or SQL where = is "equals" and <> is "not equals," because
it presents an interesting structure of lexemes.
• The terminals of the grammar, which are if, then, else, relop, id,
and number, are the names of tokens as far as the lexical
analyzer is concerned.
• The patterns for these tokens are described using regular
definitions, as shown below.
41. digit [0-9]
digits digit+
number digits(.digits)? (e[+-]? digits )?
letter [A-Za-z_]
id letter (letter|digit)*
if if
then then
else else
relop < | > | <= | >= | = | < >
Patterns for token for if-else-then statement
For this language, the lexical analyzer will recognize the keywords
if, then, and else, as well as lexemes that match the
patterns for relop, id, and number
42. Lexemes Token name Attribute Value
if if -
then then -
else else -
any id id Pointer to table entry
any number number Pointer to table entry
< relop LT
<= relop LE
= relop EQ
< > relop NE
> relop GT
>= relop GE
43. Transition Diagrams
1. We always indicate an accepting state by a double circle.
2. If it is necessary to retract the forward pointer one position,
then we shall additionally place a * near that accepting state.
3. One state is designated the start state, or initial state it is
indicated by an edge labeled "start " entering from nowhere.
45. • We begin in state 0, the start state.
• If we see < as the first input symbol, then among the lexemes that
match the pattern for relop, we can be looking at <,<>, or <=.
• We therefore go to state 1, and look at the next character.
• If it is =, then we recognize lexeme <=, enter state 2, and return the
token relop with attribute LE, the symbolic constant representing
this particular comparison operator.
• If in state 1 the next character is >, then instead we have lexeme < >,
and enter state 3 to return an indication that the not-equals
operator has been found.
• On any other character, the lexeme is < and we enter state 4 to
return that information.
• Note, however, that state 4 has a* to indicate that we must retract
the input one position.
46. • Transition diagram for id’s and keywords
• Id-> letter(letter|digit)*
9 11
10 return (getToken(),
installID)
start letter other
letter or digit
*
47. • Transition diagram for unsigned numbers
• number digits(.digits)? (e[+-]? digits )?
12 14
13
start digit
other
digit
*
15
21
20
19
18
17
16
digit
digit
digit
digit
digit
other
other
*
*
.
E
E + or -
48. Lex
• Lex and YACC helps you write programs that transforms
structured input.
• Lex generates C code for lexical analyzer whereas YACC generates
Code for Syntax analyzer.
• Lexical analyzer is build using a tool called LEX.
• Input is given to LEX and lexical analyzer is generated.
• Lex is a UNIX utility.
• It is a program generator designed for lexical processing of
character input streams.
• It uses the patterns that match strings in the input and converts
the strings to tokens.
• Lex helps you by taking a set of descriptions of possible tokens
and producing a C routine, which we call a lexical analyzer
52. • The declarations section includes declarations of variables,
manifest constant (identifiers declared to stand for a constant,
e.g, the name of a token)
• The translation rules or rule section each have the form
Pattern { Action}
• Each pattern is a regular expression, which may use the regular
definitions of the declaration section.
• The actions are fragments of code, typically written in C.
• The third code section holds whatever additional functions are
used in the actions. Alternatively, these functions can be
compiled separately and loaded with the lexical analyzer.
53. Lex terms
Lex variables
yyin OfthetypeFILE*.Thispointstothecurrentfilebeingparsedbythelexer.
yyout
OfthetypeFILE*.Thispointstothelocationwheretheoutputofthelexer
willbewritten.By default,bothyyinandyyoutpointtostandardinputand
output.
yytext The text of the matched pattern is stored in this variable (char*).
yyleng Gives the length of the matched pattern.
Lex Functions
yylex() The functionthatstartsthe analysis.ItisautomaticallygeneratedbyLex.
yywrap()
Thisfunction iscalled when endoffile(orinput) isencountered.Ifthis
function returns 1,the parsing stops. So, this can be used to parse multiple
files.
54. Write a LEX program to recognize valid arithmetic expression
Prog1.l
%{
int op=0, id=0, br=0;
%}
%%
[+] {op++;}
[-] {op++;}
[*] {op++;}
[/] {op++;}
[a-z A-Z0-9]+ {id++;}
[(] {br++;}
[)] {br--;}
%%
56. [student@localhost ~]$ vi 1a.l
[student@localhost ~]$ lex 1a.l
[student@localhost ~]$ gcc lex.yy.c -ll
[student@localhost ~]$ ./a.out
Enter the arithmetic expression: a+b*(c/d)
no of identifiers are= 4
no of operators are =3
valid expression
[student@localhost ~]$ ./a.out
Enter the arithmetic expression : ab+(
no of identifiers are=2
no of operators are=3
invalid expression
[student@localhost ~]$
57. Finite Automata
• These are essentially graphs, like transition diagrams, with a few
differences:
1. Finite automata are recognizers; they simply say "yes" or "no"
about each possible input string.
2. Finite automata come in two flavours:
(a) Nondeterministic finite automata (NFA) have no restrictions on
the labels of their edges. A symbol can label several edges out of
the same state, and , the empty string, is a possible label.
(b) Deterministic finite automata (DFA) have, for each state, and for
each symbol of its input alphabet exactly one edge with that
symbol leaving that state.
Both deterministic and nondeterministic finite automata are capable
of rec organizing the same languages
58. Nondeterministic Finite Automata
(NFA)
• A nondeterministic finite automaton (NFA) consists of:
1. A finite set of states S.
2. A set of input symbols , the input alphabet. We assume that
, which stands for the empty string, is never a member of .
3. A transition function that gives, for each state, and for each
symbol in U{ } a set of next states.
4. A state so from S that is distinguished as the start state (or
initial state).
5. A set of states F, a subset of S, that is distinguished as the
accepting states (or final states).
We can represent either an NFA or DFA by a transition graph,
where the nodes are states and the labelled edges represent the
transition function.
59. NFA
• EX: the transition graph for an NFA accepting the language of
regular expression (a|b)*abb.
0 3
1
start
a
b
2
b
a
b
State a b
0 {0,1} {0}
1 {2}
2 {3]
3
Transition table for NFA for above diagram
Transtion diagarm for
(a|b)*abb.
60. NFA
• NFA accepting L(aa*|bb*)
0
2
1
3 4
start
a
b
a
b
State a b
0
1
2
3
4
61. Deterministic Finite Automata
(DFA)
• A DFA is a special case of NFA where.
1. There are no moves on input
2. For each state ‘s’ and input symbol ‘a’, there is exactly one
edge out of ‘s’ labelled ‘a’.
(Hint to remember: both incoming and outgoing edges names
should be same form one state)
We are using a transition table to represent a DFA, then each entry
is a single state. We may therefore represent this state without the
curly braces that we use to form set.
62. DFA
• EX: the transition graph for an DFA accepting the language of
regular expression (a|b)*abb.
0 3
1
start
b
b
2
b
a b
State a b
0 1 0
1 1 2
2 1 3
3 1 0
Transition table for DFA for above diagram
Transtion diagarm for
(a|b)*abb.
a
a
a