Skip to main content

Examples of Typecheckers

rascal-0.40.16
typepal-0.14.8

Synopsis

Examples of type checkers built with TypePal.

Description

TypePal is used in a new type checker for the Rascal meta-programming language and also in type checkers for over a dozen domain-specific languages created by http://swat.engineering in the domains finance, forensics and privacy.

To get you started more quickly, we give below a list of complete TypePal-based type checkers ranging from very simple (intended only to illustrate specific TypePal features) to type checkers for FeatherweightJava and the complete Pascal programming language. For each example we give a description, the most distinctive TypePal features that are used, and its source at GitHub. Each example has the same structure:

  • Syntax.rsc the syntax of the example language.
  • Checker.rsc the type checker for the language.
  • Test.rsc functions to call the type checker and test framework.
  • tests.ttl test cases for the type checker.
  • examples (optionally) a directory with example.
Calc
WhatThe pocket calculator language Calc; we already covered it A simple pocket calculator language
Illustratesfact, define, use, requireEqual, calculate, getType, report
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/calc
Pico
WhatToy language with declared variables in single scope, assignment, if and while statement
Illustratesfact, define, use, enterScope, leaveScope, requireEqual, calculate, getType, report
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/pico
QL
WhatA questionnaire language, for describing forms with text entry fields and computed values
Illustratesfact, define, use, requireEqual, requireTrue, calculate, getType, report
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/ql
Fun
WhatFunctional language with explicit types, function declarations and calls, let and if expressions
Illustratesfact, define, use, enterScope, leaveScope, requireEqual, calculate, getType, report
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/fun
ModFun
WhatExtension of Fun with modules
IllustratesPathRole, addPathToDef
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/modfun
Struct
WhatSimple named records
IllustratesuseViaType, TypePalConfig, getTypeNamesAndRole
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/struct
Aliases
WhatStruct, extended with type aliases
IllustratesuseViaType, TypePalConfig, getTypeNamesAndRole
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/aliases
StaticFields
WhatStruct, extended with fields on non-record type
IllustratesuseViaType, TypePalConfig, getTypeNamesAndRole, getTypeInNamelessType
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/staticFields
StructParameters
WhatStruct, with parameterized records
IllustratesuseViaType, TypePalConfig, getTypeNamesAndRole, getTypeInNamelessType, instantiateTypeParameters
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/structParameters
SmallOO
WhatSmall OO language without inheritance
IllustratesuseViaType, TypePalConfig, getTypeNamesAndRole
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/smallOO
FWJava
WhatFeatherWeight Java, a minimal, Java-like, language with inheritance and constructors
IllustratesuseViaType, addPathToDef, isSubType, TypePalConfig, getTypeNamesAndRole, mayOverload, preSolver, setScopeInfo, getScopeInfo
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/fwjava
Pascal
WhatThe Pascal language (Second Edition, 1978)
IllustratesuseViaType, addPathToType, PathRole, isSubType, TypePalConfig, preCollectInitialization getTypeNamesAndRole
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/pascal
UntypedFun
WhatFunctional language with implicit (inferred) types, function declarations and calls, let and if expressions
Illustratesfact, define, use, enterScope, leaveScope, requireEqual, calculate, getType, report, newTypeVar, calculateEager, requireUnify, unify
Sourcehttps://github.com/cwi-swat/typepal/tree/master/src/examples/untypedFun