Preview

Lexical Analyzer: Reads Source Program Character-by-Character to Produce Tokens

Good Essays
Open Document
Open Document
2518 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Lexical Analyzer: Reads Source Program Character-by-Character to Produce Tokens
Lecture Two

Lexical Analysis

1

What is Lexical Analysis?
Lexical Analyzer reads the source program character by character to produce tokens. Normally a lexical analyzer doesn’t return a list of tokens at one shot, it returns a token when the parser asks a token from it.

source program

lexical analyzer

token

parser get next token

symbol table
2

The lexical analyzer deals with small-scale language constructs, such as names and numeric literals. The syntax analyzer deals with the largescale constructs, such as expressions, statements, and program units. The syntax analysis portion consists of two parts:
1. A low-level part called a lexical analyzer (essentially a pattern matcher). 2. A high-level part called a syntax analyzer, or parser.

The lexical analyzer collects characters into logical groupings and assigns internal codes to the groupings according to their structure.
3

Lexical Analyzer in Perspective
LEXICAL ANALYZER
Scan Input Remove white space, … Identify Tokens Create Symbol Table Generate Errors Send Tokens to Parser

PARSER
Perform Syntax Analysis Actions Dictated by Token Order Update Symbol Table Entries Create Abstract Rep. of Source Generate Errors

4

Lexical analyzers extract lexemes from a given input string and produce the corresponding tokens. Sum = oldsum – value /100; Token
IDENT ASSIGN_OP IDENT SUBTRACT_OP IDENT DIVISION_OP INT_LIT SEMICOLON
5

Lexeme sum = oldsum value / 100 ;

Basic Terminology
What are Major Terms for Lexical Analysis?
TOKEN

A classification for a common set of strings Examples Include , , etc.
PATTERN

The rules which characterize the set of strings for a token
LEXEME

Actual sequence of characters that matches pattern and is classified by a token Identifiers: x, count, name, etc…
6

Basic Terminology
Token
const if relation id num literal if , >= pi, count, D2 3.1416, 0, 6.02E23 “core dumped”

Sample Lexemes const if

Informal Description of

You May Also Find These Documents Helpful

  • Powerful Essays

    Lexical Analyzer

    • 2938 Words
    • 12 Pages

    Lexical Analysis Made with OpenOffice.org 1 The role of lexical analyzer: analyzer: It is the first phase of a compiler. compiler. Its main task is to read the input characters & produce as output a sequence of tokens that the parser uses for syntax analysis. analysis. Upon receiving a “get next token” command from the parser, the lexical analyzer reads input characters until it can identify the next token. token. It may also perform certain secondary tasks at the user interface. interface…

    • 2938 Words
    • 12 Pages
    Powerful Essays
  • Powerful Essays

    Gas Analyzer

    • 5081 Words
    • 21 Pages

    Gas analysis techniques Terms for gas analysis techniques Concentration The term concentration describes the amount of a substance, expressed as mass, volume, or number of particles in a unit volume of a solid, liquid, or gaseous substance e.g. alcohol in beer or oxygen in air. Different units are in use to describe concentration in gases: Mass concentration Concentration expressed in terms of mass of substance per unit volume [g substance/m3 gas volume] ¢ Volume concentration Concentration…

    • 5081 Words
    • 21 Pages
    Powerful Essays
  • Powerful Essays

    implement a character education program at Hollister High School. After collaborating with the members of the Character Education focus team and veteran members of the high school staff, there was a general consensus that the programs of the past questioned the student’s intelligence in terms of the character lessons being taught. The lessons did not make the students think. The lessons were designed for students a lot younger than high school aged young adults. The team had to develop program that…

    • 1691 Words
    • 7 Pages
    Powerful Essays
  • Good Essays

    Book Review of “The Characters of Revolutionary Characters” by Gordon S. Wood “The characters of Revolutionary Characters” is a realistic portrayal of six most important members of the founding generation of the United States. They are: George Washington, Ben Franklin, Thomas Jefferson, James Madison, Aaron Burr, John Adams, Alexander Hamilton, Thomas Paine. The Founders, indeed, were a highly unique and exceptionally talented generation. The book takes as its accent not the story…

    • 1158 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Lexical Deviation

    • 1375 Words
    • 6 Pages

    LEXICAL DEVIATION Deviation corresponds to the traditional idea of poetic license: the writer of literature is allowed in contrast to the everyday speaker to deviate from rules, maxims, or conventions. These may involve the language, as well as literary traditions or expectations set up by the text itself. The result is some degree of surprise in the reader, and his/her attention is thereby drawn to the form of the text itself (rather than to its content). Cases of neologism, live metaphor, or ungrammatical…

    • 1375 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Character

    • 639 Words
    • 3 Pages

    I, , read 471 pages of Graceling by Kristin Cashore. This book has a majority of conflicts that are solved throughout the novel, though the main conflicts occur in the very first chapter, when Katsa, the main character, rescues a Lienid grandfather who had been kidnapped and imprisoned in a dungeon cell. This books genre is fiction since this story occurs in a very different world from ours. Kasta and the council, a group that has grown throughout all seven kingdoms, know who kidnapped the Lienid…

    • 639 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Character

    • 497 Words
    • 2 Pages

    Character An individual’s character is based on a set of behavior traits that define the inner-self of a person. It determines whether a person will effectively achieve goals, have positive people skills, and/or obey the laws and rules of society. An individual’s character is a learned behavior. An individual typically develop their character from their surroundings such as parents, teachers, and friends. This development is either taught or observed by watching or listening to others…

    • 497 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Character

    • 796 Words
    • 4 Pages

    Character Sketch Examples: "Glory, be! Look whose here." Grandma said, wiping her wrinkled hands on her faded apron. She shuffled slightly as though she were about to step on into the dining room, but before she could make her move, my mother had dashed across the room and was giving her a hug. Dad and I followed sheepishly across the rooom, knowing that the mandatory hug was about to happen. When it was my turn, I could feel the soft, loose flesh of Grandma's sagging arms as she hugged me close…

    • 796 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    characters

    • 507 Words
    • 4 Pages

    Invent a Character By Kimberly Dana, Award-Winning Author ©Kimberly Dana Invent a Character - Introduction About the Packet: During author visitations, kids will often ask me how I invent my characters. I tell them I think about someone interesting - then I think about their favorite candy bar. They chuckle and I say, “Seriously! This is how well you need to know and understand your characters.” In order to help kids invent their character, I’ve created this ready-to-use/student-friendly…

    • 507 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    Characters

    • 1857 Words
    • 5 Pages

    Characters- be they villains, vagrants, kings, or commoners – are the essence of Shakespeare’s plays. The essence of anything lies in the set of attributes that render it the characteristics of its substance, purpose and function. In Shakespeare’s play, “Macbeth”, the essence of the play are the characters. Shakespeare uses a variety of different characters and all of them carry a different idea about our society. This includes kings, who carry the idea of chivalry, majesty and kindness; villains…

    • 1857 Words
    • 5 Pages
    Powerful Essays