Compiler Construction Chapter 2 Scanning-Books Pdf

Compiler Construction Chapter 2 Scanning
06 Aug 2020 | 1 views | 0 downloads | 109 Pages | 893.38 KB

Share Pdf : Compiler Construction Chapter 2 Scanning

Download and Preview : Compiler Construction Chapter 2 Scanning

Report CopyRight/DMCA Form For : Compiler Construction Chapter 2 Scanning



Transcription

Tokens Patterns and Lexemes, Lexical Errors, Symbol Tables and Hash Tables. Tokens Languages and Regular Definitions, Recognition of Tokens. Finite Automata, Regular Expression NFA, 2 Chapter 2 Scanning January 2010. Scanning or Lexical Analysis, A scanner is an implementation of a deterministic finite. automaton DFA finite state machine, That is looping but no recursion is allowed.
3 Chapter 2 Scanning January 2010, The Role of the Lexical Analyzer. The lexical analyzer or scanner is the first phase of a compiler. Its main task is to read the input characters and produce a sequence of. tokens for the syntax analyzer, More compact representation of input and easier to deal with later. All Scanners do basically the same thing only recognize different tokens. It is usually implemented as a subroutine which the syntax analyzer calls. whenever it wants the next token, The lexical analyzer returns a token and then waits for the next call. A secondary task of the lexical analyzer is to ignore white space spaces. tabs and newline characters in the source and comments. Another task might be to keep track of line numbers so meaningful error. messages can be generated, 4 Chapter 2 Scanning January 2010. Tokens Patterns and Lexemes, The terms token pattern and lexeme have specific meanings.
The lexical analyzer returns a token of a certain type to the parser. whenever it sees a sequence of input characters a lexeme that. matches the pattern for that type of token, An Example of some lexemes. Token Lexeme, The pattern for the RELOP token, contains six different lexemes IFTOK if. and THENTOK then, Many tokens such as IFTOK THENTOK ELSETOK else. have single lexeme patterns, The patterns for the ID and NUM RELOP. tokens are described by regular ASSIGNOP, expressions ID letter letter digit.
Informally a lexeme for the ID token, must start with a letter followed by NUM digit digit. zero or more letters and digits SEMITOK, 5 Chapter 2 Scanning January 2010. Tokens Patterns and Lexemes, Lexical analysis is complicated in some languages FORTRAN for example allows. white space inside of lexemes The FORTRAN statement. DO 5 I 1 25, is an assignment statement with three tokens. ID ASSIGNOP NUM, but the FORTRAN statement, DO 5 I 1 25.
is a DO statement with seven tokens, DOTOK NUM ID ASSIGNOP NUM COMMA NUM. DO 5 I 1 25, Before the lexical analyzer can produce the first token it must look ahead to see if. there is a dot or a comma in this statement, 6 Chapter 2 Scanning January 2010. Tokens Patterns and Lexemes, Most languages have keywords strings of letters that. have pre defined meanings so they can not be used as. identifiers, For example keywords in Pascal are if then else etc.
The PL I language does not reserve its keywords so. distinguishing between a keyword and an identifier is very. complicated, For example, IF THEN THEN, is a legal PL I statement. 7 Chapter 2 Scanning January 2010, Typical Token Classes. Reserved words keywords, if while do, Identifiers, interest x23 z over. Literals constants, 42 3 14159 Hello, Special symbols operators. White space blanks tabs comments newlines other, control characters.
8 Chapter 2 Scanning January 2010, TINY Tokens, Reserved words Special symbols Other. then 1 or more, repeat identifier, read 1 or more, write letters. 9 Chapter 2 Scanning January 2010, Attributes for Tokens. The pattern for the RELOP token in Pascal contains six. The syntax analyzer only needs to know that the token is a. relational operator, But later phases will have to know which of the six relational. operators is specified, So the lexical analyzer must return this attribute with the.
RELOP token, 10 Chapter 2 Scanning January 2010, Attributes for Tokens. The lexical analyzer must also return attributes with. other multi lexeme tokens, The UNARYOP ADDOP MULOP BCONST ID and NUM. A pointer to the symbol table entry is all that is required for an. An easy way to handle a NUM token is to store its lexeme in. the symbol table and return a pointer to that entry. One way to handle the other multi lexeme tokens is to pre. store all their lexemes in the symbol table so the lexical. analyzer can return a pointer to a symbol table entry in all. 11 Chapter 2 Scanning January 2010, Lexical Errors. A lexical error is a sequence of characters that does not. match the pattern of any token, The most common causes of a lexical error are. The addition of an extraneous character, The removal of a character that should be present.
The replacement of a correct character with an incorrect. character and, The transposition of two characters. 12 Chapter 2 Scanning January 2010, Lexical Errors. The theoretically best way of handling a lexical error is. to find the closest character sequence that does match a. pattern but this will take too much time and is never. used in a practical compiler, A way to handle a lexical error is to store the bad. character in the symbol table and return an ERROR, token to the syntax analyzer with a pointer to the. symbol table entry, 13 Chapter 2 Scanning January 2010.
Symbol Tables, The symbol table sometimes called a dictionary keeps track of information about the. symbols identifiers that the source program is using. Names of scalars arrays and functions etc, That is it associates attributes with names. Attributes are a representation of the semantics of the names. What are useful attributes, Numbers can go in the symbol table values must be stored somewhere. They can also be stored in a separate table, A language like C allows unions so you can return the value instead of a STptr. Keywords like if while and real can also go in the symbol table. The keywords are pre loaded into the symbol table before any of the source program is read so the. first time the source program uses a keyword it will be assigned the proper token type. The lexical analyzer can be simplified by also pre loading the other lexemes like and. into the symbol table, 14 Chapter 2 Scanning January 2010.
Symbol Tables Attributes, What do we store, What do we store. Think about C, Boolean char integer real, Pointer array function. Compiler Construction Chapter 2 Scanning Slides modified from Louden Book and Dr Scherger Contents Chapter 2 Scanning January 2010 Scanning Tokens Patterns and Lexemes Lexical Errors Scope Symbol Tables and Hash Tables Tokens Languages and Regular Definitions Recognition of Tokens Finite Automata NFA DFA Regular Expression NFA 2 Scanning or Lexical Analysis Chapter 2 Scanning

