From Test-Scratch-Wiki

DocumentInQuestion.png This page is in question to whether it is useful or not. You can discuss whether you want it deleted or not on its talk page.
Reason: Not relevant to scratch
SandCastleIcon.png This page has links to outside of the Scratch website or Wikipedia. Remember to stay safe when using the internet as we can't guarantee the safety of other sites.
This zho is about programming languages in general. For the type of project that simulates a programming language, see Programming Language (Project Type).

A programming language is a set of rules and functions that let people use computers, cell phones, tablets, and more devices. Programming languages are designed to make it easy for humans to write complex instructions. They function a lot like human languages: they have explicit grammars and a primitive vocabulary. Scratch is a programming language.


A programming language is a language for writing instructions for a machine. A programming language is defined by a grammar. Programming languages must be Turing-complete.

Many programming paradigms exist which focus on different design aspects. Imperative languages focus on commands and how to accomplish tasks, declerative languages dictate the rules and conditions of a task and do not specify the process of completing it, and functional languages emphasize functions which do not change state, and are guaranteed to always produce the same output for an input.

Languages usually have various primitive data types which can be expanded with Object-Oriented Programming:

  • Numbers, which are parsed as numbers
    • Some languages consider integers, floating-point numbers, and doubles to be different data types.
  • 字串, which are parsed as text
  • 阵列, which are lists of elements
  • Objects, which are dictionaries of key-value pairs.
  • 函式, which are pieces of code which can be executed with 参数.

In essence, a programming language just provides a framework where a function can be executed with arguments —the rest can be worked around. Usually, the grammar of a language consists of "statements", which are either:

  • Assignments: binding some value to a name (变量)
  • Procedure calls
  • Special forms: certain specialized procedures which cannot be created using the language itself, for example, IF/ELSE. The inputs to special forms are not immediately evaluated.

The syntax of a programming language gives rules about how to do each of the above. For example:

  • Assignments:
    • Squeak: var _ val
    • JavaScript: var = val
    • Scheme: (SET! var val)
  • Procedure calls
    • Squeak: obj proc: arg
    • JavaScript: proc(arg);
    • Scheme: (proc arg)
  • Special forms (if, in this case)
    • Squeak: bool ifTrue: [something] ifFalse: [something].
    • JavaScript: if (bool) {something;} else {something;}
    • Scheme: (if bool something something)

Scratch simplifies programming a lot by hiding all of this in blocks: all blocks are equal, there are no special forms. Of course, in reality, certain blocks are programmed completely differently as special cases. For example, the IF block needs special programming to execute the C block contents, and the WAIT UNTIL block needs special programming to escape the atomic loop. Assignment is just another block. The REPEAT UNTIL special form block repeatedly evaluates its Boolean input, then its block, input, until the former input evaluates to true. This contrasts with custom blocks, whose inputs are evaluated prior to their execution.


Caution.png This article or section is currently undergoing major changes by Chibi-Matoran (talk | contribs). Please avoid largely modifying this page's contents until this template has been removed.

Programming languages are generally either interpreted or compiled, which means they are either executed directly, or translated into another language. For example, C is compiled while Python and JavaScript are interpreted. Java is compiled into bytecode, which is interpreted by the Java Virtual Machine.

Note Note: Java and JavaScript are two completely different programming languages with no relation whatsoever in grammar, semantics, creation, or uses.

Language implementations usually consist of the following parts:

  • A lexer: This converts the program into tokens.
  • A parser: This analyzes the tokens as per the context-free grammar of the language, then converts them into a data structure (阵列 or Object) that can easily be interpreted.
  • A code optimizer: This improves the program.
  • An interpreter or compiler: This "understands" the data structure and interprets it.

The lexer accepts the program as an input and tokenizes it. The programming language may have regular expressions which define tokens. The lexer's output has two parts: the lexemes, which are the different components of the program, and the tokens, which are the type of grammatical structure that the lexemes are.

The parser analyzes the tokens and lexemes produced by the lexer program and creates an abstract syntax tree (AST). The parser utilizes a context-free grammar, a set of rules which defines the nonterminals (grammatical structures consisting of tokens and nonterminals). Algorithms such as LALR or Earley may be used.

Parsing algorithms are classified into top-bottom parsing, which starts with the root node and constructs the tree to the leaves, and bottom-up parsing, which start with the tokens and work up to the root node. Bottom-up parsing consists of shifts, where the next token may be pushed onto the parse stack, and reduction, where items on the stack are found to match a production, and replaced with it.[1] Lookahead tokens are used when whether to shift or reduce is undecided.[2]

Scratch as a Programming Language

Caution.png This article or section is currently undergoing major changes by Chibi-Matoran (talk | contribs). Please avoid largely modifying this page's contents until this template has been removed.

Scratch is a block-based imperative, event-driven, dynamically-typed and interpreted programming language.


Scratch is dynamically-typed, meaning that whether data types agree is checked during program execution.[3] Scratch's primitive data types are numbers, strings and Booleans.

Special Forms

Scratch's special forms are blocks which cannot be replicated using custom blocks. These blocks may reevaluate their inputs. For example, the repeat-until loop reevaluates its Boolean input before each iteration to see if the condition's value has changed.[4]

Programming languages relevant to Scratch


Main article: Smalltalk

Squeak was used to program the 1.x series of Scratch. It is a simple language designed to be human-readable and concise. See Squeak 教程 for a simple introduction.


Adobe Flash is a programming suite by Adobe, which was used to create Scratch 2.0. Flash programming is done in ActionScript, a language based on ECMAScript.


Main article: Python

Python is a simple interpreted scripting language that is used in the Scratch 2.0 back-end (server-side code). The Django coding platform is used on a nginx server.[5] The forums run on DjangoBB, a Python library. Python is also used in many Scratch add-ons, including Kurt.


PHP is a programming language which was used in the Scratch 网站的 server-side code (ScratchR). It stands for PHP: Hypertext Preprocessor.


SQL (Structured Query Language) is a database query language. This is used to store backend information on the website, such as users and forum data.


Mongo is a database system that is used to store 云端变量.


Java is a powerful, object oriented programming language. Java was used to write the original Java 播放器 for Scratch.


JavaScript (commonly shortened to JS) is a simple programming language based on ECMAScript for web development. Snap! is written entirely in JavaScript, and the Scratch website uses JavaScript for interactive elements. These include 注释, 加上标签, and editing 专案备注. In the 2.0 site, it is also used to automatically check for new 讯息, load 发生什么事? and Scratch 新闻, and quote posts in the Scratch 论坛.

Markup Languages


HTML is a web-based markup language. It is used for the layout the Scratch website and to create the HTML5 播放器.

Cascading Style Sheets

Cascading Style Sheets (commonly shortened to CSS) are a method of styling HTML documents. It is used to add color and make the site more visually appealing.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.