## Symbol Table in Java

Symbol Table Definition :

In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating to its declaration or appearance in the source, such as its type, scope level and sometimes its location.

Symbol Table code using java :

I will be reading a file named 4th.txt which has a c/c++ code in it and then it makes a symbol table of the code given.

4th.txt :

```#include<iostream.h>

viod main(){

int a,b,c=10;

cout<<a;

cout<<b;

float flt=10.20;

float flt1=10.20;

cout<<flt;

```

JAVA CODE :
` `
```import java.io.BufferedReader;
import java.io.File;
import java.util.StringTokenizer;

public class SymbolTable {

public static void main(String[] args) {

try{
String s;
String fr[];
String data[]=null;
String val[]=null;
String var[]=null;
int st,ed,ln,i=0;
File f=new File("4th.txt");
System.out.println("Datatype \t Variable \t Current Value");
StringTokenizer str=new StringTokenizer(s);
if(s.contains("int")==true){
fr=s.split(" ");
System.out.println();
System.out.print(fr + "\t\t ");
fr=fr.replaceAll(","," ");
var=fr.split(" ");

for(i=0;i<var.length;i++){
if(var[i].contains("=")==true){
var=var[i].split("=");
for(i=0;i<var.length;i++){

System.out.print(var[i].replace(';', ' '));
System.out.print("\t\t ");
}

}else{
System.out.print(var[i]);
System.out.print("\t\t ");
System.out.print(0);
System.out.println();
System.out.print("\t\t ");

}
}

}else if(s.contains("float")==true){
fr=s.split(" ");
System.out.println();
System.out.print(fr + "\t\t ");
fr=fr.replaceAll(","," ");
var=fr.split(" ");

for(i=0;i<var.length;i++){
if(var[i].contains("=")==true){
var=var[i].split("=");
for(i=0;i<var.length;i++){

System.out.print(var[i].replace(';', ' '));
System.out.print("\t\t ");
}

}else{
System.out.print(var[i]);
System.out.print("\t\t ");
System.out.print(0);
System.out.println();
System.out.print("\t\t ");

}
}

}
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}

}
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5236262,"math_prob":0.934391,"size":2347,"snap":"2019-51-2020-05","text_gpt3_token_len":616,"char_repetition_ratio":0.18992744,"word_repetition_ratio":0.43678162,"special_character_ratio":0.33020878,"punctuation_ratio":0.2768166,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9898083,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-17T17:17:20Z\",\"WARC-Record-ID\":\"<urn:uuid:20c0b90b-3bbe-4a5d-927b-d08c205abef3>\",\"Content-Length\":\"128166\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6fe32708-07e4-4eeb-990d-c34f887739ae>\",\"WARC-Concurrent-To\":\"<urn:uuid:8bdb7187-e6cf-4f9c-9485-e1a37692677b>\",\"WARC-IP-Address\":\"172.217.7.243\",\"WARC-Target-URI\":\"http://www.code2learn.com/2011/02/symbol-table-in-java.html\",\"WARC-Payload-Digest\":\"sha1:JYTRIOUSFFTDNW3UR3GCAFEVPWI22VDM\",\"WARC-Block-Digest\":\"sha1:XPC3RLXMPYIN6EK4GQL6OZDKJQGMLU3T\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250589861.0_warc_CC-MAIN-20200117152059-20200117180059-00018.warc.gz\"}"}