Cela fait plusieurs jours que je cherche un programme de ce genre :

J'aimerais savoir si vous sauriez comment reproduire ce genre sur Ti Nspire CX CAS, merci

Cordialement,
-- Algobox to TI-Nspire Basic converter
-- Adrien "Adriweb" Bertrand
-- v0.2 alpha
-- July 7th, 2014
platform.apilevel = '2.0'
function string:trim()
return self:gsub("^%s*(.-)%s*$", "%1")
end
function deleteNumbersAtBeginning(str)
return str:gsub('^%d*(%s*.+)$', function(x) return x end)
end
local __VAL = "%w+%[*%w*%]*" -- regexp for a value.
function replaceThings(str)
str = str:gsub('^%s*(VARIABLES)%s*$', "")--"© %1")
str = str:gsub('^(%s*)(%w+) EST_DU_TYPE (.+)%s*$', "%1Local %2")-- © %3")
str = str:gsub('^%s*(DEBUT_ALGORITHME)%s*$', "")--"© %1")
str = str:gsub('^%s*DEBUT_.*$', '')
str = str:gsub('!=', '≠')
str = str:gsub('==', '=')
str = str:gsub('('..__VAL..')%%('..__VAL..')', 'mod(%1, %2)')
str = str:gsub('random%(%)', 'rand%(%)')
str = str:gsub('^(%s*)('..__VAL..') PREND_LA_VALEUR (.+)%s*$', "%1%2:=%3")
str = str:gsub('^(%s*)POUR (.-) ALLANT_DE (.-) A (.-)%s*$', "%1For %2,%3,%4")
str = str:gsub('^(%s*)TANT_QUE (.-) FAIRE%s*$', "%1While %2")
str = str:gsub('^(%s*)SINON%s*$', "__SINON__")
str = str:gsub('^(%s*)SI (.-) ALORS%s*$', "%1If %2 Then")
str = str:gsub('^(%s*)AFFICHER (.+)%s*$', "%1Disp %2")
str = str:gsub('^(%s*)LIRE (%w+)%s*$', "%1Request \"%2= %?\", %2")
str = str:gsub('^(%s*)(TRACER_.+)%s*$', '') -- "%1© %2") -- to handle later.
str = str:gsub('^(%s*)FIN_POUR', '%1EndFor')
str = str:gsub('^(%s*)FIN_SINON', '%1EndIf')
str = str:gsub('^(%s*)FIN_SI', '%1EndIf')
str = str:gsub('^(%s*)FIN_TANT_QUE', '%1EndWhile')
str = str:gsub('^%s*(FIN_ALGORITHME)%s*$', "")--"© %1")
-- todo : handle powers like "1e-8" => "1−8" ( <= there is a charactere between, no space)
return str
end
function secondPass(code)
code = code:gsub(":(%s*)EndIf\n:__SINON__", "%1 : Else")
return code
end
code = [[1 VARIABLES
2 x EST_DU_TYPE NOMBRE
3 y EST_DU_TYPE NOMBRE
4 a EST_DU_TYPE NOMBRE
5 DEBUT_ALGORITHME
6 LIRE a
7 x PREND_LA_VALEUR 1
8 y PREND_LA_VALEUR a
9 TANT_QUE (abs(y-x)>1.−8) FAIRE
10 DEBUT_TANT_QUE
11 x PREND_LA_VALEUR (x+y)/2
12 y PREND_LA_VALEUR a/x
13 SI (x<y) ALORS
14 DEBUT_SI
15 AFFICHER approx(x), " < approx(racine) < ", approx(y)
18 FIN_SI
19 SINON
20 DEBUT_SINON
21 AFFICHER approx(y), " < approx(racine) < ", approx(x)
24 FIN_SINON
25 FIN_TANT_QUE
26 FIN_ALGORITHME]]
lineBreak = [[
]]
progLines = ":"
function convert(code)
newCodeTbl = {}
for line in code:gmatch("[^\r\n]+") do
--ligneNew = deleteWhiteSpacesAtBeginning(line)
ligneNew = deleteNumbersAtBeginning(line)
ligneNew = replaceThings(ligneNew)
newCodeTbl[#newCodeTbl+1] = ligneNew
end
progLines = ""
for i,ligne in ipairs(newCodeTbl) do
if #ligne > 0 then
progLines = progLines .. ":" .. ligne .. lineBreak
end
end
progLines = secondPass(progLines)
progStr = [[Define algo()=
Prgm
]] .. progLines .. [[
:EndPrgm]]
destED:setText(progLines)
end
function on.enterKey()
code = sourceED:getText()
convert(code)
_res, _err = math.evalStr("DelVar algo:"..progStr)
if not _res then
print("Problem while saving (" .. (_err==910 and "syntax error" or ("errCode: " .. _err)) .. ")" )
else
print("Program saved successfully !")
end
end
function on.construction()
toolpalette.enableCopy(true)
toolpalette.enableCut(true)
toolpalette.enablePaste(true)
sourceED = D2Editor.newRichText():setBorder(1):setText(code):setReadOnly(false):setBorder(1)
sourceED:registerFilter({escapeKey = on.enterKey})
destED = D2Editor.newRichText():setBorder(1):setText(progLines):setReadOnly(true):setBorder(1)
convert(code)
end
function on.resize(w,h)
sourceED:move(1,1)
sourceED:resize(w/2-2,h-30-2)
destED:move(w/2+1,1)
destED:resize(w/2-2,h-30-2)
W,H = w,h
end
function on.paint(gc)
gc:drawString("Press [enter] to export the program",W/2-105,H-26,"top")
end
function myErrorHandler(line, errMsg, callStack, locals)
print("Error handled ! ", errMsg)
return true -- let the script continue
end
platform.registerErrorHandler(myErrorHandler)
Return to Problèmes divers / Aide débutants
Users browsing this forum: ClaudeBot [spider] and 38 guests