managing the symbol table - hampden-sydney...

47
Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb T. Koether Hampden-Sydney College Fri, Mar 6, 2015 Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 1 / 26

Upload: others

Post on 31-Aug-2019

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol TableLecture 21

Sections 2.7, 5.1

Robb T. Koether

Hampden-Sydney College

Fri, Mar 6, 2015

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 1 / 26

Page 2: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 2 / 26

Page 3: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 3 / 26

Page 4: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Symbol Table Members

Symbol Table MembersLinkedList id_tableint level

id_table – The linked list of hashtables of symbols.level – The current level in the linked list.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 4 / 26

Page 5: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Symbol Table Functions

Symbol Table Functionsvoid init()

void init_keywords()

void install_keyword()

void enter_block()

void leave_block()

IdEntry id_lookup(String name, int blk_lev)

IdEntry install(String name, int blk_lev)

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 5 / 26

Page 6: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 6 / 26

Page 7: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function init()

The Function init()id_table = new LinkedList<Hashtable<String, IdEntry>>();id_table.addLast(null);

Create a linked list.Create a null hash table at level 0 (node 0).

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 7 / 26

Page 8: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function init_keywords()

The Function init_keywords()install_res_word(sym.INT, "int");install_res_word(sym.DOUBLE, "double");

...

Initialize the symbol table with all the keywords.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 8 / 26

Page 9: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function install_keyword(kw)

The Function install_keyword(kw)IdEntry p = install(kw, 1);p.type = t;

Install the keyword s at level 1 of the symbol table.The install() function returns a reference to the IdEntry inthe table.Set the type attribute to t.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 9 / 26

Page 10: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 10 / 26

Page 11: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function enter_block()

The Function enter_block()level++;id_table.addLast(new Hashtable<String, IdEntry>());

This function creates a new hash table at the next higher level.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 11 / 26

Page 12: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function leave_block()

The Function leave_block()id_table.removeLast();level-;

This function removes the hash table from the highest level.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 12 / 26

Page 13: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 13 / 26

Page 14: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function id_lookup(name, blk_lev)

The Function id_lookup()Identry id = null;Hashtable<String, Identry> ht = id_table.get(blk_lev);id = ht.get(name);

If blk_lev is positive, then id_lookup() searches only thehash table at that level.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 14 / 26

Page 15: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function id_lookup(name, blk_lev)

The Function id_lookup()Identry id = null;for (int i = id_table.size() - 1; i > 0; i-){

Hashtable<String, Identry> ht = id_table.get(i);id = ht.get(name);if (id != null) break;

}

If blk_lev is 0, then id_lookup() searches all hash tables,beginning at the highest level.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 15 / 26

Page 16: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 16 / 26

Page 17: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function install(name, blk_lev)

The Function install()Hashtable<String, Identry> ht = id_table.get(blk_lev);IdEntry id = new IdEntry();id.name = s;id.block_level = blk_lev;ht.put(s, id);

If blk_lev is 0, then install() installs the identifier at thecurrent level, level.If blk_lev is positive, then install() installs the identifier atthat level.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 17 / 26

Page 18: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 18 / 26

Page 19: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Lexer and the Symbol Table

The lexer must distinguish between identifiers and keywords.We could write a separate regular expression for each keyword:"int" {return new Symbol(sym.INT)}

However, this would make the lexer much more complicated.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 19 / 26

Page 20: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Lexer and the Symbol Table

When a token consists of a string of letters, the lexer will checklevel 1 of the symbol table.If the string is found there, then the lexer will return theappropriate keyword token.If the string is not found there, then the lexer will assume that it isan identifier and return an identifier token.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 20 / 26

Page 21: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function lookup(name)

The Function lookup(name)IdEntry entry = SymbolTable.id_lookup(name, 1);if (entry != null)

return new Symbol(entry.type);else

return new Symbol(sym.ID, s);

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 21 / 26

Page 22: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

The Function lookup(name)

The lookup() function is placed in the directive section of theflex file, within %{ and %}.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 22 / 26

Page 23: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 23 / 26

Page 24: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

Processing the statement int count;

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 25: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"int"

The Lexer sees “int”

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 26: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"int"

lookup("int", 1)

Search the Symbol Table for keyword “int”

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 27: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"int"

not null

Keyword “int” is found

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 28: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"int" sym.INT

Send the INT token to the Parser

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 29: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"int" sym.INT type ::= INT

The Parser matches type→ INT

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 30: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count"

The Lexer sees “count”

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 31: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count"

lookup("count", 1)

Search the Symbol Table for keyword “count”

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 32: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count"

null

Keyword “count” is not found

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 33: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count"sym.ID, "count"

Send the ID token to the Parser

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 34: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count" lval ::= ID

The Parser matches lval → ID

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 35: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count" lval ::= IDid("count")

Invoke the Semantic Action id("count")

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 36: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count"

id_lookup("count", 0)

lval ::= ID

Look up “count” in the Symbol Table

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 37: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count" lval ::= ID

null

“count” is not found

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 38: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

"count" lval ::= ID

install("count", 0)

IdEntryname = "count"

Install “count” in the Symbol Table

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 39: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";"

IdEntryname = "count"

The Lexer sees “;”

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 40: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";"sym.SEMI

IdEntryname = "count"

Send the SEMI token to the Parser

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 41: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";"sym.SEMI

dcl ::= type ID ;

IdEntryname = "count"

The Parser matches dcl → type ID ;

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 42: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";" dcl ::= type ID ;dcl("count", 0)

IdEntryname = "count"

Invoke the Semantic Action dcl("count", 0)

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 43: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";"

install("count", 0)

dcl ::= type ID ;

IdEntryname = "count"

Invoke install("count", 0)

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 44: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";" dcl ::= type ID ;

IdEntryname = "count"

IdEntry

Retrieve the IdEntry for count

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 45: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Managing the Symbol Table

Lexer ParserSemantic

Action

SymbolTable

";" dcl ::= type ID ;

IdEntryname = "count"type = INT

Update the type of count to INT

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 24 / 26

Page 46: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Outline

1 Symbol Table FunctionsInitialization Functionsenter_block() and leave_block()id_lookup()install()

2 The Lexer and the Symbol Table

3 An Example

4 Assignment

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 25 / 26

Page 47: Managing the Symbol Table - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures/Spring 2015/Lecture...Managing the Symbol Table Lecture 21 Sections 2.7, 5.1 Robb

Assignment

HomeworkRead Sections 2.7 and 5.1.

Robb T. Koether (Hampden-Sydney College) Managing the Symbol Table Fri, Mar 6, 2015 26 / 26