Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ALGOL 68
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Program representation== A feature of ALGOL 68, inherited from the [[ALGOL]] tradition, is its different representations. Programs in the ''strict language'' (which is rigorously defined in the Report) denote production trees in the form of a sequence of grammar symbols, and should be represented using some ''representation language'', of which there are many and tailored to different purposes. * Representation languages that are intended to describe algorithms in printed works are known as ''publication languages'' and typically make use of rich typography to denote bold words and operator indications. * Representation languages that are intended to be used in compiler input, what we would call ''programming languages'', are limited by the restrictions imposed by input methods and character sets and have to resort to ''stropping regimes'' to distinguish between bold and non bold letters and digits. * Representation languages that are intended to be both produced and consumed by computers, known as ''hardware languages'', would typically use a binary compact representation. The Revised Report defines a ''reference language'' and it is recommended for representation languages that are intended to be read by humans to be close enough to the reference language so symbols can be distinguished "without further elucidation". These representation languages are called ''implementations of the reference language''. For example, the construct in the strict language '''bold-begin-symbol''' could be represented as '''begin''' in a publication language, as {{var|BEGIN}} in a programming language or as the bytes 0xC000 in some hardware language. Similarly, the strict language '''differs from symbol''' could be represented as ≠ or as /=. ALGOL 68's reserved words are effectively in a different [[namespace]] from identifiers, and spaces are allowed in identifiers in most stropping regimes, so this next fragment is legal: '''INT''' a real int = 3 ; The programmer who writes executable code does not always have an option of '''BOLD''' typeface or <u>underlining</u> in the code as this may depend on hardware and cultural issues. Different methods to denote these identifiers have been devised. This is called a ''[[Stropping (programming)|stropping]] regime''. For example, all or some of the following may be available ''programming representations'': 'INT'A REAL INT = 3; # QUOTE stropping style # .INT A REAL INT = 3; # POINT stropping style # INT a real int = 3; # UPPER stropping style # int a_real_int = 3; # RES stropping style, there are 61 accepted reserved words # All implementations must recognize at least POINT, UPPER and RES inside PRAGMAT sections. Of these, POINT and UPPER stropping are quite common. QUOTE (single apostrophe quoting) was the original recommendation{{citation needed|date=May 2025}}. It may seem that RES stropping is a contradiction to the specification, as there are no reserved words in Algol 68. This is not so. In RES stropping the representation of the bold word (or keyword) '''begin''' is {{var|begin}}, and the representation of the identifier ''begin'' is {{var|begin_}}. Note that the underscore character is just a representation artifact and not part of the represented identifier. In contrast, in non-stropped languages with reserved words, like for example C, it is not possible to represent an identifier {{var|if}}, since the representation {{var|if_}} represents the identifier {{var|if_}}, not {{var|if}}. The following characters were recommended for portability, and termed "worthy characters" in the [http://algol68-lang.org/docs/standard-hardware-representation.pdf Report on the Standard Hardware Representation of Algol 68] : * {{note|worthy}}Worthy Characters: ABCDEFGHIJKLM<wbr>NOPQRSTUVWXYZ<wbr>0123456789 "#$%'()*+,-./:;<=>@[ ]_| This reflected a problem in the 1960s where some hardware didn't support lower-case, nor some other non-[[ASCII]] characters, indeed in the 1973 report it was written: "Four worthy characters — "|", "_", "[", and "]" — are often coded differently, even at installations which nominally use the same character set." * Base characters: "Worthy characters" are a subset of "base characters". ===Example of different program representations=== {| class="wikitable plainrowheaders" |- ! scope="col" | Representation ! scope="col" | Code |- ! scope="row" | Algol68 as typically published | {{pre|1= ''¢ underline or '' ''bold typeface ¢'' '''mode''' '''xint''' = '''int'''; '''xint''' sum sq:=0; '''for''' i '''while''' sum sq≠70×70 '''do''' sum sq+:=i↑2 '''od''' }} |- ! scope="row" | Quote stropping<br />(like [[Lightweight markup language#Text/font-face formatting|wikitext]]) | {{sxhl|2=text|1= 'pr' quote 'pr' 'mode' 'xint' = 'int'; 'xint' sum sq:=0; 'for' i 'while' sum sq≠70×70 'do' sum sq+:=i↑2 'od' }} |- ! scope="row" | For a [[List of binary codes#Seven-bit binary codes|7-bit]] character code compiler | {{sxhl|2=man|1= PR UPPER PR MODE XINT = INT; XINT sum sq:=0; FOR i WHILE sum sq/=70*70 DO sum sq+:=i**2 OD }} |- ! scope="row" | For a [[Six-bit character code|6-bit]] character code compiler | {{sxhl|2=man|1= .PR POINT .PR .MODE .XINT = .INT; .XINT SUM SQ:=0; .FOR I .WHILE SUM SQ .NE 70*70 .DO SUM SQ .PLUSAB I .UP 2 .OD }} |- ! scope="row" | Algol68 using '''RES''' stropping<br />(reserved word) | {{sxhl|2=man|1= .PR RES .PR mode .xint = int; .xint sum sq:=0; for i while sum sq≠70×70 do sum sq+:=i↑2 od }} |} ALGOL 68 allows for every natural language to define its own set of keywords Algol-68. As a result, programmers are able to write programs using keywords from their native language. Below is an example of a simple procedure that calculates "the day following", the code is in two languages: English and German.{{Citation needed|date=August 2011}} # Next day date - English variant # '''MODE''' '''DATE''' = '''STRUCT'''('''INT''' day, '''STRING''' month, '''INT''' year); '''PROC''' the day following = ('''DATE''' x) '''DATE''': '''IF''' day '''OF''' x < length of month (month '''OF''' x, year '''OF''' x) '''THEN''' (day '''OF''' x + 1, month '''OF''' x, year '''OF''' x) '''ELIF''' month '''OF''' x = "December" '''THEN''' (1, "January", year '''OF''' x + 1) '''ELSE''' (1, successor of month (month '''OF''' x), year '''OF''' x) '''FI'''; # Nachfolgetag - Deutsche Variante # '''MENGE''' '''DATUM''' = '''TUPEL'''('''GANZ''' tag, '''WORT''' monat, '''GANZ''' jahr); '''FUNKTION''' naechster tag nach = ('''DATUM''' x) '''DATUM''': '''WENN''' tag '''VON''' x < monatslaenge(monat '''VON''' x, jahr '''VON''' x) '''DANN''' (tag '''VON''' x + 1, monat '''VON''' x, jahr '''VON''' x) '''WENNABER''' monat '''VON''' x = "Dezember" '''DANN''' (1, "Januar", jahr '''VON''' x + 1) '''ANSONSTEN''' (1, nachfolgemonat(monat '''VON''' x), jahr '''VON''' x) '''ENDEWENN'''; ''Russian/Soviet example:'' In English Algol68's case statement reads '''CASE''' ~ '''IN''' ~ '''OUT''' ~ '''ESAC''', in [[Cyrillic]] this reads '''выб''' ~ '''в''' ~ '''либо''' ~ '''быв'''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)