Mod 2.2 (lexical analyzer) Flashcards

1
Q

tasks performed by the lexical analyzer

A
  • identification of lexemes
  • identifying and removal of any extra whitespaces and stripping out comment lines
  • corelating the error messages with the source program
  • expanding the macros in the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a token

A

a terminal symbol in the grammar for the source language

it is an abstract symbol representing a kind of lexical unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a pattern

A

a rule that describe a set of lexemes that can represent a particular token in the source program
a pattern in a description of the form that lexemes of a token might take

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a lexeme

A

it is a sequence of characters in the source program that is matched by the pattern for a token
it is a sequence of characters and is identified by the lexical analyzer as an instance of that token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is input buffering

A

lexical analyzer is the only phase of the compiler that reads the source program. since it reads the program character by character, the speed of this operation needs to be considered.
it also needs to look at one or more characters beyond the next lexeme before we have the right lexeme

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Buffer pairs

A

the buffer consists of two pointers
- beginning of lexeme pointer
- forward pointer
both point to the first character of the next lexeme to be found
forward pointer scans at least until a match for a pattern is found

if the forward pointer moves past the halfway mark, then the other half of the buffer is filled with new characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sentinels

A

when the forward pointer is moved to a new input, it needs to check for two conditions: if it is the end of the buffer and to determine what character is read
we can combine these two test into a single test if we extend each buffer to hold a “eof” sentinel character at the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly