Ajax HTML 5 Création site CMS Comment Design Logiciels Programmation RSS SQL Scriptol Scripts Mobiles
Forum
Scriptol
Description
Exemples
Applications
Utilisation
Télécharger
Installer
Manuel
XML et HTML
Scripts HTML
Scripts XML
DOM
Tutoriels


Exemples de code Scriptol

Ces codes sources ont été testés avec le compilateur Scriptol PHP et le compilateur Scriptol C++ / Binaire.

Récursion

Algorithme de Fibonacci récursif. Calcul des nombres de Fibonacci.

constant int fibmax = 16
int z = 0

int fib(int n)
  if n <= 1 :  z = n
  else
     z = 0 + fib(n - 1) + fib(n - 2)
  /if
return z

for int i in 0..fibmax
  print "fib($i)=" , fib(i)
/for

Tableaux

Comparaison de fichiers texte. Compare deux fichiers texte chargés dans des tableaux.

array f1, f2
if argsize <> 3 ? die("usage:  fcomp file1 file2")
echo "Comparing ", arglist[1]," ", arglist[2] , ": "
	
if not file_exists(arglist[1]) ? die(arglist[1] + " not found")
if not file_exists(arglist[2]) ? die(arglist[2] + " not found")
f1.load(arglist[1])
f2.load(arglist[2])
if f1.size() <> f2.size() ? die("sizes differ")
for int i in 0..f1.size() - 1
  if f1[i] <> f2[i] ? die("files differ")
/for
print "no difference found."

Fonctions intégrées

L'heure et la date courante ou dernière modification d'un fichier.

print "Example of date and time"
print "Format ISO 8601 (PHP 5/Scriptol C++)"
real d = time()
print "Current date and time:", date("c", d)
d = filetime("exdate.sol")
text filedate = date("c", d)
print "Date of this file:", filedate[ .. 9]

Ligne de commande

Hello You. Fonctions d'entrée-sorties de base en ligne de commande.

text name
input "What is you name? ", name
print "Hello", name

Arguments de ligne de commande. Passer des arguments en ligne de commande.

extern int argc
extern array argv

int main(int argnum, array arglist)
  print argnum, "arguments"
  int i = 0
  scan arglist                         ` scan the array
    echo i, ")", " ", arglist[], "\n"  ` display next argument
    i + 1
  /scan
return 0

main(argc, argv)  ` argv and argc are  PHP or C variables.

Classes

Simple classe avec une méthode. Compter les occurences de mots dans une chaine de caractères.

class Words
  int count(text base, text sea)
  int ctr = 0
  int i = 0
  while forever
    i = base.find(sea, i)
    if i = nil break
      i + 1
      ctr + 1
  /while
  return ctr

/class


Words demos
text sample = "a b c de a hello a"
print "Number of words:", demos.count(sample, "a")

Héritage et méthodes statiques. Définir une classe et une sous-classe. Instance, méthode et méthode statique.

class Car
    int power = 850
    int getPower() return power
    
    static text color(int c)
        text tc = "other"
        if c
        = 1: tc = "blue"
        = 2: tc = "green"
        = 4: tc = "red"
        /if
    return "color is " + tc
    
/class

class FormulaOne is Car
    int speed
    int getSpeed()
        speed = getPower() * 2 / 5
    return speed
/class

FormulaOne f1
print f1.power
print f1.getPower()
print f1.getSpeed()
print FormulaOne.color(4)  

Graphismes utilisant GD (Scriptol PHP)

Dessiner un bouton. Créer un bouton avec un libellé, avec la bibliothèque Scriptol Image.

include "phpgd.h"
include "image.sol"

print "Program Button - Testing GD"

Image button
button.create(88,31)
int black = button.createColor(0, 0, 0)
int white = button.createColor(255,255,255)
int green = button.createColor(0, 192, 0)

` filling background and drawing borders
button.fill(green)
button.line(0,0,87,0, white)
button.line(0,0,0,30, white)
button.line(0,30,87,30, black)
button.line(87,0,87,30, black)

` now, writing a label
button.setFontSize(5)
button.write(26, 8, "Label", black)

text bname = "button.jpg"
button.saveJpeg(bname, 100)
print bname,"created"

DOM et XML

Créer un simple fichier XML accessible par les méthodes de DOM.

text tag = "Internet"
text title = "My article"
text article ="Here is the story I am speaking of..."
text fname="article.xml"

array arr = array("<?xml version=\"1.0\" ?>\n",  "<articles>\n", 
" <article tag=\"" + tag + "\" title=\"" + title+ "\" >\n", article + "\n",
" </article>\n", "</articles>\n" ) file nfile = fopen(fname, "w") for text x in arr nfile.write(x) /for nfile.close()

Le fichier XML créé:

<?xml version="1.0" ?>
<articles>
<article tag="Internet" title="My article" >
Here is the story I am speaking of...
</article>
</articles>

Charger le fichier XML et lire le contenu par les attributs et méthodes de DOM.

text name = "article.xml";

DOMDocument doc
DOMNodeList articles
DOMNode node
DOMElement article = null

doc.load(name)
articles = doc.getElementsByTagName("article")
node= articles.item(0)
article = node

text tag = article.getAttribute("tag")
text title= article.getAttribute("title")
text content= article.textContent

print "Title:",title,"Tag:",tag,"Content:",content
  
  • Télécharger tous les sources dans une archive zip.

Autres sources

  • Algorithmes couramment utilisés, sont disponibles sur le site web Scriptol.net.
  • Le répertoire XML propose des scripts et outils XML.

© 2001-2011 Scriptol.fr