Commit 4a2f5106 authored by Georges Khaznadar's avatar Georges Khaznadar

Import Upstream version 0.10~beta

parents
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.dll
*.dylib
# Qt-es
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
Makefile*
*build-*
# QtCreator
*.autosave
# QtCtreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCtreator CMake
CMakeLists.txt.user*
__pycache__
*.pyc
.idea
.vs
dist
build
src/editor_backend.spec
editor_backend
turing
*.gz
*.zip
src/turing.spec
.DS_Store
# Contributing to Turing
## Code
just make good code
follow pep8 and everything will be good
## Translation
Translators must use Qt Linguist. It can be obtained by installing the Qt toolkit.
### Editing an existing language
Just open the .ts file in Linguist and change what needs to be changed.
### Adding a new language
First, create a new .ts file in /src/lang/ using the following template:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0" language="LANGUAGE CODE" sourcelanguage="en">
<context>
</context>
</TS>
Replace `LANGUAGE CODE` by the ISO code of the language. If the language is "generic", use the short code (example: French `fr`, German `de`, Spanish `es`), but if it's not, use the full code (example: Simplified Chinese `zh-Hans`, Traditional Chinese `zh-Hant`).
Then, download the [FatCow Hosting Icons pack](http://www.fatcow.com/free-icons), find the corresponding flag in the 16x16 folder. Rename it to the language code you used for the .ts file (example: fr.png, de.png, zh-Hans.png) and put that in the /src/media/lang/ folder.
Open a command prompt in /src/ and run tools/compile-gui (make sure that the CWD is /src/).
Then, open /src/turing.qrc in Qt Creator and add /src/lang/LANGUAGE.qm and /src/media/lang/LANGUAGE.png under the /lang prefix. Save, and use /src/run to test and make sure everything works.
\ No newline at end of file
MIT License
Copyright (c) 2018 TuringApp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[![GitHub issues](https://img.shields.io/github/issues/TuringApp/Turing.svg)](https://github.com/TuringApp/Turing/issues) [![GitHub stars](https://img.shields.io/github/stars/TuringApp/Turing.svg)](https://github.com/TuringApp/Turing/stargazers) [![GitHub license](https://img.shields.io/github/license/TuringApp/Turing.svg)](https://github.com/TuringApp/Turing/blob/master/LICENSE) [![Gitter](https://img.shields.io/gitter/room/TuringDevelopment/Lobby.svg)]( https://gitter.im/TuringDevelopment)
# Turing
Turing is a free and cross-platform app whose main goal is to assist the learning of algorithms and programming languages by providing easy-to-use development tools to all.
It provides a lighter alternative to the well-known Algobox, which is the currently de-facto widely used solution.
**Note:** Turing was originally meant to be a school project for the [CS class](https://twitter.com/davR74130). Don't expect enterprise-grade code here. We do our best to keep the whole codebase clean, but some parts are still undocumented and not covered by unit tests.
## Quid, quis, quomodo?
Turing is written in Python 3.6 and uses the PyQt5 framework for its GUI. It provides two work modes:
- Algorithm mode
- Uses a "natural" pseudocode language similar to the one used in Algobox and school books.
- Assisted development
- Program mode
- Uses Python, for the more experienced
In both modes, the code can be debugged and executed step-by-step to facilitate the problem-solving side of development.
## Using Turing
Turing is cross-platform, but has only been tested on Windows and Linux-based operating systems. macOS should be supported, but no guarantee is made of that.
### Using pre-compiled binaries (recommended)
Click on the [**Releases**](https://github.com/TuringApp/Turing/releases) tab at the top of the page and download the release corresponding to your OS.
- windows32: Windows 32 bits (7 or later)
- tested on 10 x64
- nix64: Linux 64 bits (Ubuntu 14.04 or later)
- tested on 18.04
- osx: macOS 64 bits (10.13 *High Sierra* or later)
- tested on 10.13
### Using the source code (advanced users)
#### Python 3.6 required!
**You need to have `python3` point to Python 3.6 in your shell! Either use an alias in your `.bashrc` or a distribution that comes with Python 3.6.**
It uses the following libraries:
- [PyQt 5](https://riverbankcomputing.com/software/pyqt/) - UI framework
- [pyQode](https://github.com/pyQode/pyQode) - PyQt code editor with syntax highlighting
- [Pygments](http://pygments.org/) - Syntax highlighter for printing code files
- [pep8](https://pypi.python.org/pypi/pep8) - Code quality checker
First, install everything using pip:
pip install --ignore-installed -r requirements.txt
Note: if you have Python 2.x installed on your computer (which is the case on 99% of Linux distributions), the old `pip` may be present in `PATH` and interfere with the above command line. If that happens, try using `pip3` instead of `pip`. Of course, it must be the `pip` paired with the installed Python3 (so you may need to use `pip3.6` instead).
Next, open the src/ folder and use `run.bat` or `source run.sh` depending on your operating system.
#### Building Turing (using pyInstaller)
You need:
- Python 3.6 (`python3.6`)
- Python 3.6 dev package (`python3.6-dev`)
- Qt5 `lrelease` (`qt5-dev-tools`)
## Contributing
We're currently looking for translators. For more information, see the [CONTRIBUTING.md](CONTRIBUTING.md) file and [the Gitter](https://gitter.im/TuringDevelopment).
If you're a developer and you found a bug somewhere and fixed it, feel free to make a PR, we usually answer in no more than a few hours.
#!/bin/sh
python3 /usr/share/turing/src/main.py
@echo off
pushd src && tools\compile-gui && python tools\build.py && popd && xcopy /y src\dist\turing.exe . && gen-arc
#!/bin/bash
cd src
source tools/compile-gui.sh
python3 tools/build.py
cd ..
\cp src/dist/turing .
source gen-arc.sh
theme: jekyll-theme-cayman
show-downloads: true
\ No newline at end of file
This diff is collapsed.
# Built-in expression parser
Turing has a built-in mathematical expression parser, which is used when the program is in pseudocode mode.
The language is case-insensitive for keywords, i.e. `FALSE`, `false` and `FaLsE` are the same thing.
## Types
### Number
Stored using a Python `float`, automatically converted to `int` when needed.
A point (`.`) shall be used to separate the integer part from the fractional part.
#### Example
- `42`
- `3.1415`
### Boolean
Stored using a Python `bool`, automatically converted to Number when needed (only if strict mode is disabled).
#### Syntax
The following keywords are available:
- `TRUE` / `VRAI` : True value
- `FALSE` / `FAUX` : False value
### String
Stored using a Python `str` (Unicode).
A string is enclosed between double quotes (`"`). It is not possible yet to escape characters inside a string literal.
### List
Stored using a Python `list`, indices start at 0 (like in any real programming language. *Lua*, you should feel ashamed of yourself).
#### Operators
Certain operators can be applied on operands of type List.
##### `+` (Plus)
Concatenates two lists.
###### Examples
- `[1, 2, 3] + [3, 4, 5] == [1, 2, 3, 3, 4, 5]`
##### `-` (Binary minus)
Returns all items of A that are not in B.
###### Examples
- `[1, 2, 3] - [3, 4, 5] == [1, 2]`
##### `-` (Unary minus)
Returns a reversed copy of the list.
###### Examples
- `-[1, 2, 3] == [3, 2, 1]`
##### `*` (Times)
*Must be used on a List and a Number together.*
Duplicates the list the specified amount of times.
###### Examples
- `[1, 2, 3] * 3 == [1, 2, 3, 1, 2, 3, 1, 2, 3]`
##### `&` / `ET` (Intersection)
Returns all items of A that are also in B.
###### Examples
- `[1, 2, 3] & [2, 3, 4] == [2, 3]`
##### `|` / `OU` (Union)
Returns an ordered list of all items of A and all items of B, without duplicates.
###### Examples
- `[1, 2, 3] | [2, 3, 4] == [1, 2, 3, 4]`
##### `XOR` (exclusive Or)
Returns an ordered list of all items that are present either in A or B but not both.
###### Examples
- `[1, 2, 3] XOR [3, 4, 5] == [1, 2, 4, 5]`
### Function / lambda
Standard Python function.
#### Calling
A function call consists of the function followed by an argument list enclosed in parentheses. The function can be an identifier or any expression returning a function.
someFunc(arg1, arg2, arg3)
The argument list can be passed as a list object, for example for dynamic calls, using the `*` expanding operator in front of the list object.
gcd(*[248, 4584]) == gcd(248, 4584)
#### Lambda/inline function syntax
Comma-separated list of parameters enclosed in braces, followed by expression enclosed in parentheses. The function can be called immediately. There is no limit to the amount of parameters. A parameter is made of an identifier, no less, no more.
Varargs are not available yet.
##### Examples
- `{x, y}(2 * x + y)(3, 8) == 14`
- `map({a}(2 * a), [2, 3, 4]) == [4, 6, 8]`
## Operators
### Binary operators
| Symbol | Operator | Types |
|--------|----------|-------|
| `+` | Plus, Concatenate | Number, String, List |
| `-` | Minus, Reverse | Number, List |
| `*` | Times, Repeat | Number, List |
| `/` | Divide | Number |
| `%` | Modulus | Number |
| `^` | Power | Number |
| `<=` | Less than or equal | Number |
| `<` | Strictly less than | Number |
| `>` | Strictly greater than | Number |
| `>=` | Greater than or equal | Number |
| `==` | Equals | All |
| `!=` | Not equals | All |
| `&` / `ET` | AND / Intersection | Number, Boolean, List |
| <code>&#124;</code> / `OU` | OR / Union | Number, Boolean, List |
| `XOR` | Exclusive OR / Exclusive union | Number, Boolean, List |
### Unary operators
| Symbol | Operator | Types |
|--------|----------|-------|
| `-` | Negate | Number, List |
| `NON` | Invert | Boolean |
The numbers and booleans are treated the same way as in **plain Python**. In other words, booleans can be treated as numbers (`False` becomes 0 and `True` becomes 1), and numbers can be treated as booleans (0 becomes `False` and everything else becomes `True).
If **strict mode** is enabled, operators can only be used with operands of **identical type**, and **implicit number-boolean casts** are disabled. The `c_bool` and `c_num` functions can then be used for that purpose.
## Function library
The engine provides many functions that can be used with almost all value types.
In the following table, a type name followed by a star (*) means that the function accepts a variable argument list of the specified self.
#### Example
The `average` function accepts either List(Number) or Number*. Thus, it can be used either with a list object: `average(myList)` or with varargs: `average(1, 2, 3)`.
| Name | Parameters | Description |
|------|------------|-------------|
{{{funcdoc}}}
Useful (?) constants are also provided, with the maximum supported precision.
| Name | Approximated value | Description |
|------|-------------------:|-------------|
{{{constdoc}}}
# Turing
## Documentation
- [Expression parser](expression.html)
BlockStmt([CommentStmt('Finds the square root of a number using the Babylonian algorithm'), InputStmt(IdentifierNode('a'), None), AssignStmt(IdentifierNode('x'), NumberNode(1)), AssignStmt(IdentifierNode('y'), IdentifierNode('a')), AssignStmt(IdentifierNode('prec'), NumberNode(1e-08)), WhileStmt(BinOpNode(CallNode(IdentifierNode('abs'), [BinOpNode(IdentifierNode('y'), IdentifierNode('x'), '-')]), IdentifierNode('prec'), '>'), [AssignStmt(IdentifierNode('x'), BinOpNode(BinOpNode(IdentifierNode('x'), IdentifierNode('y'), '+'), NumberNode(2), '/')), AssignStmt(IdentifierNode('y'), BinOpNode(IdentifierNode('a'), IdentifierNode('x'), '/'))]), DisplayStmt(CallNode(IdentifierNode('round'), [CallNode(IdentifierNode('min'), [ListNode([IdentifierNode('x'), IdentifierNode('y')])]), IdentifierNode('prec')]), False), DisplayStmt(StringNode(' ≤ √a ≤ '), False), DisplayStmt(CallNode(IdentifierNode('round'), [CallNode(IdentifierNode('max'), [ListNode([IdentifierNode('x'), IdentifierNode('y')])]), IdentifierNode('prec')]), True)])
\ No newline at end of file
BlockStmt([CommentStmt('Solves Func(x)=0 on the interval [a, b]'), AssignStmt(IdentifierNode('Func'), LambdaNode(['x'], BinOpNode(BinOpNode(IdentifierNode('x'), NumberNode(1), '-'), BinOpNode(NumberNode(1), IdentifierNode('x'), '/'), '-'))), AssignStmt(IdentifierNode('prec'), NumberNode(1e-08)), InputStmt(IdentifierNode('a'), None), InputStmt(IdentifierNode('b'), None), WhileStmt(BinOpNode(BinOpNode(IdentifierNode('b'), IdentifierNode('a'), '-'), IdentifierNode('prec'), '>'), [AssignStmt(IdentifierNode('m'), BinOpNode(BinOpNode(IdentifierNode('a'), IdentifierNode('b'), '+'), NumberNode(2), '/')), IfStmt(BinOpNode(BinOpNode(CallNode(IdentifierNode('Func'), [IdentifierNode('m')]), CallNode(IdentifierNode('Func'), [IdentifierNode('b')]), '*'), NumberNode(0), '>'), [AssignStmt(IdentifierNode('b'), IdentifierNode('m'))]), ElseStmt([AssignStmt(IdentifierNode('a'), IdentifierNode('m'))])]), DisplayStmt(CallNode(IdentifierNode('round'), [IdentifierNode('a'), IdentifierNode('prec')]), False), DisplayStmt(StringNode(' < x < '), False), DisplayStmt(CallNode(IdentifierNode('round'), [IdentifierNode('b'), IdentifierNode('prec')]), True)])
\ No newline at end of file
import colorsys
import numpy as np
g_window(-5, 5, -2, 2)
step = 0.2
size = 0.1
func = lambda a: 1.5 * cos(a) * cos(0.5 * a)
for x in np.arange(-5, 5, step):
(r, g, b) = colorsys.hsv_to_rgb((x + 5) / 10, 1.0, 1.0)
r = int(255 * r)
g = int(255 * g)
b = int(255 * b)
clr = ('#%02x%02x%02x') % (r, g, b)
for xx in np.arange(x, x + step + size, size):
y = func(xx)
g_line(xx, y, xx, 0, clr)
\ No newline at end of file
words = ["HELLO", "COMPUTER", "KEYBOARD", "INTERNET", "CORRECT", "HORSE", "BATTERY", "STAPLE"]
word = choice(words)
user = ["_" for _ in word]
tries = 10
while True:
if tries <= 0:
print("You lose!")
print("The word was: " + word)
break
print(" ".join(user))
if user == list(word):
print("You win!")
break
print("%d tries remaining" % tries)
current = input("? ")[:1].upper()
if not current:
continue
for i in range(len(user)):
if word[i] == current:
user[i] = current
if current not in word:
tries -= 1
print("\n")
BlockStmt([AssignStmt(IdentifierNode('words'), ListNode([StringNode('HELLO'), StringNode('COMPUTER'), StringNode('KEYBOARD'), StringNode('INTERNET'), StringNode('CORRECT'), StringNode('HORSE'), StringNode('BATTERY'), StringNode('STAPLE')])), AssignStmt(IdentifierNode('word'), CallNode(IdentifierNode('choice'), [IdentifierNode('words')])), AssignStmt(IdentifierNode('user'), BinOpNode(ListNode([StringNode('_')]), CallNode(IdentifierNode('len'), [IdentifierNode('word')]), '*')), AssignStmt(IdentifierNode('tries'), NumberNode(10)), WhileStmt(NumberNode(True), [IfStmt(BinOpNode(IdentifierNode('tries'), NumberNode(0), '<='), [DisplayStmt(StringNode('You lose!'), True), DisplayStmt(BinOpNode(StringNode('The word was: '), IdentifierNode('word'), '+'), True), BreakStmt()]), DisplayStmt(CallNode(IdentifierNode('c_str'), [IdentifierNode('user')]), True), IfStmt(BinOpNode(IdentifierNode('user'), CallNode(IdentifierNode('c_list'), [IdentifierNode('word')]), '=='), [DisplayStmt(StringNode('You win!'), True), BreakStmt()]), DisplayStmt(BinOpNode(IdentifierNode('tries'), StringNode(' tries remaining'), '+'), True), InputStmt(IdentifierNode('current'), StringNode('? '), True), IfStmt(BinOpNode(CallNode(IdentifierNode('len'), [IdentifierNode('current')]), NumberNode(1), '!='), [ContinueStmt()]), AssignStmt(IdentifierNode('found'), NumberNode(False)), ForStmt('i', NumberNode(0), BinOpNode(CallNode(IdentifierNode('len'), [IdentifierNode('user')]), NumberNode(1), '-'), [IfStmt(BinOpNode(ArrayAccessNode(IdentifierNode('word'), IdentifierNode('i')), CallNode(IdentifierNode('upper'), [IdentifierNode('current')]), '=='), [AssignStmt(ArrayAccessNode(IdentifierNode('user'), IdentifierNode('i')), ArrayAccessNode(IdentifierNode('word'), IdentifierNode('i'))), AssignStmt(IdentifierNode('found'), NumberNode(True))])], None), IfStmt(UnaryOpNode(IdentifierNode('found'), 'NOT'), [AssignStmt(IdentifierNode('tries'), BinOpNode(IdentifierNode('tries'), NumberNode(1), '-'))]), DisplayStmt(StringNode(' '), True)])])
\ No newline at end of file
BlockStmt([CommentStmt('Approximates the integral of f(x) from a to b using the trapezoidal rule.'), AssignStmt(IdentifierNode('f'), LambdaNode(['x'], BinOpNode(CallNode(IdentifierNode('sin'), [IdentifierNode('x')]), NumberNode(2), '^'))), InputStmt(IdentifierNode('a'), None), InputStmt(IdentifierNode('b'), None), AssignStmt(IdentifierNode('count'), NumberNode(10)), AssignStmt(IdentifierNode('result'), NumberNode(0)), AssignStmt(IdentifierNode('step'), BinOpNode(BinOpNode(IdentifierNode('b'), IdentifierNode('a'), '-'), IdentifierNode('count'), '/')), ForStmt('i', NumberNode(0), BinOpNode(IdentifierNode('count'), NumberNode(1), '-'), [AssignStmt(IdentifierNode('result'), BinOpNode(IdentifierNode('result'), BinOpNode(BinOpNode(IdentifierNode('step'), NumberNode(2), '/'), BinOpNode(CallNode(IdentifierNode('f'), [BinOpNode(IdentifierNode('a'), BinOpNode(IdentifierNode('i'), IdentifierNode('step'), '*'), '+')]), CallNode(IdentifierNode('f'), [BinOpNode(IdentifierNode('a'), BinOpNode(BinOpNode(IdentifierNode('i'), NumberNode(1), '+'), IdentifierNode('step'), '*'), '+')]), '+'), '*'), '+'))], None), DisplayStmt(BinOpNode(StringNode('∫a→b f(x) dx = '), IdentifierNode('result'), '+'), True)])
\ No newline at end of file
BlockStmt([CommentStmt('Approximates the value of Pi using the Monte-Carlo algorithm'), AssignStmt(IdentifierNode('sum'), NumberNode(0)), AssignStmt(IdentifierNode('steps'), NumberNode(10000)), ForStmt('i', NumberNode(1), IdentifierNode('steps'), [AssignStmt(IdentifierNode('x'), CallNode(IdentifierNode('random'), [])), AssignStmt(IdentifierNode('y'), CallNode(IdentifierNode('random'), [])), IfStmt(BinOpNode(BinOpNode(BinOpNode(IdentifierNode('x'), IdentifierNode('x'), '*'), BinOpNode(IdentifierNode('y'), IdentifierNode('y'), '*'), '+'), NumberNode(1), '<'), [AssignStmt(IdentifierNode('sum'), BinOpNode(IdentifierNode('sum'), NumberNode(1), '+'))])], None), AssignStmt(IdentifierNode('approx_pi'), BinOpNode(BinOpNode(NumberNode(4), IdentifierNode('sum'), '*'), IdentifierNode('steps'), '/')), DisplayStmt(BinOpNode(StringNode('Pi ~= '), IdentifierNode('approx_pi'), '+'))])
\ No newline at end of file
mots = [
"BONJOUR",
"ORDINATEUR",
"CLAVIER",
"SOURIS",
"CHEVAL",
"OISEAU",
"CHIEN"
]
mot = choix(mots)
saisi = ["_"] * taille(mot)
essais = 10
while True:
if essais <= 0:
print("Vous avez perdu !")
print("Le mot était : " + mot)
break
print(" ".join(saisi))
if saisi == list(mot):
print("Vous avez gagné !")
break
print("%d essais restants" % essais)
lettre = maju(input("? "))
for i in range(taille(mot)):
if mot[i] == lettre:
saisi[i] = lettre
if lettre not in mot:
essais -= 1
print(" ")
\ No newline at end of file
BlockStmt([AssignStmt(IdentifierNode('Prix'), CallNode(IdentifierNode('randint'), [NumberNode(0), NumberNode(1000)])), AssignStmt(IdentifierNode('X'), UnaryOpNode(NumberNode(1), '-')), AssignStmt(IdentifierNode('Essais'), NumberNode(0)), WhileStmt(BinOpNode(IdentifierNode('X'), IdentifierNode('Prix'), '!='), [InputStmt(IdentifierNode('X'), None, False), IfStmt(BinOpNode(IdentifierNode('X'), IdentifierNode('Prix'), '<'), [DisplayStmt(StringNode(' '), True), DisplayStmt(StringNode("C'est trop bas !!"), True), DisplayStmt(StringNode(' '), True)]), ElseStmt([DisplayStmt(StringNode(' '), True), DisplayStmt(StringNode("C'est trop haut !"), True), DisplayStmt(StringNode(' '), True)]), AssignStmt(IdentifierNode('Essais'), BinOpNode(IdentifierNode('Essais'), NumberNode(1), '+'))]), DisplayStmt(BinOpNode(BinOpNode(StringNode("C'est gagné WAY WAY WAY, en "), IdentifierNode('Essais'), '+'), StringNode(' essais !'), '+'), True)])
\ No newline at end of file
BlockStmt([AssignStmt(IdentifierNode('lst'), ListNode([NumberNode(5), NumberNode(1), NumberNode(4), NumberNode(2), NumberNode(8), NumberNode(2), NumberNode(7), NumberNode(1), NumberNode(8), NumberNode(3), NumberNode(6), NumberNode(4), NumberNode(9), NumberNode(5), NumberNode(2), NumberNode(4)])), GWindowStmt(NumberNode(0), CallNode(IdentifierNode('len'), [IdentifierNode('lst')]), CallNode(IdentifierNode('min'), [IdentifierNode('lst')]), CallNode(IdentifierNode('max'), [IdentifierNode('lst')]), NumberNode(0), NumberNode(0)), ForStmt('i', BinOpNode(CallNode(IdentifierNode('len'), [IdentifierNode('lst')]), NumberNode(1), '-'), NumberNode(1), [ForStmt('j', NumberNode(0), BinOpNode(IdentifierNode('i'), NumberNode(1), '-'), [GClearStmt(), IfStmt(BinOpNode(ArrayAccessNode(IdentifierNode('lst'), BinOpNode(IdentifierNode('j'), NumberNode(1), '+')), ArrayAccessNode(IdentifierNode('lst'), IdentifierNode('j')), '<'), [CallStmt(IdentifierNode('swap'), [IdentifierNode('lst'), BinOpNode(IdentifierNode('j'), NumberNode(1), '+'), IdentifierNode('j')]), GLineStmt(IdentifierNode('j'), CallNode(IdentifierNode('max'), [IdentifierNode('lst')]), BinOpNode(IdentifierNode('j'), NumberNode(1), '+'), CallNode(IdentifierNode('max'), [IdentifierNode('lst')]), StringNode('red'))]), ElseStmt([GLineStmt(IdentifierNode('j'), CallNode(IdentifierNode('max'), [IdentifierNode('lst')]), BinOpNode(IdentifierNode('j'), NumberNode(1), '+'), CallNode(IdentifierNode('max'), [IdentifierNode('lst')]), StringNode('green'))]), ForStmt('i', NumberNode(0), BinOpNode(CallNode(IdentifierNode('len'), [IdentifierNode('lst')]), NumberNode(1), '-'), [GLineStmt(IdentifierNode('i'), NumberNode(0), IdentifierNode('i'), ArrayAccessNode(IdentifierNode('lst'), IdentifierNode('i')), StringNode('red'))], None), SleepStmt(NumberNode(0.3))], None)], None)])
\ No newline at end of file
BlockStmt([CommentStmt('Calculates the n-th Fibonacci number using a recursive function'), FuncStmt('fibo', ['n'], [IfStmt(BinOpNode(IdentifierNode('n'), NumberNode(1), '<='), [ReturnStmt(IdentifierNode('n'))]), ReturnStmt(BinOpNode(CallNode(IdentifierNode('fibo'), [BinOpNode(IdentifierNode('n'), NumberNode(1), '-')]), CallNode(IdentifierNode('fibo'), [BinOpNode(IdentifierNode('n'), NumberNode(2), '-')]), '+'))]), InputStmt(IdentifierNode('num'), None), DisplayStmt(CallNode(IdentifierNode('fibo'), [IdentifierNode('num')]))])
\ No newline at end of file
BlockStmt([CommentStmt('Recursively calculates the GCD of two numbers'), FuncStmt('gcd', ['a', 'b'], [IfStmt(BinOpNode(IdentifierNode('a'), NumberNode(0), '=='), [ReturnStmt(IdentifierNode('b'))]), IfStmt(BinOpNode(IdentifierNode('b'), NumberNode(0), '=='), [ReturnStmt(IdentifierNode('a'))]), IfStmt(BinOpNode(IdentifierNode('b'), IdentifierNode('a'), '<='), [ReturnStmt(CallNode(IdentifierNode('gcd'), [BinOpNode(IdentifierNode('a'), IdentifierNode('b'), '-'), IdentifierNode('b')]))]), ReturnStmt(CallNode(IdentifierNode('gcd'), [IdentifierNode('a'), BinOpNode(IdentifierNode('b'), IdentifierNode('a'), '-')]))]), InputStmt(IdentifierNode('num1'), None), InputStmt(IdentifierNode('num2'), None), DisplayStmt(BinOpNode(BinOpNode(BinOpNode(BinOpNode(BinOpNode(StringNode('GCD of '), IdentifierNode('num1'), '+'), StringNode(' and '), '+'), IdentifierNode('num2'), '+'), StringNode(' is '), '+'), CallNode(IdentifierNode('gcd'), [IdentifierNode('num1'), IdentifierNode('num2')]), '+'))])
\ No newline at end of file
BlockStmt([CommentStmt('Displays the sum of all integers from 1 to user-inputted number'), AssignStmt(IdentifierNode('s'), NumberNode(0)), InputStmt(IdentifierNode('n'), None), ForStmt('i', NumberNode(1), IdentifierNode('n'), [AssignStmt(IdentifierNode('s'), BinOpNode(IdentifierNode('s'), IdentifierNode('i'), '+'))], None), DisplayStmt(StringNode('Sum: ')), DisplayStmt(IdentifierNode('s'))])
\ No newline at end of file
BlockStmt([CommentStmt('Finds the roots of a second-degree polynomial using the quadratic formula.'), DisplayStmt(StringNode('f(x) = ax² + bx + c'), True), InputStmt(IdentifierNode('a'), None), InputStmt(IdentifierNode('b'), None), InputStmt(IdentifierNode('c'), None), AssignStmt(IdentifierNode('D'), BinOpNode(BinOpNode(IdentifierNode('b'), NumberNode(2), '^'), BinOpNode(BinOpNode(NumberNode(4), IdentifierNode('a'), '*'), IdentifierNode('c'), '*'), '-')), DisplayStmt(BinOpNode(StringNode('Δ = '), IdentifierNode('D'), '+'), True), IfStmt(BinOpNode(IdentifierNode('a'), NumberNode(0), '!='), [AssignStmt(IdentifierNode('alpha'), BinOpNode(BinOpNode(UnaryOpNode(IdentifierNode('b'), '-'), NumberNode(2), '/'), IdentifierNode('a'), '*')), AssignStmt(IdentifierNode('beta'), BinOpNode(BinOpNode(IdentifierNode('D'), NumberNode(4), '/'), IdentifierNode('a'), '*')), DisplayStmt(BinOpNode(StringNode('α = '), IdentifierNode('alpha'), '+'), True), DisplayStmt(BinOpNode(StringNode('β = '), IdentifierNode('beta'), '+'), True)]), IfStmt(BinOpNode(IdentifierNode('D'), NumberNode(0), '<'), [DisplayStmt(StringNode('No real roots'), True)]), ElseStmt([IfStmt(BinOpNode(IdentifierNode('D'), NumberNode(0), '=='), [AssignStmt(IdentifierNode('x0'), BinOpNode(BinOpNode(UnaryOpNode(IdentifierNode('b'), '-'), NumberNode(2), '/'), IdentifierNode('a'), '*')), DisplayStmt(BinOpNode(StringNode('Unique real root - x0 = '), IdentifierNode('x0'), '+'), True)]), ElseStmt([AssignStmt(IdentifierNode('x1'), BinOpNode(BinOpNode(BinOpNode(UnaryOpNode(IdentifierNode('b'), '-'), CallNode(IdentifierNode('sqrt'), [IdentifierNode('D')]), '-'), NumberNode(2), '/'), IdentifierNode('a'), '*')), AssignStmt(IdentifierNode('x2'), BinOpNode(BinOpNode(BinOpNode(UnaryOpNode(IdentifierNode('b'), '-'), CallNode(IdentifierNode('sqrt'), [IdentifierNode('D')]), '+'), NumberNode(2), '/'), IdentifierNode('a'), '*')), DisplayStmt(StringNode('Two real roots:'), True), DisplayStmt(BinOpNode(StringNode('x1 = '), IdentifierNode('x1'), '+'), True), DisplayStmt(BinOpNode(StringNode('x2 = '), IdentifierNode('x2'), '+'), True)])])])
\ No newline at end of file
BlockStmt([CommentStmt('Such wiggle wow'), ForStmt('i', NumberNode(1), NumberNode(100), [GClearStmt(), GFuncStmt('x', BinOpNode(BinOpNode(IdentifierNode('i'), CallNode(IdentifierNode('cos'), [BinOpNode(IdentifierNode('x'), BinOpNode(IdentifierNode('i'), NumberNode(3), '/'), '+')]), '*'), NumberNode(25), '/'), UnaryOpNode(NumberNode(7), '-'), NumberNode(7), NumberNode(0.1), StringNode('red')), GWindowStmt(UnaryOpNode(NumberNode(10), '-'), NumberNode(10), UnaryOpNode(NumberNode(10), '-'), NumberNode(10), NumberNode(0), NumberNode(0)), SleepStmt(NumberNode(0.001))], None)])
\ No newline at end of file
BlockStmt([AssignStmt(IdentifierNode('C'), NumberNode(0)), InputStmt(IdentifierNode('N'), None), ForStmt('i', NumberNode(1), IdentifierNode('N'), [AssignStmt(IdentifierNode('DR1'), CallNode(IdentifierNode('alea_ent'), [NumberNode(1), NumberNode(6)])), AssignStmt(IdentifierNode('DR2'), CallNode(IdentifierNode('alea_ent'), [NumberNode(1), NumberNode(6)])), AssignStmt(IdentifierNode('DB'), CallNode(IdentifierNode('alea_ent'), [NumberNode(1), NumberNode(6)])), IfStmt(BinOpNode(CallNode(IdentifierNode('max'), [ListNode([IdentifierNode('DR1'), IdentifierNode('DR2')])]), IdentifierNode('DB'), '>'), [AssignStmt(IdentifierNode('C'), BinOpNode(IdentifierNode('C'), NumberNode(1), '+'))])], None), DisplayStmt(BinOpNode(IdentifierNode('C'), StringNode(' victoires'), '+'), True)])
\ No newline at end of file
BlockStmt([AssignStmt(IdentifierNode('debut'), NumberNode(2009)), AssignStmt(IdentifierNode('initiale'), NumberNode(1500)), AssignStmt(IdentifierNode('taux'), NumberNode(2.25)), InputStmt(IdentifierNode('annee'), None), AssignStmt(IdentifierNode('solde'), BinOpNode(IdentifierNode('initiale'), BinOpNode(BinOpNode(NumberNode(1), BinOpNode(IdentifierNode('taux'), NumberNode(100), '/'), '+'), BinOpNode(IdentifierNode('annee'), IdentifierNode('debut'), '-'), '^'), '*')), DisplayStmt(BinOpNode(BinOpNode(BinOpNode(BinOpNode(StringNode('En '), CallNode(IdentifierNode('str'), [IdentifierNode('annee')]), '+'), StringNode(', le solde sera de '), '+'), CallNode(IdentifierNode('str'), [IdentifierNode('solde')]), '+'), StringNode(' €'), '+'), True)])
\ No newline at end of file
BlockStmt([GWindowStmt(NumberNode(0), NumberNode(1), NumberNode(0), NumberNode(1), NumberNode(1), NumberNode(1)), InputStmt(IdentifierNode('N'), None), AssignStmt(IdentifierNode('compteur'), NumberNode(0)), ForStmt('i', NumberNode(1), IdentifierNode('N'), [AssignStmt(IdentifierNode('x'), CallNode(IdentifierNode('alea'), [])), AssignStmt(IdentifierNode('y'), CallNode(IdentifierNode('alea'), [])), IfStmt(BinOpNode(CallNode(IdentifierNode('hypot'), [IdentifierNode('x'), IdentifierNode('y')]), NumberNode(1), '<='), [GPointStmt(IdentifierNode('x'), IdentifierNode('y'), StringNode('red')), AssignStmt(IdentifierNode('compteur'), BinOpNode(IdentifierNode('compteur'), NumberNode(1), '+'))]), ElseStmt([GPointStmt(IdentifierNode('x'), IdentifierNode('y'), StringNode('blue'))])], None), AssignStmt(IdentifierNode('F'), BinOpNode(IdentifierNode('compteur'), IdentifierNode('N'), '/')), DisplayStmt(BinOpNode(StringNode('La proportion de points rouges est : '), IdentifierNode('F'), '+'), True), DisplayStmt(BinOpNode(StringNode('Pi vaut donc 4 × F soit approximativement '), BinOpNode(NumberNode(4), IdentifierNode('F'), '*'), '+'), True)])
\ No newline at end of file
BlockStmt([InputStmt(IdentifierNode('xa'), None), InputStmt(IdentifierNode('ya'), None), InputStmt(IdentifierNode('xb'), None), InputStmt(IdentifierNode('yb'), None), InputStmt(IdentifierNode('xc'), None), InputStmt(IdentifierNode('yc'), None), AssignStmt(IdentifierNode('m1'), BinOpNode(BinOpNode(IdentifierNode('yb'), IdentifierNode('ya'), '-'), BinOpNode(IdentifierNode('xb'), IdentifierNode('xa'), '-'), '/')), AssignStmt(IdentifierNode('m2'), BinOpNode(BinOpNode(IdentifierNode('yc'), IdentifierNode('ya'), '-'), BinOpNode(IdentifierNode('xc'), IdentifierNode('xa'), '-'), '/')), IfStmt(BinOpNode(IdentifierNode('m1'), IdentifierNode('m2'), '=='), [DisplayStmt(StringNode('Les points A, B et C sont alignés.'), True)]), ElseStmt([DisplayStmt(StringNode('Les droites (AB) et (AC) sont sécantes.'), True)])])
\ No newline at end of file
BlockStmt([InputStmt(IdentifierNode('xa'), None), InputStmt(IdentifierNode('ya'), None), InputStmt(IdentifierNode('xb'), None), InputStmt(IdentifierNode('yb'), None), InputStmt(IdentifierNode('xc'), None), InputStmt(IdentifierNode('yc'), None), AssignStmt(IdentifierNode('c'), BinOpNode(BinOpNode(BinOpNode(IdentifierNode('xb'), IdentifierNode('xa'), '-'), NumberNode(2), '^'), BinOpNode(BinOpNode(IdentifierNode('yb'), IdentifierNode('ya'), '-'), NumberNode(2), '^'), '+')), AssignStmt(IdentifierNode('a'), BinOpNode(BinOpNode(BinOpNode(IdentifierNode('xb'), IdentifierNode('xc'), '-'), NumberNode(2), '^'), BinOpNode(BinOpNode(IdentifierNode('yb'), IdentifierNode('yc'), '-'), NumberNode(2), '^'), '+')), AssignStmt(IdentifierNode('b'), BinOpNode(BinOpNode(BinOpNode(IdentifierNode('xc'), IdentifierNode('xa'), '-'), NumberNode(2), '^'), BinOpNode(BinOpNode(IdentifierNode('yc'), IdentifierNode('ya'), '-'), NumberNode(2), '^'), '+')), IfStmt(BinOpNode(BinOpNode(BinOpNode(IdentifierNode('a'), IdentifierNode('b'), '+'), IdentifierNode('c'), '+'), BinOpNode(NumberNode(2), CallNode(IdentifierNode('max'), [ListNode([IdentifierNode('a'), IdentifierNode('b'), IdentifierNode('c')])]), '*'), '=='), [DisplayStmt(StringNode('oui'), False)]), ElseStmt([DisplayStmt(StringNode('non'), False)])])
\ No newline at end of file
BlockStmt([
FuncStmt("sayHello2", ["name"], [
AssignStmt(parse("text"), parse("\"Hello \" + name")),
FuncStmt("say", [], [
DisplayStmt(parse("text"))
]),
ReturnStmt(parse("say"))
]),
AssignStmt(parse("say2"), parse("sayHello2(\"Bob\")")),
CallStmt(parse("say2"), [])
])
\ No newline at end of file