Partage
  • Partager sur Facebook
  • Partager sur Twitter

BrainFuck, le retour.

Problème d'array.

Anonyme
    25 octobre 2006 à 16:31:14

    Bonjour !

    <?php
    session_start();
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
            <head>
                    <title>Le BF, c'est chouette.</title>
                    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
            </head>
            <body>
                    <?php
                            // Fonction de conversion nombre > ASCII correspondant.
                            function numberToChar($nombre)
                            {
                                    return $nombre;
                            }
                           
                            $script = $_POST['
    script'];
                            $tempsDExecution = time();
                            $positionDansLArray = 0;
                            $array[255];
                            $i = 0;
                           
                            // Interpretation.
                            function interpret($longueurDuScript,
                                                   $script,
                                                   $tempsDExecution,       
                                                   $i,
                                                   $array,
                                                   $positionDansLArray)
                            {       
                                    $nombreDeCaracteresDansLaBoucle = 0;
                                   
                                    for ($i; $i < $longueurDuScript; $i++)
                                    {
                                            if (!strcmp($script[$i], ".")) echo                                                             
                                                                numberToChar($array[$positionDansLArray]);
                                            if (!strcmp($script[$i], "<")) $positionDansLArray--;
                                            if (!strcmp($script[$i], ">")) $positionDansLArray++;
                                            if (!strcmp($script[$i], "+")) $array[$positionDansLArray]++;
                                            if (!strcmp($script[$i], "-")) $array[$positionDansLArray]--;
                                           
                                            // Test de position dans l'
    array.
                                            if ($positionDansLArray > 255) $positionDansLArray = 255;
                                            if ($positionDansLArray < 0) $positionDansLArray = 0;
                                           
                                            if (!strcmp($script[$i], "["))
                                            {
                                                    // On compte le nombre de caractères dans la boucle
                                                    while (strcmp($script[$i], "]"))
                                                              $nombreDeCaracteresDansLaBoucle++;
                                                   
                                                    // On sauvegarde la position dans le script...
                                                    $backUp = $i + $nombreDeCaracteresDansLaBoucle + 1;
                                                   
                                                    // On interprète la boucle.
                                                    while (!$array[$positionDansLArray])
                                                    {
                                                            interpret($nombreDeCaracteresDansLaBoucle,                                     
                                                                      $script,
                                                                      $tempsDExecution,
                                                                      $i,
                                                                      $array,
                                                                      $positionDansLArray);
                                                    }
                                                   
                                                    // ... et on la restaure !
                                                    $i = $backUp;
                                            }
                                           
                                            if (!strcmp($script[$i], "]")) return;
                                           
                                            // Vérification du temps d'éxécution
                                            if (time() > $tempsDExecution + 15)
                                            {
                                                    echo "<br />Temps d'éxécution dépassé !";
                                                    return;
                                            }
                                    }
                            }
                           
                            echo "<p>\n\t";
                            interpret(strlen($script),
                                      $script,
                                      $tempsDExecution,
                                      $i,
                                      $array,
                                      $positionDansLArray);
                            echo "\n</p>";
                    ?>
            </body>
    </html>


    Il y a une erreur d'array; la variable array est déclarée en tant que simple variable. De plus, je ne peux plus déclarer de variables sans lui assigner une valeur.

    Pourriez vous m'aider ?

    Merci !

    Tchaw !

    • Partager sur Facebook
    • Partager sur Twitter

    BrainFuck, le retour.

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown