|
Actually... I think I realised I am missing storing some information (though still not sure what to store for class/functions/methods).
Currently I'm just printing out for each variable...
* name (the identifier name e.g. a, x)
* type (int, boolean, char, class)
* kind (static, field, arg, var).
* index (offset)
...but these should be stored in the symbol table also. So classes and function names could be stored as
* name (the identifier name, e.g. MyClass, someFunction, someMethod)
* type (not applicable? the return type? the class name (for methods)?)
* kind (class, method, function, constructor).
* index (not applicable?)
In a structure similar to (JSON shown here). Note: since there is only one symbol table per class, we know that every method belongs to the the class.
{
"x": {"type": "int", kind: "field", index: 0}
"MyClass": {kind: "class"}
"someFunction": {kind: "function"}
"someMethod": {kind: "method"}
}
I think maybe I'll keep trying to move forward/generate VM code and then add whatever is needed to the symbol table as I go.
|