The ZOTI-FTN LanguageΒΆ

The ZOTI-FTN language consists in a small syntax used for describing data types. ZOTI-FTN files represent modules and can have the following structure:

  ftn        =  import* moddef
  import     =  "import" id ("as" id)? ";"
  moddef     =  moddecl modspec ";"
  moddecl    =  id ":" "module"
  modspec    =  "{" binding* "}"

A module consists in multiple bindings from names to type specifications, as specified in the following parser rules:

  typespec   =  (aggrspec / simplespec)
  aggrspec   =  aggrkind "{" binding* "}"
  aggrkind   =  "structure"
  binding    =  id ":" typespec ";"
  simplespec =  (arrspec / atomspec / intspec / boolspec / voidspec / typeref / attrref)
  arrspec    =  "array" attrspec typespec
  atomspec   =  "atom"
  intspec    =  "integer" attrspec
  boolspec   =  "boolean" attrspec?
  voidspec   =  "void"
  typeref    =  id "." id attrspec?
  attrref    = "constant" attrspec
  attrspec   =  "(" (attrs / attrval / constref)? ")"
  attrs      =  attr (";" attr)*
  attr       =  id ":" attrval
  attrval    =  id / rangeval / intliteral
  constref   =  id
  id         =  r'[A-Za-z_][A-Za-z0-9_-]*'
  rangeval   =  intliteral ".." intliteral
  intliteral =  "-"? radix_pfx? r'[0-9A-Za-f]+'
  radix_pfx  =  r'0[xXoObB]'

The attributes (attrs) differ for different types, and the allowed enties are documented in the AST schemas (e.g., for the target-agnostic AST or the C-specific AST). The allowed keywords are:

ATTR_IMPORTS = "imports"
ATTR_IMPORTS_MODULE = "module"
ATTR_IMPORTS_AS = "as"
ATTR_IMPORTS_PATH = "from"
ATTR_MODULES = "modules"
ATTR_TYPE = "type"
ATTR_FIELDS = "fields"
ATTR_ENTRIES = "entries"
ATTR_CONTEXT = "context"
ATTR_ELEMENT_TYPE = "element-type"
ATTR_TYPE = "type"
ATTR_REF = "ref"
ATTR_RANGE = "range"
ATTR_ENDIAN = "endian"
ATTR_BIT_SIZE = "bit-size"
ATTR_LEN_FIELD = "length-field"
ATTR_INFO = "_info"

TYPE_INTEGER = "integer"
TYPE_BOOLEAN = "boolean"
TYPE_VOID = "void"
TYPE_ATOM = "atom"
TYPE_ARRAY = "array"
TYPE_STRUCTURE = "structure"
TYPE_REF = "ref"
TYPE_CONSTANT = "constant"
TYPE_MODULE = "module"

To parse an input file into its AST one can use the CLI tool associated with this package, e.g.

python3 -m zoti_ftn -h