MontiCore Symbol tables are stored as JSON artifacts. JSON symbol tables are not very concise, easy to read or write. As such, JSON symbol tables are best generated based on a model by a language tool.
SymTabDefinition is a small, non-conservative CD4Code variant for the modelling of symbol tables. Its models a concise, easily read- and writeable representation of symbol tables. The Current version focuses on types, functions, and variables. As its sole purpose is to describe symbol tables, elements that are not represented in the symbol table are not part of the language, e.g., initial values of variables/fields.
package de.monticore.math;
symtabdefinition Calc {
double pi;
int abs(int i);
class Vec2<T> {
+ T v1;
+ T v2;
+ (T, T) asTuple();
+ <U> Vec2<U> map(T -> U mapping);
}
}
The example:
- defines a variable symbol
piof typedouble. - defines a function symbol
absof typeint -> int;- the parameter has name
i.
- the parameter has name
- defines a (generic) CDType symbol
Vec2; In the spanned scope of the symbol are- a type-variable symbol
T. - two public field symbols
v1,v1, each of typeT. - a public method symbol
asTupleof type() -> (T, T). - a public generic method symbol
mapof type(T -> U) -> Vec2<U>;- the function parameter has the name
mapping; - the type parameter has the name
U;
- the function parameter has the name
- a type-variable symbol
CD4Code has model elements that are not part of the SymTabDefinition Language
- initial values for fields (and variables) are not stored in the symbol table, and as such are not part of the language.
- Associations are not part of the SymTabDefinition language.
SymTabDefinition has model elements that are not part of CD4Code
- top level variables/functions
- Function types, e.g.,
int -> int - Union, intersection, and tuple types, e.g.,
Student | Teacher,Car & Ship,(int, int)