Language Definition Module
Description
Language Module Exports
Additional Notes
Examples
A language definition module is a repository of information necessary for translating intermediate code to a specific target language.
A language definition module is a Maple module with the exports PrintTarget, and Printer. These exports must satisfy certain criteria:
Printer - a valid Printer module.
PrintTarget - a procedure that returns a string, the translated output. In most cases, PrintTarget simply calls Printer:-PrintTarget.
For Add to work correctly, you must use single-quotes to delay the evaluation of your language module before adding it with Add. In other words, your module must be of the form 'module() ... end module', and must evaluate to a module definition, not a module. For more information on module definitions, see type,moduledefinition.
The body of the module definition must contain a sequence of calls to Printer commands that define language-specific data, as well as any utility procedures.
Once defined, the module definition must be added to CodeGeneration using the Add command.
with⁡CodeGeneration:
m := 'module() export PrintTarget, Printer; PrintTarget := proc() Printer:-PrintTarget(args); end proc: Printer := eval(LanguageDefinition[Get]("default")):-Printer; Printer:-AddFunction("sin", [numeric]::numeric, "sine"); Printer:-AddOperator(Names:-Assignment = "="); end module':
LanguageDefinitionAdd⁡LanguageModuleExample,m
Translate⁡sin⁡x,resultname=t0,language=LanguageModuleExample
t0 = sine(x);
See Also
Add
Define
Get
Printer
Download Help Document