[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Non-textual semantic values for Tokens?


I am porting a compiler in C/flex/yacc to Java/SableCC. The original version
sometimes uses semantic actions in the flex input file to convert tokens to
semantic values that are appropriate for the type dealt with. For example,
tokens representing character constants will be converted to C chars, using
atoi() and that sort of conversion routines.
I'd like to know if you can do the same in SableCC.

I've looked in particular at the Basic interpreter example provided and have
noticed that it extracts those values only in later passes for the purpose
of interpretation. For now, I am planning on doing something similar: not
extract those semantic values until I need them, which is at code generation
in my case. I plan on using a hashTable indexed by AST node (like the in and
out provided by SableCC's analyses) to store them if I need them more than
once (which I probably won't...). Is there a better way to handle this?

My project supervisor finds it hard to believe that, in SableCC, you can't
do this sort of "semantic value extraction" while keeping the information
extracted in the AST itself. I may be missing something then...