Professional Documents
Culture Documents
Lecture 2-3 (CMS)
Lecture 2-3 (CMS)
Lecture 2-3 (CMS)
4. It needs to enter that lexeme into the symbol table and also
reads from the symbol table.
– PATTERN
• A rule describing a set of strings
– LEXEME
• a sequence of characters that match some pattern
• Identifiers: x, count, name, etc…
else a Identifier
, Separator
return b;
int Keyword
} b Identifier
) Separator
{ operator
if Keyword
.. ..
BITS Pilani, Hyderabad Campus
Example - 2
YES NO
BITS Pilani, Hyderabad Campus
Attributes for tokens
➢ When more than one lexeme can match a pattern, the lexical analyzer must
provide the subsequent compiler phases additional information about the
particular lexeme that matched.
i.e., <token name, attribute value>
➢ Token name influences parsing decisions,
➢ Attribute value influences translation of tokens after the parse.
➢ We shall assume that tokens have at most one associated attribute, although
this attribute may have a structure that combines several pieces of
information.
➢ Example: token name id,
➢ Information: its lexeme, its type, and the location at which it is first
found is kept in the symbol table.
➢ Thus, the appropriate attribute value for an identifier is a pointer to
the symbol table entry for that identifier.
BITS Pilani, Hyderabad Campus
Attributes for tokens
➢ Empty string
➢ String Concatenation
BITS Pilani, Hyderabad Campus
Operations on Lanaguages
➢ 𝜖 is a R.E. (denotes 𝜖 )
𝐿𝑒𝑡𝑡𝑒𝑟 → 𝑎 − 𝑧
𝐷𝑖𝑔𝑖𝑡 → 0 − 9
𝐼𝐷 → 𝐿𝑒𝑡𝑡𝑒𝑟(𝐿𝑒𝑡𝑡𝑒𝑟|𝐷𝑖𝑔𝑖𝑡)∗
➢ Now, we must study how to take the patterns for all the needed
tokens and build a piece of code that examines the input string
and finds a prefix that is a lexeme matching one of the patterns