![]() |
NEURON
|
NMODL Abstract Language Definition ##############################. More...
NMODL Abstract Language Definition ##############################.
Lot of information about language constructs is necessary at various stages like AST definitions, visitors implementation, source-to-source transformations etc. In case of small changes in grammar or AST definition, especially during development stage, we have to re-write considerable part of the code. The idea of "abstract" language definition is to define framework that can automatically generate part of this "mechanical" code. This approach has been used in some open source projects (e.g. compiler design courses, TableGen format in LLVM).
During first prototyping phase we defined simple text rules inspired by compiler course assignment available at jazariethach/project6_CS160.git (no longer available on github).
The basic format of the every construct specification was:
BaseType:ChildType => MemberType<member_name>
Here "ChildType" is a new AST class that we are defining. "ParentType" is the base class, "MemberType" is the type of member variable with variable name "member_name". The name is specified in the angle braces "< >". This will generate C++ class definition like :
class ChildType : public BaseType { private: MemberType member_name; };
This specification format was sufficient for first AST design but as we started implementing more features and compiler passes, we need to add more information to language definition. For example, we need to make certain members vector, some are optional, some need specific method (getter/setter) etc. In the future we may need to make certain members private. Above text definition is limiting if we have to accomodate future enhancements.
To overcome above limitation, we are moving to YAML definition format. This allows easy extension to language construct. For example, new properties could be easily added to exisiting specification.
Old text specification has been converted to YAML format. The old documentation has information about how/why specific types were choosen for AST. You can find that documentation in the older commits of this file (e.g. a0a20e277ccf26752af4f648c245b4e06a44af20).
Text based specification described above is very limiting in terms adding extra properties. YAML based specification allows easy addition of new properties. Below are some comments about the properties and specification :
TODO : Add detailed information about YAML specification by porting old text based rule specification
Specification of NMODL in YAML format