Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
CodeGeneration[LanguageDefinition][Define] - define a target language module
Calling Sequence
CodeGeneration[LanguageDefinition][Define](lang, extend=ext_lang, f1, f2,...)
Parameters
lang
-
string; name of target language
ext_lang
(optional) string; name of language to extend
f1, f2, ...
function calls with the function name being one of AddFunction, AddFunctions, AddOperator, AddPrintHandler, AddType, or SetLanguageAttribute
Description
The Define function defines a language for use with CodeGeneration.
f1, f2, ... can be any number of function calls, with the function's name (zeroth operand) being one of AddFunction, AddFunctions, AddOperator, AddPrintHandler, AddType, SetLanguageAttribute. These function calls accept exactly the same syntax as the Printer functions of the same name.
When ext_lang is provided, the resulting language definition module is identical to the module for language ext_lang, except where the function calls f1, f2, ... override the data of ext_lang. This provides a convenient mechanism for altering a language in simple ways and testing the result.
Note: In the user-defined procedures added through the function calls f1, f2, ... , it is often necessary to refer to exports of a Printer module, such as Indent, Print, or GetPrecedence. For correct behavior, every occurrence of these Printer exports within user-defined procedures must be explicitly declared as Printer exports by prefixing them with 'Printer:-', for example, Printer:-Indent, Printer:-Print. Otherwise, these references will not be properly handled by Define.
Examples
Define a custom language DefineExample, using the pre-defined ANSI C as a base, which uses tab characters for indentation and := for assignment. Translate a simple expression to the language DefineExample.
LanguageDefinition[Define]("DefineExample", extend = "C", SetLanguageAttribute( "Indent_Char" = " ", # use tab character for indentation "Indent_Base" = 1, "Indent_Increment" = 1 ), AddOperator( Names:-Assignment = ":=" ), AddPrintHandler( Names:-Integer = proc(x) Printer:-Print( convert(x, 'string') ) end proc ) );
cg := sin(x);
See Also
Add, Language Definition Overview, LanguageDefinition, LanguageModule, Printer
Download Help Document
Copyright © MathResources Inc. All Rights Reserved.
www.mathresources.com