1424 lines
35 KiB
JavaScript
1424 lines
35 KiB
JavaScript
var code = new Array();
|
||
var indices = new Array();
|
||
var erreur_syntaxe = new Array(), nb_erreurs;
|
||
var previsions = new Array();
|
||
var type, indice_previsions;
|
||
var j, k, for_ti, n;
|
||
var conditions_ouvertes, conditions_fermees, alors, boucles_ouvertes, boucles_fermees, pour_ouverts, pour_fermes, ti_ouverts, ti_fermes;
|
||
var bug1, bug2, bug3, bug4, bug5;
|
||
|
||
function saut_de_ligne(texte) {
|
||
while(texte.indexOf("<hr>") != -1)
|
||
texte = texte.replace("<hr>","@");
|
||
|
||
while(texte.indexOf(" ") != -1)
|
||
texte = texte.replace(" ","");
|
||
|
||
/*while(texte.indexOf("<span class=\"Apple-tab-span\" style=\"white-space:pre\"> </span>") != -1)
|
||
texte = texte.replace("<span class=\"Apple-tab-span\" style=\"white-space:pre\"> </span>","");
|
||
|
||
while(texte.indexOf("<span style=\"font-size: 10pt;\">") != -1)
|
||
texte = texte.replace("<span style=\"font-size: 10pt;\">","");
|
||
|
||
while(texte.indexOf("<font face=\"Arial, Verdana\" size=\"2\">") != -1)
|
||
texte = texte.replace("<font face=\"Arial, Verdana\" size=\"2\">","");
|
||
|
||
while(texte.indexOf("<span style=\"font-family: 'Times New Roman'; font-size: medium;\">") != -1)
|
||
texte = texte.replace("<span style=\"font-family: 'Times New Roman'; font-size: medium;\">","");
|
||
|
||
while(texte.indexOf("</font>") != -1)
|
||
texte = texte.replace("</font>","");
|
||
|
||
while(texte.indexOf("</span>") != -1)
|
||
texte = texte.replace("</span>","");*/
|
||
|
||
var balises = [
|
||
"<font", "</font",
|
||
"<p", "</p",
|
||
"<a", "</a",
|
||
"<i", "</i",
|
||
"<u", "</u"
|
||
];
|
||
|
||
for(var k = 0; k < 10; k++)
|
||
{
|
||
while(texte.indexOf(balises[k]) != -1)
|
||
{
|
||
var start, end;
|
||
start = texte.indexOf(balises[k], 0);
|
||
end = texte.indexOf(">", start);
|
||
|
||
if(start != -1 && end != -1)
|
||
texte = texte.substring(0, start) + texte.substring(end + 1, texte.length);
|
||
}
|
||
}
|
||
|
||
do
|
||
{
|
||
var pos = texte.indexOf('<span style="background-color:yellow;">');
|
||
|
||
if(pos != -1)
|
||
{
|
||
var pos2 = texte.indexOf("</span>", pos);
|
||
texte = texte.substring(0, pos2) + texte.substring(pos2 + 7, texte.length);
|
||
|
||
texte = texte.replace('<span style="background-color:yellow;">',"");
|
||
}
|
||
}
|
||
while(pos != -1);
|
||
|
||
while(texte.indexOf(" ") != -1)
|
||
texte = texte.replace(" "," ");
|
||
|
||
while(texte.indexOf("<div") != -1)
|
||
{
|
||
if(texte.indexOf("<div>") == 0)
|
||
texte = texte.replace("<div>", "");
|
||
else
|
||
{
|
||
while(texte.indexOf("<div") != -1)
|
||
{
|
||
var start, end;
|
||
start = texte.indexOf("<div", 0);
|
||
end = texte.indexOf(">", start);
|
||
|
||
if(start != -1 && end != -1)
|
||
texte = texte.substring(0, start) + "@" + texte.substring(end + 1, texte.length);
|
||
}
|
||
}
|
||
}
|
||
while(texte.indexOf("</div>") != -1)
|
||
texte = texte.replace("</div>","");
|
||
|
||
while(texte.indexOf("<span") != -1)
|
||
{
|
||
if(texte.indexOf("<span>") == 0)
|
||
texte = texte.replace("<span>", "");
|
||
else
|
||
{
|
||
while(texte.indexOf("<span") != -1)
|
||
{
|
||
var start, end;
|
||
start = texte.indexOf("<span", 0);
|
||
end = texte.indexOf(">", start);
|
||
|
||
if(start != -1 && end != -1)
|
||
texte = texte.substring(0, start) + "@" + texte.substring(end + 1, texte.length);
|
||
}
|
||
}
|
||
}
|
||
while(texte.indexOf("</span>") != -1)
|
||
texte = texte.replace("</span>","");
|
||
|
||
while(texte.indexOf("<br") != -1)
|
||
{
|
||
var start, end;
|
||
start = texte.indexOf("<br", 0);
|
||
end = texte.indexOf(">", start);
|
||
|
||
if(start != -1 && end != -1)
|
||
texte = texte.substring(0, start) + "@" + texte.substring(end + 1, texte.length);
|
||
}
|
||
|
||
while(texte.substring(texte.length - 1, texte.length) == " " || texte.substring(texte.length - 1, texte.length) == "@")
|
||
texte = texte.substring(0, texte.length - 1);
|
||
|
||
return texte;
|
||
}
|
||
|
||
function caracteres_speciaux(texte, sens) { // sens = 0 : § → §
|
||
var i; // sens = 1 : § → §
|
||
var car = [
|
||
" ", "",
|
||
"­", "",
|
||
"‎", "",
|
||
"‏", "",
|
||
"»", "«",
|
||
"‹", "‹",
|
||
"›", "›",
|
||
"“", "“",
|
||
"”", "”",
|
||
"„", "„",
|
||
"'", "'",
|
||
"‘", "‘",
|
||
"’", "’",
|
||
"‚", "‚",
|
||
"…", "…",
|
||
"¡", "¡",
|
||
"¿", "¿",
|
||
"¨", "¨",
|
||
"´", "´",
|
||
"ˆ", "ˆ",
|
||
"¸", "¸",
|
||
"§", "§",
|
||
"©", "©",
|
||
"®", "®",
|
||
"™", "™",
|
||
"&", "&",
|
||
"←", "←",
|
||
"↑", "↑",
|
||
"→", "→",
|
||
"↓", "↓",
|
||
"↔", "↔",
|
||
"á", "á",
|
||
"Á", "Á",
|
||
"â", "â",
|
||
"Â", "Â",
|
||
"à", "à",
|
||
"À", "À",
|
||
"ã", "ã",
|
||
"ä", "ä",
|
||
"æ", "æ",
|
||
"ç", "ç",
|
||
"Ç", "Ç",
|
||
"é", "é",
|
||
"É", "É",
|
||
"ê", "ê",
|
||
"Ê", "Ê",
|
||
"È", "È",
|
||
"ë", "ë",
|
||
"Ë", "Ë",
|
||
"î", "î",
|
||
"Î", "Î",
|
||
"ï", "ï",
|
||
"Ï", "Ï",
|
||
"ñ", "ñ",
|
||
"Ñ", "Ñ",
|
||
"ô", "ô",
|
||
"Ô", "Ô",
|
||
"ø", "ø",
|
||
"Ø", "Ø",
|
||
"ö", "ö",
|
||
"Ö", "Ö",
|
||
"œ", "œ",
|
||
"ß", "ß",
|
||
"ð", "ð",
|
||
"ú", "ú",
|
||
"Ú", "Ú",
|
||
"û", "û",
|
||
"ù", "ù",
|
||
"ü", "ü",
|
||
"Ü", "Ü",
|
||
"¤", "¤",
|
||
"€", "€",
|
||
"¢", "¢",
|
||
"£", "£",
|
||
"¥", "¥",
|
||
"ƒ", "ƒ",
|
||
"α", "α",
|
||
"Α", "Α",
|
||
"β", "β",
|
||
"Β", "Β",
|
||
"γ", "γ",
|
||
"Γ", "Γ",
|
||
"δ", "δ",
|
||
"Δ", "Δ",
|
||
"ε", "ε",
|
||
"Ε", "Ε",
|
||
"ζ", "ζ",
|
||
"Ζ", "Ζ",
|
||
"η", "η",
|
||
"Η", "Η",
|
||
"θ", "θ",
|
||
"Θ", "Θ",
|
||
"ι", "ι",
|
||
"Ι", "Ι",
|
||
"κ", "κ",
|
||
"Κ", "Κ",
|
||
"λ", "λ",
|
||
"Λ", "Λ",
|
||
"μ", "μ",
|
||
"Μ", "Μ",
|
||
"ν", "ν",
|
||
"Ν", "Ν",
|
||
"ξ", "ξ",
|
||
"Ξ", "Ξ",
|
||
"ο", "ο",
|
||
"Ο", "Ο",
|
||
"π", "π",
|
||
"Π", "Π",
|
||
"ρ", "ρ",
|
||
"Ρ", "Ρ",
|
||
"σ", "σ",
|
||
"ς", "ς",
|
||
"Σ", "Σ",
|
||
"τ", "τ",
|
||
"Τ", "Τ",
|
||
"υ", "υ",
|
||
"Υ", "Υ",
|
||
"φ", "φ",
|
||
"Φ", "Φ",
|
||
"χ", "χ",
|
||
"Χ", "Χ",
|
||
"ψ", "ψ",
|
||
"Ψ", "Ψ",
|
||
"ω", "ω",
|
||
"Ω", "Ω",
|
||
"°", "°",
|
||
"µ", "µ",
|
||
"<", "<",
|
||
">", ">",
|
||
"≤", "≤",
|
||
"≥", "≥",
|
||
"≈", "≈",
|
||
"≠", "≠",
|
||
"≡", "≡",
|
||
"±", "±",
|
||
"−", "−",
|
||
"×", "×",
|
||
"÷", "÷",
|
||
"⁄", "⁄",
|
||
"‰", "‰",
|
||
"¼", "¼",
|
||
"½", "½",
|
||
"¾", "¾",
|
||
"¹", "¹",
|
||
"²", "²",
|
||
"³", "³",
|
||
"º", "º",
|
||
"ª", "ª",
|
||
"ƒ", "ƒ",
|
||
"′", "′",
|
||
"″", "″",
|
||
"∂", "∂",
|
||
"∏", "∏",
|
||
"∑", "∑",
|
||
"√", "√",
|
||
"∞", "∞",
|
||
"¬", "¬",
|
||
"∩", "∩",
|
||
"∫", "∫"
|
||
]
|
||
|
||
for(i = 0; i < 159 * 2; i += 2)
|
||
{
|
||
while(texte.indexOf(car[i + sens]) != -1)
|
||
texte = texte.replace(car[i + sens], car[i + 1 - sens]);
|
||
}
|
||
|
||
return texte;
|
||
}
|
||
|
||
function assouplie_syntaxe(texte, langage_source) {
|
||
while(texte.indexOf("Hasard()") != -1)
|
||
texte = texte.replace("Hasard()", "Hasard(1)");
|
||
while(texte.indexOf("hasard()") != -1)
|
||
texte = texte.replace("hasard()", "hasard(1)");
|
||
while(texte.indexOf("Hasard ()") != -1)
|
||
texte = texte.replace("Hasard ()", "Hasard(1)");
|
||
while(texte.indexOf("hasard ()") != -1)
|
||
texte = texte.replace("hasard ()", "hasard(1)");
|
||
|
||
return texte;
|
||
}
|
||
|
||
function compilation(langage_source) {
|
||
var texte = document.getElementById('saisie').value;
|
||
var i, mot = "", dernier_mot = 0, espace_position , mot_en_cours;
|
||
var ligne = 1, type;
|
||
var calcul_memoire = "undefined", ligne_memoire, chaine = 0;
|
||
var texte_compil = escape(texte);
|
||
createCookie("last_algo",texte_compil,30);
|
||
createCookie("last_language",langage_source,30);
|
||
createCookie('exemple','init',30);
|
||
debug_efface();
|
||
|
||
// remise à 0 des variables
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
nb_erreurs = 0;
|
||
conditions_ouvertes = 0;
|
||
conditions_fermees = 0;
|
||
alors = 0;
|
||
boucles_ouvertes = 0;
|
||
boucles_fermees = 0;
|
||
pour_ouverts = 0;
|
||
pour_fermes = 0;
|
||
ti_ouverts = 0;
|
||
ti_fermes = 0;
|
||
for_ti = 0;
|
||
j = 0;
|
||
k = 0;
|
||
next = 0;
|
||
|
||
while(escape(texte).indexOf("%0A") != -1)
|
||
texte = unescape(escape(texte).replace("%0A",""));
|
||
|
||
// modifie le texte pour lire les retours à la ligne (@)
|
||
texte = saut_de_ligne(texte);
|
||
|
||
// remplace les entités html par les caractères spéciaux correspondants
|
||
texte = caracteres_speciaux(texte, 0);
|
||
|
||
texte = assouplie_syntaxe(texte, langage_source);
|
||
|
||
// détection des chaines de caractères
|
||
for(i = 0; i < texte.length; i++)
|
||
{
|
||
mot_en_cours = texte.substring(dernier_mot, i + 1);
|
||
|
||
if(chaine == 1 && texte.substring(i, i + 1) == "\"")
|
||
{
|
||
chaine = 0;
|
||
identification(mot_en_cours, ligne, "chaine", langage_source);
|
||
mot_en_cours = "";
|
||
dernier_mot = i + 1;
|
||
|
||
if(dernier_mot == texte.length)
|
||
break;
|
||
}
|
||
|
||
if(dernier_mot == i && mot_en_cours.substring(0, 1) == "\"")
|
||
{
|
||
chaine = 1;
|
||
if(calcul_memoire != "undefined")
|
||
{
|
||
identification(calcul_memoire, ligne_memoire, "calcul", langage_source);
|
||
calcul_memoire = "undefined";
|
||
}
|
||
}
|
||
|
||
// détection des instruction (attention : piège si/sinon, if/ifend...)
|
||
type = detecte_instruction(mot_en_cours, langage_source);
|
||
if((type == "si" && texte.toLowerCase().substring(dernier_mot, i + 4) == "sinon") || (type == "if" && texte.toLowerCase().substring(dernier_mot, i + 4) == "ifend") || (type == "while" && texte.toLowerCase().substring(dernier_mot, i + 4) == "whileend"))
|
||
type = "undefined";
|
||
|
||
if(type == "undefined")
|
||
{
|
||
// détection des signes (>, <, =, ...)
|
||
type = detecte_signe(mot_en_cours);
|
||
|
||
if(type == "signe" && detecte_signe(texte.substring(dernier_mot, i + 2)) == "signe")
|
||
{
|
||
i++;
|
||
mot_en_cours = texte.substring(dernier_mot, i + 1);
|
||
}
|
||
}
|
||
|
||
if(next == 1)
|
||
{
|
||
next = 0;
|
||
previsions[indice_previsions] = "PREV_END";
|
||
}
|
||
|
||
if(mot_en_cours.indexOf("@", 0) >= 0 && previsions[indice_previsions] == "condition_add")
|
||
next = 1;
|
||
|
||
// découpage en "mots" et traitement
|
||
if(((mot_en_cours.indexOf(" ", 0) >= 0 || escape(texte.substring(dernier_mot + 1, i + 2)) == "%u2220" || type != "undefined" || (detecte_signe(texte.substring(i + 1, i + 2)) == "signe" && texte.substring(i, i + 1) != "-") || (escape(texte.substring(i + 1, i + 7)) == "%u2220" && langage_source == 2 && mot_en_cours.length > 0) || (escape(texte.substring(i + 1, i + 3)) == "%u2192" && langage_source != 1)) && chaine == 0) || mot_en_cours.indexOf("@", 0) >= 0 || i + 1 == texte.length || (for_ti == 1 && mot_en_cours.length > 0 && texte.substring(dernier_mot, i + 2).indexOf(",", 0) >= 0) || mot_en_cours == ",")
|
||
{
|
||
// gère les retours à la ligne
|
||
if(mot_en_cours != "@" && mot_en_cours != " ")
|
||
{
|
||
mot = mot_en_cours;
|
||
espace_position = mot.search(" ");
|
||
|
||
if(espace_position == -1)
|
||
{
|
||
espace_position = mot.search("@");
|
||
chaine = 0;
|
||
}
|
||
|
||
if(espace_position != -1)
|
||
{
|
||
mot = mot.substring(0, espace_position);
|
||
chaine = 0;
|
||
}
|
||
|
||
// gère les calculs
|
||
if(detecte_calculs(mot, langage_source) == "calcul")
|
||
{
|
||
if(calcul_memoire != "undefined")
|
||
{
|
||
mot = calcul_memoire + mot;
|
||
}
|
||
else
|
||
ligne_memoire = ligne;
|
||
|
||
calcul_memoire = mot;
|
||
|
||
if(i + 1 == texte.length || mot_en_cours.indexOf("@", 0) >= 0 || texte.substring(i + 1, i + 2) == "@")
|
||
{
|
||
identification(calcul_memoire, ligne_memoire, "calcul", langage_source);
|
||
calcul_memoire = "undefined";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(calcul_memoire != "undefined")
|
||
{
|
||
identification(calcul_memoire, ligne_memoire, "calcul", langage_source);
|
||
calcul_memoire = "undefined";
|
||
}
|
||
identification(mot, ligne, type, langage_source);
|
||
}
|
||
}
|
||
mot = "";
|
||
dernier_mot = i + 1;
|
||
|
||
if(mot_en_cours.indexOf("@", 0) >= 0)
|
||
ligne++;
|
||
}
|
||
}
|
||
|
||
// Après la détection, on gère les erreurs si il manque des éléments attendus
|
||
if(previsions[indice_previsions] == "tout")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
}
|
||
else
|
||
{
|
||
for(n = 0; n <= indice_previsions; n++)
|
||
{
|
||
if(previsions[n] == "PREV_END")
|
||
{
|
||
previsions[indice_previsions] = "PREV_END";
|
||
break;
|
||
}
|
||
}
|
||
if(previsions[indice_previsions] != "PREV_END" && previsions[indice_previsions] != "condition_add")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs] = previsions[indice_previsions];
|
||
ameliore_syntaxe_suggestion(2);
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "manquant";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
//ameliore_syntaxe_suggestion(langage_source);
|
||
nb_erreurs++;
|
||
}
|
||
}
|
||
|
||
// on compte les éléments de conditions et de boucles
|
||
if((langage_source != 3 && conditions_ouvertes - conditions_fermees != 0) || conditions_ouvertes - alors != 0)
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "erreur_conditions";
|
||
nb_erreurs++;
|
||
}
|
||
|
||
if(langage_source != 3 && (boucles_ouvertes - boucles_fermees != 0 || pour_ouverts - pour_fermes != 0))
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "erreur_boucles";
|
||
nb_erreurs++;
|
||
}
|
||
|
||
if(langage_source == 3 && ti_ouverts - ti_fermes != 0)
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "erreur_ti";
|
||
nb_erreurs++;
|
||
}
|
||
|
||
// si il y a des erreurs, on les affiche
|
||
if(nb_erreurs > 0)
|
||
{
|
||
texte = affiche_erreurs(texte);
|
||
|
||
texte = texte.replace("@","<div>");
|
||
while(texte.indexOf("@") != -1)
|
||
texte = texte.replace("@","</div><div>");
|
||
|
||
texte += "</div>";
|
||
|
||
document.getElementById("saisie").value = texte;
|
||
$("#saisie").cleditor()[0].updateFrame().focus();
|
||
return "failed";
|
||
}
|
||
else
|
||
{
|
||
masque_erreurs();
|
||
return "completed";
|
||
}
|
||
}
|
||
|
||
function identification(mot_recu, ligne, type, langage_source) {
|
||
var mot;
|
||
mot = mot_recu.toLowerCase();
|
||
|
||
if(mot == ",")
|
||
type = ",";
|
||
|
||
// on différencie variables et calculs
|
||
if(type == "calcul")
|
||
{
|
||
type = detecte_variable(mot);
|
||
if(type != "variable")
|
||
type = "calcul";
|
||
}
|
||
|
||
// on affiche une erreur si le type reçu est différent du type attendu
|
||
if((type != previsions[indice_previsions] && previsions[indice_previsions] != "tout" && !((type == "chaine" || type == "variable" || type == "calcul") && previsions[indice_previsions] == "chaine_variable_calcul") && !((escape(type) == "%u2192" || escape(type) == "%u2220" || type == "prend_la_valeur" || type == "#ran") && previsions[indice_previsions] == "→_ou_∠") && !((type == "variable" || type == "calcul" || type == "signe" || type == "et" || type == "ou" || type == "and" || type == "or") && (previsions[indice_previsions] == "condition" || previsions[indice_previsions] == "condition_alors")) && !(previsions[indice_previsions] == "condition_alors") && !(type == "variable" && previsions[indice_previsions] == "calcul")) && !(escape(type) == "%u2192" && previsions[indice_previsions] == "→") && !(escape(type) == "%u2220" && previsions[indice_previsions] == "∠") && previsions[indice_previsions] != "PREV_END" && previsions[indice_previsions] != "condition_add")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs] = previsions[indice_previsions];
|
||
if(type == "chaine")
|
||
mot_recu = mot_recu.substring(1, mot_recu.length - 1);
|
||
erreur_syntaxe[4 * nb_erreurs + 1] = mot_recu;
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
ameliore_syntaxe_description();
|
||
ameliore_syntaxe_suggestion(langage_source);
|
||
nb_erreurs++;
|
||
}
|
||
|
||
indice_previsions++;
|
||
|
||
// gestion des conditions
|
||
if(previsions[indice_previsions - 1] == "condition" || previsions[indice_previsions - 1] == "condition_alors" || previsions[indice_previsions - 1] == "condition_add")
|
||
{
|
||
code[j] = mot;
|
||
|
||
if(previsions[indice_previsions - 1] == "condition")
|
||
previsions[0] = "condition_add";
|
||
else
|
||
previsions[0] = previsions[indice_previsions - 1];
|
||
|
||
previsions[1] = "PREV_END";
|
||
|
||
if(previsions[indice_previsions] == "alors")
|
||
previsions[1] = "alors";
|
||
if(previsions[indice_previsions] == "then")
|
||
previsions[1] = "then";
|
||
|
||
indice_previsions = 0;
|
||
}
|
||
|
||
code[j] = "rien";
|
||
|
||
// reconnaissance des fonctions "algorithme"
|
||
if(langage_source == 1)
|
||
{
|
||
switch(type)
|
||
{
|
||
case "lire":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "lire";
|
||
previsions[0] = "variable";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "afficher":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "afficher";
|
||
previsions[0] = "chaine_variable_calcul";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "si":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "si";
|
||
previsions[0] = "condition";
|
||
previsions[1] = "alors";
|
||
previsions[2] = "PREV_END";
|
||
indice_previsions = 0;
|
||
conditions_ouvertes++;
|
||
break;
|
||
|
||
case "alors":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "alors";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
alors++;
|
||
break;
|
||
|
||
case "sinon":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "sinon";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_conditions(mot_recu, ligne);
|
||
break;
|
||
|
||
case "fin_si":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_si";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_conditions(mot_recu, ligne);
|
||
conditions_fermees++;
|
||
break;
|
||
|
||
case "tant_que":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "tant_que";
|
||
previsions[0] = "condition";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
boucles_ouvertes++;
|
||
break;
|
||
|
||
case "fin_tant_que":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_tant_que";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_boucles(mot_recu, ligne, langage_source);
|
||
boucles_fermees++;
|
||
break;
|
||
|
||
case "pour":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "pour";
|
||
previsions[0] = "variable";
|
||
previsions[1] = "allant_de";
|
||
previsions[2] = "calcul";
|
||
previsions[3] = "à";
|
||
previsions[4] = "calcul";
|
||
previsions[5] = "PREV_END";
|
||
indice_previsions = 0;
|
||
pour_ouverts++;
|
||
break;
|
||
|
||
case "allant_de":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = "allant_de";
|
||
break;
|
||
|
||
case "à":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = "à";
|
||
break;
|
||
|
||
case "fin_pour":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_pour";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_pour(mot_recu, ligne, langage_source);
|
||
pour_fermes++;
|
||
break;
|
||
|
||
case "prend_la_valeur":
|
||
code[j] = "prend_la_valeur";
|
||
previsions[0] = "calcul";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "et":
|
||
code[j] = "et";
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "ou":
|
||
code[j] = "ou";
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "fin_programme":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_programme";
|
||
if(previsions[indice_previsions - 1] != "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
// reconnaissance des fonctions Casio
|
||
if(langage_source == 2)
|
||
{
|
||
switch(type)
|
||
{
|
||
case "?":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "lire";
|
||
previsions[0] = "→";
|
||
previsions[1] = "variable";
|
||
previsions[2] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "ifend":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_si";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_conditions(mot_recu, ligne);
|
||
conditions_fermees++;
|
||
break;
|
||
|
||
case "for":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "pour";
|
||
previsions[0] = "calcul";
|
||
previsions[1] = "→";
|
||
previsions[2] = "variable";
|
||
previsions[3] = "to";
|
||
previsions[4] = "calcul";
|
||
previsions[5] = "PREV_END";
|
||
indice_previsions = 0;
|
||
pour_ouverts++;
|
||
break;
|
||
|
||
case "to":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = "to";
|
||
break;
|
||
|
||
case "next":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_pour";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_pour(mot_recu, ligne, langage_source);
|
||
pour_fermes++;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// reconnaissance des fonctions TI
|
||
if(langage_source == 3)
|
||
{
|
||
switch(type)
|
||
{
|
||
case "input":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "lire";
|
||
previsions[0] = "variable";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "disp":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "afficher";
|
||
previsions[0] = "chaine_variable_calcul";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
break;
|
||
|
||
case "end":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_si_ou_boucle";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
ti_fermes++;
|
||
break;
|
||
|
||
case "for(":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "pour";
|
||
previsions[0] = "variable";
|
||
previsions[1] = ",";
|
||
previsions[2] = "calcul";
|
||
previsions[3] = ",";
|
||
previsions[4] = "calcul";
|
||
previsions[5] = "PREV_END";
|
||
indice_previsions = 0;
|
||
for_ti = 1;
|
||
ti_ouverts++;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// reconnaissance des fonctions communes à Casio et TI
|
||
if(langage_source == 2 || langage_source == 3)
|
||
{
|
||
switch(type)
|
||
{
|
||
case "if":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "si";
|
||
previsions[0] = "condition";
|
||
previsions[1] = "then";
|
||
previsions[2] = "PREV_END";
|
||
indice_previsions = 0;
|
||
conditions_ouvertes++;
|
||
ti_ouverts++;
|
||
break;
|
||
|
||
case "then":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "alors";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
alors++;
|
||
break;
|
||
|
||
case "else":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "sinon";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_conditions(mot_recu, ligne);
|
||
break;
|
||
|
||
case "while":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "tant_que";
|
||
previsions[0] = "condition";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
boucles_ouvertes++;
|
||
ti_ouverts++;
|
||
break;
|
||
|
||
case "whileend":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_tant_que";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
verifie_boucles(mot_recu, ligne, langage_source);
|
||
boucles_fermees++;
|
||
break;
|
||
|
||
case "→":
|
||
code[j] = "→";
|
||
if(previsions[indice_previsions] == "PREV_END")
|
||
{
|
||
previsions[0] = "variable";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "and":
|
||
code[j] = "et";
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "or":
|
||
code[j] = "ou";
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "stop":
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "fin_programme";
|
||
if(previsions[indice_previsions - 1] != "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
}
|
||
|
||
switch(escape(type))
|
||
{
|
||
case "%u2192":
|
||
code[j] = "→";
|
||
|
||
if(previsions[indice_previsions] == "PREV_END")
|
||
{
|
||
previsions[0] = "variable";
|
||
previsions[1] = "PREV_END";
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
|
||
case "%u2220":
|
||
if(langage_source == 2)
|
||
{
|
||
code[j] = "∠";
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
// reconnaissance des fonctions communes aux trois langages
|
||
switch(type)
|
||
{
|
||
case "chaine":
|
||
if(previsions[indice_previsions - 1] == "PREV_END" || previsions[indice_previsions] == "condition_add")
|
||
{
|
||
if(langage_source == 2)
|
||
{
|
||
indices[k] = j;
|
||
k++;
|
||
previsions[0] = "∠";
|
||
previsions[1] = "PREV_END";
|
||
}
|
||
else
|
||
{
|
||
previsions[0] = "PREV_END";
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
}
|
||
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = "chaine";
|
||
j++;
|
||
code[j] = mot_recu;
|
||
break;
|
||
|
||
case "variable":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
indices[k] = j;
|
||
k++;
|
||
code[j] = "variable";
|
||
if(langage_source != 1)
|
||
{
|
||
if(langage_source == 2) previsions[0] = "→_ou_∠";
|
||
if(langage_source == 3) previsions[0] = "→";
|
||
previsions[1] = "PREV_END";
|
||
}
|
||
else
|
||
previsions[0] = "PREV_END";
|
||
|
||
indice_previsions = 0;
|
||
}
|
||
else
|
||
code[j] = "variable";
|
||
j++;
|
||
code[j] = mot;
|
||
break;
|
||
|
||
case "calcul":
|
||
if(mot == ")" && for_ti == 1)
|
||
{
|
||
j--;
|
||
for_ti = 0;
|
||
break;
|
||
}
|
||
|
||
if(mot == "," && for_ti == 1)
|
||
{
|
||
j--;
|
||
break;
|
||
}
|
||
|
||
if(previsions[indice_previsions - 1] == "PREV_END" || previsions[indice_previsions] == "condition_add")
|
||
{
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
indices[k] = j;
|
||
k++;
|
||
}
|
||
code[j] = "calcul";
|
||
if(langage_source != 1 && previsions[indice_previsions] != "condition_add")
|
||
{
|
||
previsions[0] = "→_ou_∠";
|
||
previsions[1] = "PREV_END";
|
||
}
|
||
else
|
||
previsions[0] = "condition_add";
|
||
|
||
indice_previsions = 0;
|
||
}
|
||
else
|
||
{
|
||
code[j] = "calcul";
|
||
}
|
||
|
||
if(for_ti == 1 && indice_previsions == 5)
|
||
for_ti = 0;
|
||
|
||
j++;
|
||
code[j] = mot;
|
||
break;
|
||
|
||
case ",":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = ",";
|
||
break;
|
||
|
||
case "signe":
|
||
if(previsions[indice_previsions - 1] == "PREV_END")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "tout";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
indice_previsions = 0;
|
||
}
|
||
code[j] = "signe";
|
||
j++;
|
||
code[j] = mot;
|
||
break;
|
||
}
|
||
|
||
// en cas de non reconnaissance de l'instruction : erreur
|
||
if(code[j] == "rien")
|
||
{
|
||
erreur_syntaxe[4 * nb_erreurs] = previsions[indice_previsions - 1];
|
||
erreur_syntaxe[4 * nb_erreurs + 1] = mot_recu;
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "non_reconnu";
|
||
erreur_syntaxe[4 * nb_erreurs + 3] = ligne;
|
||
nb_erreurs++;
|
||
previsions[0] = "PREV_END";
|
||
indice_previsions = 0;
|
||
}
|
||
|
||
j++;
|
||
}
|
||
|
||
// affichage des erreurs
|
||
function affiche_erreurs(code) {
|
||
var a;
|
||
|
||
affiche_debug();
|
||
|
||
for(a = nb_erreurs - 1; a >= 0; a--)
|
||
{
|
||
var expression = 0;
|
||
|
||
switch(erreur_syntaxe[4 * a + 2])
|
||
{
|
||
case "non_reconnu":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• ligne " + erreur_syntaxe[4 * a + 3] + " : expression \"" + erreur_syntaxe[4 * a + 1] + "\" non reconnue.</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : vérifiez la syntaxe du mot.</span></p>");
|
||
expression = erreur_syntaxe[4 * a + 1];
|
||
break;
|
||
|
||
case "manquant":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• ligne " + erreur_syntaxe[4 * a + 3] + " : élément de syntaxe manquant.</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : ajoutez " + erreur_syntaxe[4 * a] + ".</span></p>");
|
||
break;
|
||
|
||
case "tout":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• ligne " + erreur_syntaxe[4 * a + 3] + " : élément manquant.</span></p>");
|
||
break;
|
||
|
||
case "instruction_illegale":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• ligne " + erreur_syntaxe[4 * a + 3] + " : instruction \"" + erreur_syntaxe[4 * a + 1] + "\" inadaptée au contexte.</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : vérifiez vos " + erreur_syntaxe[4 * a + 4] + ".</span></p>");
|
||
expression = erreur_syntaxe[4 * a + 1];
|
||
break;
|
||
|
||
case "erreur_conditions":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• Erreur de conditions</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : vérifiez vos conditions.</span></p>");
|
||
break;
|
||
|
||
case "erreur_boucles":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• Erreur de boucles</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : vérifiez vos boucles.</span></p>");
|
||
break;
|
||
|
||
case "erreur_ti":
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• Erreur de structure</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : vérifiez vos conditions et vos boucles.</span></p>");
|
||
break;
|
||
|
||
default:
|
||
$("#debug_titre").after("<p class='erreurs'><span id='description_erreur'>• ligne " + erreur_syntaxe[4 * a + 3] + " : " + erreur_syntaxe[4 * a + 2] + " au contexte.</span><br /><img class='ampoule' src='Images/ampoule.png'/><span id='suggestion_erreur'>Suggestion : remplacer \"" + erreur_syntaxe[4 * a + 1] + "\" par " + erreur_syntaxe[4 * a] + ".</span></p>");
|
||
expression = erreur_syntaxe[4 * a + 1];
|
||
break;
|
||
}
|
||
|
||
if(erreur_syntaxe[4 * a + 2] != "erreur_conditions" && erreur_syntaxe[4 * a + 2] != "erreur_boucles" && erreur_syntaxe[4 * a + 2] != "erreur_ti")
|
||
code = surligne_erreurs(code, erreur_syntaxe[4 * a + 3], expression);
|
||
}
|
||
|
||
return code;
|
||
}
|
||
|
||
// affiche le "debug"
|
||
function affiche_debug() {
|
||
$('#execution').css('height', '85px');
|
||
$('#debug').show();
|
||
}
|
||
|
||
// cache le "debug"
|
||
function masque_erreurs() {
|
||
$('#debug').hide();
|
||
$('#execution').css('height', '210px');
|
||
}
|
||
|
||
// efface le debug
|
||
function debug_efface() {
|
||
$("").replaceAll('.erreurs');
|
||
}
|
||
|
||
function ameliore_syntaxe_description() {
|
||
erreur_syntaxe[4 * nb_erreurs + 2] = "expression \"" + erreur_syntaxe[4 * nb_erreurs + 1] + "\" inadaptée";
|
||
}
|
||
|
||
function ameliore_syntaxe_suggestion(langage_source) {
|
||
var a, nouveau;
|
||
|
||
switch(erreur_syntaxe[4 * nb_erreurs])
|
||
{
|
||
case "variable":
|
||
nouveau = "une variable";
|
||
break;
|
||
|
||
case "chaine":
|
||
nouveau = "un texte";
|
||
break;
|
||
|
||
case "calcul":
|
||
nouveau = "une valeur";
|
||
break;
|
||
|
||
case "chaine_variable_calcul":
|
||
nouveau = "un texte ou une valeur";
|
||
break;
|
||
|
||
case "condition":
|
||
nouveau = "une condition";
|
||
break;
|
||
|
||
case "condition_alors":
|
||
if(langage_source == 1)
|
||
nouveau = "l'instruction \"Alors\"";
|
||
else
|
||
nouveau = "l'instruction \"Then\"";
|
||
break;
|
||
|
||
case "→_ou_∠":
|
||
if(langage_source == 2)
|
||
nouveau = "\"→\" suivi d'une variable ou de \"∠\"";
|
||
else
|
||
nouveau = "\"→\" suivi d'une variable";
|
||
break;
|
||
|
||
default:
|
||
nouveau = "\"" + erreur_syntaxe[4 * nb_erreurs] + "\"";
|
||
break;
|
||
}
|
||
|
||
erreur_syntaxe[4 * nb_erreurs] = nouveau;
|
||
}
|
||
|
||
function detecte_variable(mot) {
|
||
if(mot == "a" || mot == "b" || mot == "c" || mot == "d" || mot == "e" || mot == "f" || mot == "g" || mot == "h" || mot == "i" || mot == "j" || mot == "k" || mot == "l" || mot == "m" || mot == "n" || mot == "o" || mot == "p" || mot == "q" || mot == "r" || mot == "s" || mot == "t" || mot == "u" || mot == "v" || mot == "w" || mot == "x" || mot == "y" || mot == "z")
|
||
return "variable";
|
||
else return mot;
|
||
}
|
||
|
||
|
||
function detecte_calculs(mot, langage_source) {
|
||
var lettre, dernier, avant_dernier = "undefined";
|
||
|
||
mot = mot.toLowerCase();
|
||
|
||
for(a = 0; a < mot.length; a++)
|
||
{
|
||
lettre = mot.substring(a, a + 1);
|
||
|
||
if(mot.substring(a, a + 14) == "racine_carrée(")
|
||
{
|
||
lettre = "+";
|
||
a += 13;
|
||
}
|
||
|
||
if(mot.substring(a, a + 4) == "exp(")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
|
||
if(mot.substring(a, a + 2) == "ln")
|
||
{
|
||
lettre = "+";
|
||
a += 1;
|
||
}
|
||
|
||
if(langage_source == 1)
|
||
{
|
||
if(mot.substring(a, a + 6) == "hasard")
|
||
{
|
||
lettre = "+";
|
||
a += 5;
|
||
}
|
||
|
||
if(mot.substring(a, a + 14) == "partie_entière")
|
||
{
|
||
lettre = "+";
|
||
a += 13;
|
||
}
|
||
|
||
if(mot.substring(a, a + 15) == "partie_décimale")
|
||
{
|
||
lettre = "+";
|
||
a += 14;
|
||
}
|
||
|
||
if(mot.substring(a, a + 14) == "valeur_absolue")
|
||
{
|
||
lettre = "+";
|
||
a += 13;
|
||
}
|
||
}
|
||
|
||
if(langage_source == 2)
|
||
{
|
||
if(mot.substring(a, a + 4) == "#ran")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
|
||
if(mot.substring(a, a + 3) == "int")
|
||
{
|
||
lettre = "+";
|
||
a += 2;
|
||
}
|
||
|
||
if(mot.substring(a, a + 4) == "frac")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
|
||
if(mot.substring(a, a + 3) == "abs")
|
||
{
|
||
lettre = "+";
|
||
a += 2;
|
||
}
|
||
}
|
||
|
||
if(langage_source == 3)
|
||
{
|
||
if(mot.substring(a, a + 4) == "rand")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
|
||
if(mot.substring(a, a + 4) == "int(")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
|
||
if(mot.substring(a, a + 6) == "fpart(")
|
||
{
|
||
lettre = "+";
|
||
a += 5;
|
||
}
|
||
|
||
if(mot.substring(a, a + 4) == "abs(")
|
||
{
|
||
lettre = "+";
|
||
a += 3;
|
||
}
|
||
}
|
||
|
||
dernier = detecte_variable(lettre);
|
||
if((dernier == "variable" && dernier == avant_dernier) || !(detecte_nombre(lettre, 0) == "nombre" || dernier == "variable" || lettre == "+" || lettre == "-" || lettre == "*" || lettre == "%" || lettre == "/" || lettre == "^" || lettre == "(" || lettre == ")" || escape(lettre) == "%u03C0"))
|
||
return "undefined";
|
||
|
||
avant_dernier = dernier;
|
||
}
|
||
|
||
return "calcul";
|
||
}
|
||
|
||
function detecte_nombre(mot, lire) {
|
||
var a, current, point = 0;
|
||
|
||
if(mot == "π")
|
||
return "nombre";
|
||
|
||
for(a = 0; a < mot.length; a++)
|
||
{
|
||
current = mot.substring(a, a + 1);
|
||
|
||
if(lire == 1 && a == 0 && (current == "+" || current == "-") && mot.length > 1)
|
||
continue;
|
||
|
||
if(current == ".")
|
||
point++;
|
||
|
||
if(point > 1 || !(current == "0" || current == "1" || current == "2" || current == "3" || current == "4" || current == "5" || current == "6" || current == "7" || current == "8" || current == "9" || current == "."))
|
||
return mot;
|
||
}
|
||
|
||
return "nombre";
|
||
}
|
||
|
||
function surligne_erreurs(code, ligne, expression) {
|
||
var i;
|
||
var begin = 0, end;
|
||
|
||
for(i = 1; i < ligne; i++)
|
||
{
|
||
begin = code.indexOf("@", begin) + 1;
|
||
}
|
||
|
||
if(expression)
|
||
{
|
||
begin = code.indexOf(expression, begin);
|
||
end = begin + expression.length;
|
||
}
|
||
else
|
||
{
|
||
end = code.indexOf("@", begin) + 1;
|
||
if(end == -1)
|
||
end = code.length;
|
||
}
|
||
|
||
var newcode = code.substring(0, begin) + "<span style='background-color:yellow;'>" + code.substring(begin, end) + "</span>" + code.substring(end, code.length);
|
||
return newcode;
|
||
}
|