Related Books

FLEXING COUPLING Type N EUPEX Motor Pump Ventilation com

FLEXING COUPLING Type N EUPEX Motor Pump Ventilation com

To be agreed If operating or plant behaviour requires a higher bal ancing quality this must be agreed separately For peripheral speeds of v gt 30 m s Render recommends a balancing quality of G6 3 which can be carried out in two planes if required and must also be ordered separately

Operating Instructions and Parts Manual 16 x 52 inch Foot

Operating Instructions and Parts Manual 16 x 52 inch Foot

Operating Instructions and Parts Manual 16 x 52 inch Foot Shear Model FS 1652J JET 427 New Sanford Road Before operating the foot shear remove tie rings watches and other jewelry and roll sleeves up past the elbows Do not wear loose clothing Confine long hair Non slip footwear or anti skid floor strips are recommended 8 Wear ear protectors plugs or muffs if noise reaches unsafe

Operating Instructions and Parts Manual Shear Brake and

Operating Instructions and Parts Manual Shear Brake and

4 0 About this manual This manual is provided by JET covering the safe operation and maintenance procedures for a JET model SBR 30M and SBR 40M Shear Brake and Roll This manual contains instructions on installation safety precautions general operating procedures maintenance instructions and parts breakdown Your machine has

Lengua castellana evaluaci n Control y 2

Lengua castellana evaluaci n Control y 2

2 Completa estas palabras con mb o mp 10 A las 9 de la ma ana A las 2 de la tarde A las 6 de la tarde A las 9 de la noche colu io l ar ta o bo ill so r ca an bo o gt e a ulanci tro et 3 Ordena las piezas de forma diferente y escribe dos oraciones en cada caso

GEOGRAF A E HISTORIA Portfolio Anaya Educaci n

GEOGRAF A E HISTORIA Portfolio Anaya Educaci n

ESO GEOGRAF A E HISTORIA Portfolio 2 ndice El portfolio y su inclusi n en nuestro proyecto 3 Gu a para trabajar con el portfolio 9 Introducci n Propuestas de trabajo para el comienzo del curso Propuestas de trabajo para cada unidad Propuestas de trabajo para cada trimestre Propuestas de trabajo para finalizar el curso Propuestas de trabajo

Tareas competenciales para preparar las pruebas de diagn stico

Tareas competenciales para preparar las pruebas de diagn stico

allende2 la morer a Ni la quiero por mujer cristiano que all pasare ni la quiero por amiga yo le quitar la vida pues que no pude gozar No lo hagas compa ero de aquella que m s quer a Romancero viejo Catedra 1 Tornar convertir 2Allende de la parte de 3Garrida hermosa 2 Cu ntas personas hablan en este poema

Pruebas de evaluaci n jcyl es

Pruebas de evaluaci n jcyl es

Evaluaciones con el que podr obtener pruebas para evaluar cada unidad individualmente o junto con otras unidades Incluye tambi n una prueba de evaluaci n inicial para evaluar los preconceptos de sus estudian tes en relaci n con los contenidos del curso y una prue ba de evaluaci n final con la que podr comprobar el grado de adquisici n de los contenidos de la materia competencias

CIENCIAS SOCIALES 2 ESO RES MENES DE LOS TEMAS

CIENCIAS SOCIALES 2 ESO RES MENES DE LOS TEMAS

2 ESO RES MENES DE LOS TEMAS T 2 N UEVO D EMOS 2 Res menes de los apartados 3 Los castillos medievales n Los castillos medievales eran las residencias de los se ores feudales En caso de ataques o invasiones serv an tambi n como refugio para los habitantes del feudo n El centro del castillo lo ocupaba la torre del homenaje lugar de residencia y de vigilancia rodeada por otras

J Colera I Gaztelu

J Colera I Gaztelu

3 Esta serie de Matem ticas responde a un proyecto pedag gico creado y desarrollado por Anaya Educaci n para la ESO En su elaboraci n han participado Autores Jos Colera e Ignacio Gaztelu Coordinaci n editorial Mercedes Garc a Prieto

19 20 CULTURA CL SICA 2 ESO IES Condesa Eylo

19 20 CULTURA CL SICA 2 ESO IES Condesa Eylo

2 En el mes de Junio se realizar un examen global para los alumnos que hayan suspendido una o varias de las evaluaciones Al ser un examen de contenidos m nimos s lo podr ser calificado como aprobado o suspenso y no se podr realizar para subir nota salvo indicaci n expresa del profesor

ACTIVIDADES DE REPASO MATEM TICAS 2 ESO

ACTIVIDADES DE REPASO MATEM TICAS 2 ESO

a 2 74 12 3 b 7 0 12 1 1 2 34 c 20 3 3 25 22 Juan va al mercado con 50 euros y compra 2 kilos y medio de pl tanos a 0 90 kg un kilo de carne de vaca a 11 6 Kg 3 kilos y cuarto de naranjas a 0 90 kg una docena de huevos a 10 c ntimos cada huevo Cu nto dinero le sobra