>
|
LanguageDefinition:-Define("MyLanguage", extend="default",
SetLanguageAttribute(
"Procedure_Start" = proc(rettype,pname,params)
(Printer:-Indent(),"func ",pname," ",params," : ",rettype,";\n")
end proc,
"Procedure_End" = proc() (Printer:-Indent(),"end func\n") end proc,
"Procedure_ParametersInBody" = false,
"ParameterSequence_Start" = "(",
"ParameterSequence_End" = ")",
"ParameterSequence_Delimiter" = ",",
"ParameterSequence_MaxOnLine" = 3,
"Statement_End" = ";",
"Block_Start" = proc() Printer:-Indent(),"begin\n" end proc,
"Block_End" = proc() Printer:-Indent(),"end\n" end proc
),
AddType(
'integer' = table(['single' = "integer", 'double'="long"]),
'numeric' = table(['single' = "real", 'double'="real"])
),
AddFunction( "sqrt", [numeric]::numeric,
x->Printer:-Print("surd(",x,",2)")
),
AddOperator( Names:-Assignment = ":=" ),
AddPrintHandler( Names:-Return = proc(x) Printer:-Print("return ",x) end proc)
):
Translate( sqrt(x), language="MyLanguage" );
|