CodeGeneration[LanguageDefinition]
Add
add language definition
Get
get language definition
Calling Sequence
Parameters
Description
Examples
CodeGeneration[LanguageDefinition][Add](langname, moddef)
CodeGeneration[LanguageDefinition][Get](langname)
langname
-
string; name of target language
moddef
procedure or module definition; defines a target language
The Add function adds definition of the language langname to CodeGeneration's table of recognized languages. This language is then available for use by Translate and Get.
The Get function retrieves the definition of langname. Note that Get will return a module definition for any defined language, regardless of whether the language has been defined using Define or Add.
The module definition moddef must satisfy certain criteria: see LanguageModule.
Define a language "AddExample" that translates the sin function as "Sine". Add it to CodeGeneration with Add, and perform a translation.
with⁡CodeGeneration:
langdef := proc() module() export PrintTarget, Printer; PrintTarget := proc() Printer:-PrintTarget(args); end proc: Printer := eval(LanguageDefinition[Get]("default")):-Printer; Printer:-AddFunction("sin", [anything]::anything, "Sine"); Printer:-AddOperator(Names:-Assignment = ":="); end module: end proc:
LanguageDefinitionAdd⁡AddExample,langdef
Translate⁡sin⁡x,language=AddExample
cg := (double) Sine(x);
See Also
Define
Language Definition Overview
LanguageDefinition
LanguageModule
Download Help Document