Language Module - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Language Definition Module

 

Description

Language Module Exports

Additional Notes

Examples

Description

  

A language definition module is a repository of information necessary for translating intermediate code to a specific target language.

Language Module Exports

  

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.

Additional Notes

• 

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.

Examples

withCodeGeneration:

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':

LanguageDefinitionAddLanguageModuleExample,m

Translatesinx,resultname=t0,language=LanguageModuleExample

t0 = sine(x);

See Also

Add

Define

Get

Printer