Irfan_Mohamed
asked on
Java Lexical Analyser
hi
just wanted to know how modify this code so that different identifiers are recorded iin the symbol table.
any commensts, advice would be appreciated
import java.util.*;
class SymbolTable
{
private Vector symbolTableEntries;
public SymbolTable()
{
symbolTableEntries = new Vector(); // create "empty" vector
}
public int length()
{
/*
Return the number of entries in the Symbol Table.
*/
return symbolTableEntries.size();
}
public int lookupIdentifier(String id)
{
/*
Return index of entry in the symbol table for identifier id. If the identifier
is not already in the table, it is added
*/
// search existing entries and return if identifier found
for (int i=0; i<symbolTableEntries.size( ); i++)
if ( ( (SymbolTableEntry) symbolTableEntries.element At(i) ).idName.equals(id) )
return i;
// name must not be in the table, so add it
SymbolTableEntry entry = new SymbolTableEntry(id);
symbolTableEntries.add(ent ry);
return symbolTableEntries.size()- 1;
}
public String getIdentifier(int index)
{
/*
Return the identifier at position index of the symbol table, or
null if invalid index.
*/
return ( (SymbolTableEntry) symbolTableEntries.element At(index) ).idName;
}
class SymbolTableEntry
{
String idName;
public SymbolTableEntry(String s)
{
idName = s;
}
}
}
just wanted to know how modify this code so that different identifiers are recorded iin the symbol table.
any commensts, advice would be appreciated
import java.util.*;
class SymbolTable
{
private Vector symbolTableEntries;
public SymbolTable()
{
symbolTableEntries = new Vector(); // create "empty" vector
}
public int length()
{
/*
Return the number of entries in the Symbol Table.
*/
return symbolTableEntries.size();
}
public int lookupIdentifier(String id)
{
/*
Return index of entry in the symbol table for identifier id. If the identifier
is not already in the table, it is added
*/
// search existing entries and return if identifier found
for (int i=0; i<symbolTableEntries.size(
if ( ( (SymbolTableEntry) symbolTableEntries.element
return i;
// name must not be in the table, so add it
SymbolTableEntry entry = new SymbolTableEntry(id);
symbolTableEntries.add(ent
return symbolTableEntries.size()-
}
public String getIdentifier(int index)
{
/*
Return the identifier at position index of the symbol table, or
null if invalid index.
*/
return ( (SymbolTableEntry) symbolTableEntries.element
}
class SymbolTableEntry
{
String idName;
public SymbolTableEntry(String s)
{
idName = s;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- Split points between randyd and csar
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venabili
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- Split points between randyd and csar
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venabili
EE Cleanup Volunteer
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.