2

I've been dabbling with scanners/parsers for a while and I got the hang of the basics involved in recursive descent parsing. I was thinking of implementing something more complex where I can define a proper language.

I don't use parser generators like ANTLR, SableCC, etc. which includes a token scanner and a rudimentary recursive descent parser. To this point, everything was pretty easy. Symbol table is simple a HashMap containing variable to int/string mappings. The best I could come up was Map-of-Maps to maintain hierarchy. This is inefficient and doesn't allow generic representation.

Could someone please show me how to elegantly represent a symbol table for storing type bound class hierarchies?

More precisely, I'm looking for expressing:

class MyType<A, X> extends SuperType<A, Integer> { ... }

... in a symbol table correctly.

Frankly, I'm lost; unable to even visualise how a structure to represent this would even look like.

Unmanned Player
  • 1,109
  • 9
  • 30
  • You just need to design a Symbol class that contains everything you need to know about the symbol. You'll be modifying it constantly while you develop your parser actions and subsequent tree processing. Just start. – user207421 Jan 31 '17 at 04:04
  • You're right, there will be a Symbol class, but what will I keep inside? The name of the class and.. ? The problem is it goes recursive and gets convoluted. – Unmanned Player Jan 31 '17 at 04:19
  • 1
    Real symbol tables tend to have hash maps for symbols-within-scopes, and complex relations between scopes if you language is complex (e.g., has generics, inheritance, interfaces, ... You can learn a little bit about symbol tables here: http://stackoverflow.com/a/32012786/120163 – Ira Baxter Jan 31 '17 at 05:53

0 Answers0