Share to: share facebook share twitter share wa share telegram print page

Modula-2

Modula-2
编程范型指令式结构化模块化数据和方法隐藏英语information hiding并发
语言家族Wirth Modula
設計者尼克劳斯·维尔特
发行时间1978年,​46年前​(1978
型態系統强,静态
系统平台Lilith英语Lilith (computer)AMD 2901英语AMD Am2900
操作系统跨平台
文件扩展名.mod .m2 .def .MOD .DEF .mi .md
網站www.modula2.org
主要實作產品
Niklaus Wirth編写的ETH编译器, GNU Modula-2, ADW Modula-2
衍生副語言
PIM2、PIM3、PIM4、ISO
啟發語言
Modula, Mesa, Pascal, ALGOL W, Euclid英语Euclid (programming language)
影響語言
Modula-3, Oberon, Ada, Fortran, Lua, Seed7英语Seed7, Zonnon英语Zonnon, Modula-GM

Modula-2,是一种通用的结构化过程式编程语言,由尼克劳斯·维尔特在1978年至1985年间于苏黎世联邦理工学院开发。它具有充分的灵活性用于系统编程,和更加广阔应用领域。特别是,它被设计为以一种直接的方式支持分离编译和数据抽象。它的很多语法基于了维尔特早先的周知语言Pascal

历史

在1976年至1977年年間,维尔特在Xerox Palo Alto研究中心,與一群設計Alto電腦的工作夥伴一同工作。1978年,维尔特在瑞士聯邦理工學院資訊研究所,根據其早期對Pascal程式語言Modula模組程式語言、及Alto電腦的經驗,定義了Modula-2語言,他還開始了一個Lilith英语Lilith (computer)個人電腦計畫。

Modula-2語言本身與Lilith結構之設計,都以優雅及簡單為原則,是以Modula-2為Lilith的系統程式語言,而不需用到組譯器,並且以Lilith為Modula-2的組織架構。為此,Modula-2語言不僅要適用於編寫高階的應用程式,也要應適用於編寫低階的與機器相關的編碼程式,用於裝置的操控與儲存體的配置。

Modula-2提供了一些標準程式庫模組,如異常處置、字串處理、輸入/輸出及並行程式設計等,通過重複使用它們來降低語言本身的複雜度。在Lilith計畫從1978年到1988年的整個生命期中,作業系統、繪圖套裝軟體、資料庫系統、網路協議、檔案伺服器,及許多其他系統和應用模組,都是藉著Modula-2發展出來的。

描述

Modula-2被设计为显著的类似于Pascal,移除了一些元素和语法歧义,增补了“模块”这个重要概念,并且对多道程序有直接的语言支持。维尔特将Modula-2看作他早期的编程语言PascalModula的后继者[1][2]。主要的概念是:

  1. 模块是分离编译的编译单元。
  2. 协程并发处理的基本建造块。
  3. 类型和过程允许访问特定于机器的数据。

Modula-2提供了(有限的)单处理器并发(监视器协程和显式控制转移)和硬件访问(绝对地址、位操纵和中断)。它使用了名称类型系统英语nominal type system。Modula-2语言允许使用一趟编译器英语One-pass compilerGutknecht英语Jürg Gutknecht和维尔特的这种编译器大致上比早前的多趟编译器英语Multi-pass compiler要快上四倍[3]

Modula-2有两种主要方言:PIM和ISO/IEC 10514-1:1996,PIM得名于Niklaus Wirth的著作《Programming in Modula-2》[4],这本书一共有四个版本,成为方言的是PIM2(1983年)、PIM3(1985年)和PIM4(1988年)。

例子代码

下面是"Hello world"程序的Modula-2源代码例子:

MODULE Hello;
  FROM STextIO IMPORT WriteString;
BEGIN
  WriteString("Hello World!");
END Hello.

语言元素

保留字

PIM版本2、3、4定义了40个保留字

AND         ELSIF           LOOP       REPEAT
ARRAY       END             MOD        RETURN
BEGIN       EXIT            MODULE     SET
BY          EXPORT          NOT        THEN
CASE        FOR             OF         TO
CONST       FROM            OR         TYPE
DEFINITION  IF              POINTER    UNTIL
DIV         IMPLEMENTATION  PROCEDURE  VAR
DO          IMPORT          QUALIFIED  WHILE
ELSE        IN              RECORD     WITH

内建标识符

PIM版本3、4定义了29个内建标识符

ABS         EXCL            LONGINT    REAL
BITSET      FALSE           LONGREAL   SIZE
BOOLEAN     FLOAT           MAX        TRUE
CAP         HALT            MIN        TRUNC
CARDINAL    HIGH            NIL        VAL
CHAR        INC             ODD
CHR         INCL            ORD
DEC         INTEGER         PROC

模块

Modula-2的模块(module),可以用来封装一组有关的子程序和数据结构,并限制它们对程序其他部份的可见性。模块设计以清晰的方式,实现了Modula-2的数据抽象特征。语言有严格的作用域控制。模块的作用域,可以被当作是不可逾越的墙:除了标准标识符之外,来自外部的对象在模块内是不可见的,除非显式的导入它;内部的模块对象在外部是不可见的,除非显式的导出它。

Modula-2程序是由模块组成,其中“程序模块”包含一个Modula-2程序的主程序。所有Modula-2程序,必须有定义了执行开始之处的一个主程序。在一个单一的程序中,不能有链接在一起的两个程序模块。“局部模块”是在其他模块内声明的模块。程序模块和局部模块的起始关键字,就是单独的MODULE

定义模块与实现模块

除了程序模块之外的“全局模块”,都构成自两个部份:作为接口部份的“定义模块”,它只包含“导出”(对其他模块可见)的那部份子系统,和同名的“实现模块”,它包含模块内部的工作代码:

DEFINITION MODULE GM;
  ...
  
IMPLEMENTATION MODULE GM;
  ...

定义模块中可以包含不透明类型英语Opaque data type声明,它有如下形式:

TYPE name;

它对应的实际类型,对于这个模块的用户是不可见的。这个类型名字,可以用在定义模块内的其他声明之中。对于在定义模块中声明的任何不透明类型,在对应的实现模块中,必须包含它的完全类型声明。完全类型声明,必须定义一个指针类型。

导出

假定局部模块M1导出对象abcP,可将它们的标识符列举于显式EXPORT导出列表之中:

MODULE M1;
  EXPORT a, b, c, P;
  ...

如果加上了可选的关键字QUALIFIED,它们以一种有限制的方式给导出至外部,必须将导出的这个模块名字用作限定符,并跟随着对象的名字。这里的来自模块M1的对象abcP,在模块M1外部就叫做M1.aM1.bM1.cM1.P

PIM2在定义模块中要求显式的EXPORT子句;PIM3从定义模块中删除了EXPORT子句,因为发现了它是多余的。

导入

假定模块M2包含下列IMPORT声明:

MODULE M2;
  IMPORT M1;
  ...

然后这意味着模块M1导出至它所包围的程序的外部的对象,现在可以用在模块M2内部。它们以一种限定方式来引用,也就是M1.aM1.bM1.cM1.P。例如:

  ...
  M1.a := 0;
  M1.c := M1.P(M1.a + M1.b);
  ...

限定导出避免了名字冲突:例如,如果另一个模块M3也导出了一个对象叫做P,那么我们仍可以区分这两个对象,因为M1.P不同于M3.P。凭借限定导出,两个对象在它们的导出模块M1M3中都叫做P是不碍事的。

存在一种可作为替代的方式,它在Modula-2编程者中广泛采用。假定模块M3是公式化为如下:

MODULE M3;
  FROM M1 IMPORT a, b, c, P;

然后这意味着模块M1导出至外部的对象,可以用在模块M3内部,但可以用无限定方式来引用导出的标识符,也就是abcP。例如:

  ...
  a := 0;
  c := P(a + b);
  ...

这种无限定导入的方法,允许在其导出模块之外,以同在它们的导出模块之内一样简单的方式,来使用这些变量和其他对象。对于所有这些已经被显式允许的对象,包围所有模块的墙变得与它们无关了。当然无限定导入只在没有名字冲突时是可用的。

这些导出和导入规则,看起来可能是没有必要的限制和冗余的。但是它们不只是守卫对象免于不希望的访问,而且还有一个让人愉悦的副作用,提供了在程序中定义的所有标识符的自动交叉引用:如果标识符被一个模块名字所限定,那么它的定义位于那个模块。否则如果它是无限定的出现的,简单的回溯查找,将会要么遇到这个标识符的声明,要么遇到它出现在一个IMPORT语句中,指出了它所来自的模块的名字。这个性质在尝试理解包含很多模块的大型程序时是非常有用的。

參見

引用

  1. ^ Wirth, Niklaus. Pascal and its Successors. Broy, Manfred; Denert, Ernst (编). Software Pioneers: Contributions to Software Engineering. Berlin, Heidelberg: Springer-Verlag. 2002: 108–120. ISBN 978-3-642-59412-0. doi:10.1007/978-3-642-59412-0. 
  2. ^ Wirth, Niklaus. History and Goals of Modula-2. Dr. Dobb's Journal (Informa PLC). 18 February 2005 [2021-06-15]. (原始内容存档于2021-04-10). 
  3. ^ Wirth, Niklaus. A Single-pass Modula-2 Compiler for Lilith (PDF). CFB Software. 1 May 1984 [28 January 2019]. (原始内容 (PDF)存档于2021-01-24). 
  4. ^ Wirth, Niklaus. Programming in Modula-2 4th. Berlin, Heidelberg: Springer. 1988. ISBN 978-3-642-83565-0. doi:10.1007/978-3-642-83565-0.  Page 4.

图书

外部連結

本條目部分或全部内容出自以GFDL授權發佈的《自由線上電腦詞典》(FOLDOC)。

Read more information:

AF-S VR Micro-Nikkor 105mm f/2.8G IF-ED[1]MakerNikon CorporationTechnical dataFocal length105mmAperture (max/min)f/2.8 - f/32Close focus distance31.4 cm / 12.0 in.Max. magnification1:1Diaphragm blades9 (rounded)Construction14 elements in 12 groupsFeaturesShort back focus NoUltrasonic motor YesLens-based stabilization YesMacro capable YesApplicationMacroPhysicalMax. length4.5in / 116mmDiameter3.3in / 83mmWeight790g / 27.9 oz.Filter diameter62 mmAcce…

Glacier in Antarctica Location of Oscar II Coast on Antarctic Peninsula. Pequod Glacier (65°30′S 62°3′W / 65.500°S 62.050°W / -65.500; -62.050) is a glacier over 15 nautical miles (28 km) long, draining eastwards between Parlichev Ridge to the north, and Taridin Ridge and Krupen Ridge to the south, and flowing into Exasperation Inlet on the east coast of Graham Land. It lies parallel and just south of Melville Glacier. The lower part of the glacier was survey…

Санносе (яп. 三之瀬町, さんのせまち, санносе-маті, «Три течії») — колишнє містечко в Японії, в провінції Акі повіту Акі. Розташоване на східному березі острова Сімо-Камаґарі, де східна, західна і південно-західна течії утворюють бурхливу протоку Санносе. Політико-адміністрат…

«Mon amour»Sencillo de Zzoilo y AitanaPublicación 30 de diciembre de 202017 de agosto de 2021 (remix)Formato Descarga digitalGénero(s) Pop rapDuración 2:54 3:02 (remix)Discográfica Universal Music SpainAutor(es) Zoilo TuñónProductor(es) Víctor GalindoCertificación 1× Platino 9× Platino (remix)Posicionamiento en listas N.º 1 en España (remix)Sencillos de Zzoilo «Mon amour» (2020) «Luces, Cámara, Acción» (2021) Cronología de Aitana «Aunque no sea conmigo»(2021) «Mon amour R…

كثرة منسجات البحر الأزرق معلومات عامة الاختصاص علم الدم  تعديل مصدري - تعديل   كثرة منسجات البحر الأزرق أو كثرة المنسجات الزرقاء (بالإنجليزية:Sea-blue histiocytosis) هو مرض جلدي عادة ما يكون متلازمة وراثية ومن الممكن أن يكون كنتيجة لارتشاح ثانوي أو جهازي مكتسب [1] وهو من كثرة…

Klassifikation nach ICD-10 K83.0 Cholangitis, primär sklerosierend ICD-10 online (WHO-Version 2019) Die primär sklerosierende Cholangitis (PSC) ist eine chronische Entzündung der Gallenwege (Cholangitis) innerhalb und/oder außerhalb der Leber. Sie führt zu einer narbigen Verhärtung (Sklerose) und damit verbunden zu einer Verengung der Gallenwege. Inhaltsverzeichnis 1 Krankheitsentstehung 2 Klinische Erscheinungen 3 Untersuchungsmethoden 4 Typische Laborbefunde 5 Histologie 6 Verlauf 7 Ther…

American actress and model (born 1983) This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Melissa Ordway – news · newspapers · books · scholar · JSTOR (September 2009) (Learn how and when to remove th…

Father of Napoleon Bonaparte (1746–1785) Carlo BuonaparteNoble Patrician of TuscanyPortrait attributed to Anton Raphael Mengs, between c. 1766–1779Full nameCarlo Maria BuonaparteBorn27 March 1746Ajaccio, Corsica, Republic of GenoaDied24 February 1785(1785-02-24) (aged 38)Montpellier, Kingdom of FranceBuriedImperial Chapel, Ajaccio, FranceNoble familyBuonaparteSpouse(s) Maria Letizia Ramolino ​ ​(m. 1764)​IssueDetail Joseph, King of Spain Napoleon…

IllusionAlbum mini karya ZE:ADirilis9 Agustus 2013 (2013-08-09)Direkam2013GenreK-pop, dance-popDurasi21:32BahasaKoreaLabelStar Empire EntertainmentKronologi ZE:A Phoenix(2012)Phoenix2012 Illusion(2013) First Homme(2014)First Homme2014 Singel dalam album Illusion The Ghost Of WindDirilis: August 9, 2013 Illusion adalah album mini Korea pertama yang dirilis oleh boy band ZE:A. Album ini dirilis pada tanggal 9 Agustus 2013. Daftar lagu Nomor Judul Lirik Komposer Arranger Durasi 1 Crazy 이…

Pour des articles plus généraux, voir Combiné nordique aux Jeux olympiques et Jeux olympiques d'hiver de 2018. Cet article est une ébauche concernant le combiné nordique. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Combiné nordique aux Jeux olympiques de 2018 Généralités Sport Combiné nordique Organisateur(s) CIO Éditions 23e Lieu(x) Pyeongchang Date du 12 février 2018au 20 février 2018 Épreuves 3 …

Gempa bumi Badghis 2022ShakeMap dibuat oleh USGS untuk gempa bumiWaktu UTC2022-01-17 11:40:08ISC621723883USGS-ANSSComCatTanggal setempat17 Januari, 2022 (17 Januari, 2022)Waktu setempat15:40Kekuatan5.3 MwKedalaman18,8 km (11,7 mi)Episentrum34°56′46″N 63°34′48″E / 34.946°N 63.580°E / 34.946; 63.580Koordinat: 34°56′46″N 63°34′48″E / 34.946°N 63.580°E / 34.946; 63.580Wilayah bencanaAfganistanIntens…

E. Clay Shaw Eugene Clay Shaw (* 19. April 1939 in Miami, Florida; † 10. September 2013[1] in Fort Lauderdale, Florida) war ein US-amerikanischer Jurist und Politiker, der den Bundesstaat Florida im US-Repräsentantenhaus vertrat. Clay Shaw besuchte zunächst die Edison Senior High School in seiner Heimatstadt Miami; danach studierte er an der Stetson University in DeLand und der University of Alabama in Tuscaloosa. Im Anschluss ging er erneut auf die Stetson University, erhielt dort 1…

British actress (born 1977) Lucy PunchPunch in April 2011Born (1977-12-30) 30 December 1977 (age 45)Hammersmith, London, EnglandEducationGodolphin and Latymer SchoolUniversity of LondonNational Youth TheatreOccupationActressYears active1998–presentChildren1 Lucy Punch (born 30 December 1977)[1] is a British actress. She has appeared in the films Ella Enchanted (2004), Hot Fuzz (2007), You Will Meet a Tall Dark Stranger, Dinner for Schmucks, (both 2010) and Into the Woods (201…

Martin BuberLahir8 Februari 1878Wina, Austro-HungariaMeninggal13 Mei 1965EraFilsafat Abad ke-20KawasanFilsafat BaratAliranEksistensialismeMinat utamaOntologiGagasan pentingIch-Du dan Ich-Es; Aku-Itu dan Aku-Engkau Dipengaruhi Immanuel Kant, Søren Kierkegaard, Friedrich Nietzsche, Ludwig Feuerbach, Ralph Waldo Emerson, Pierre-Joseph Proudhon, Sigmund Freud Memengaruhi Abraham Joshua Heschel, Walter Kaufmann, Gabriel Marcel, Franz Rosenzweig, Hans Urs Von Balthasar Martin Buber (Ibrani&…

Class of enzymes Anticodon-binding domain of tRNAleucyl-tRNA synthetase from Thermus thermophilus complexed with a post-transfer editing substrate analogueIdentifiersSymbolAnticodon_2PfamPF08264InterProIPR013155SCOP21ivs / SCOPe / SUPFAMAvailable protein structures:Pfam  structures / ECOD  PDBRCSB PDB; PDBe; PDBjPDBsumstructure summary DALR anticodon binding domain 1Thermus thermophilus arginyl-trna synthetaseIdentifiersSymbolDALR_1PfamPF05746Pfam clanCL0258InterProIPR008909SCOP21bs2 /…

1993 single by Captain Hollywood ProjectOnly With YouSingle by Captain Hollywood Projectfrom the album Love Is Not Sex B-sideRemixReleased20 December 1993GenreEurodanceLength3:52LabelBlow UpSongwriter(s) Oliver Reinecke Giora Schein Nosie Katzmann Tony Dawson Harrison Dietmar Stehle Producer(s)CyborgCaptain Hollywood Project singles chronology More and More (1992) Only With You (1993) All I Want (1993) Music videoOnly with You on YouTube Only With You is a song recorded by German musician known …

Artikel ini membutuhkan rujukan tambahan agar kualitasnya dapat dipastikan. Mohon bantu kami mengembangkan artikel ini dengan cara menambahkan rujukan ke sumber tepercaya. Pernyataan tak bersumber bisa saja dipertentangkan dan dihapus.Cari sumber: Aon Indonesia – berita · surat kabar · buku · cendekiawan · JSTOR (Desember 2013) PT AON IndonesiaJenisJasa keuangan/publikDidirikanJakarta, Indonesia (1992)Kantorpusat Jakarta, IndonesiaTokohkunciJonkheer Alexa…

Edward Cornelis William NeloeDirektur Utama Bank Mandiri ke-3Masa jabatanMei 2000 – Mei 2005PresidenAbdurrahman WahidMegawati SoekarnoputriSusilo Bambang YudhoyonoPendahuluRobby DjohanPenggantiAgus Martowardojo Informasi pribadiLahir(1944-11-07)7 November 1944Makassar, Sulawesi SelatanMeninggal5 Mei 2015(2015-05-05) (umur 70)JakartaKebangsaanIndonesiaProfesiBankir, EkonomSunting kotak info • L • B Edward Cornelis William Neloe (7 November 1944 – …

This article uses bare URLs, which are uninformative and vulnerable to link rot. Please consider converting them to full citations to ensure the article remains verifiable and maintains a consistent citation style. Several templates and tools are available to assist in formatting, such as reFill (documentation) and Citation bot (documentation). (September 2022) (Learn how and when to remove this template message) Central pattern generators (CPGs) are self-organizing biological neural circuits …

Dungeons & Dragons adventure module Descent into the Depths of the EarthThe cover of the 1981 Descent into the Depths of the Earth compilation module, with art by Jim Roslof. The artwork depicts a party of adventurers fighting a band of kuo-toa.CodeD1–2, D3TSR product code9059, 9021Rules requiredAdvanced Dungeons & Dragons 1st editionCharacter levels9–14,[1] 10–14Campaign settingGreyhawkAuthorsGary GygaxFirst published1978Linked modulesG1 G2 G3 D1 D2 D3 Q1 Desce…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 35.173.233.176