Defining primitive types for custom language, with metadata?

I'd like to create a list of primitive types that users of my language have access to.   I can't use enum (or I don't want to), because I want to have some additional metadata available for use/analysis.

For example, I have 3 "kinds" of primitives, "signed integral" "unsigned integral" and "floating point"

For the integral kinds, it can have sizes of 8, 16, 32,  For the floating point kinds, it can have 32 and 64

I'd like to have the names be determined automatically (uint8, float32, etc...)

I have a "Type" concept, and a TypeReference concept.  I'll have other Types (user-defined types, and some library types).

 

I'm not quite sure how to create this.  I'd like the language user to easily type the primitive name to get a reference to that type.

 

2 comments

Well, basically you can define your own "primitive types" language using just MPS language concepts, especially if you want to give the types some meta data.

You might want to look at the PrimitveType concept and how MPS implements their primitve types: http://127.0.0.1:63320/node?ref=r%3A00000000-0000-4000-0000-011c895902ca%28jetbrains.mps.baseLanguage.structure%29%2F1164118113764&project=com.siemens.ct.scanner

Having predefined value ranges with types is something I think KernelF allows you to define. See section 2.1 for a first reference: http://voelter.de/data/pub/kernelf-reference.pdf

0

Yeah, I was thinking of going that route.  Though I realized in my system I was thinking about types a bit backward, so I figured out I can use a substitution menu on a PrimitiveType concept to create all the instances I care about.  I can do this based on metadata from another module. For now, I'm just doing it from an enum I created in the runtime solution, but I will probably change that when I get a better sense of what metadata I'm going to actually need.

0

Please sign in to leave a comment.