A Macro Is a Series of Instructions That Can Be Grouped Together as a Single Command.ã¢â‚¬â€¹

In computer science, a curtailed representation of a pattern

A macro (short for "macro instruction", from Greek combining grade μακρο- "long, large"[1]) in computer science is a rule or pattern that specifies how a sure input should be mapped to a replacement output. Applying a macro to an input is macro expansion. The input and output may be a sequence of lexical tokens or characters, or a syntax tree. Character macros are supported in software applications to make information technology piece of cake to invoke common command sequences. Token and tree macros are supported in some programming languages to enable lawmaking reuse or to extend the linguistic communication, sometimes for domain-specific languages.

Macros are used to make a sequence of calculating instructions available to the programmer as a single programme argument, making the programming task less deadening and less error-prone.[2] [3] (Thus, they are called "macros" considering a "big" block of code tin can exist expanded from a "small" sequence of characters.) Macros ofttimes allow positional or keyword parameters that dictate what the conditional assembler program generates and have been used to create unabridged programs or program suites according to such variables every bit operating organisation, platform or other factors. The term derives from "macro teaching", and such expansions were originally used in generating assembly language code.

Keyboard and mouse macros [edit]

Keyboard macros and mouse macros let short sequences of keystrokes and mouse actions to transform into other, usually more time-consuming, sequences of keystrokes and mouse actions. In this way, often used or repetitive sequences of keystrokes and mouse movements can be automated. Divide programs for creating these macros are called macro recorders.

During the 1980s, macro programs – originally SmartKey, and so SuperKey, KeyWorks, Prokey – were very popular, starting time equally a means to automatically format screenplays, then for a variety of user input tasks. These programs were based on the TSR (cease and stay resident) mode of functioning and applied to all keyboard input, no matter in which context information technology occurred. They have to some extent fallen into obsolescence following the advent of mouse-driven user interfaces and the availability of keyboard and mouse macros in applications such as word processors and spreadsheets, making it possible to create application-sensitive keyboard macros.

Keyboard macros tin be used in massively multiplayer online role-playing games (MMORPGs) to perform repetitive, but lucrative tasks, thus accumulating resource. Equally this is washed without homo attempt, it can skew the economic system of the game. For this reason, utilise of macros is a violation of the TOS or EULA of most MMORPGs, and their administrators spend considerable try to suppress them.[iv]

Application macros and scripting [edit]

Keyboard and mouse macros that are created using an application's built-in macro features are sometimes called application macros. They are created by carrying out the sequence once and letting the application tape the actions. An underlying macro programming linguistic communication, most commonly a scripting language, with straight access to the features of the application may also exist.

The programmers' text editor, Emacs, (short for "editing macros") follows this thought to a determination. In effect, most of the editor is made of macros. Emacs was originally devised every bit a prepare of macros in the editing language TECO; it was afterwards ported to dialects of Lisp.

Another programmers' text editor, Vim (a descendant of vi), besides has an implementation of keyboard macros. It tin can record into a register (macro) what a person types on the keyboard and it can be replayed or edited simply similar VBA macros for Microsoft Office. Vim also has a scripting language called Vimscript[v] to create macros.

Visual Basic for Applications (VBA) is a programming language included in Microsoft Role from Office 97 through Office 2022 (although information technology was available in some components of Function prior to Role 97). However, its office has evolved from and replaced the macro languages that were originally included in some of these applications.

XEDIT, running on the Conversational Monitor Arrangement (CMS) component of VM, supports macros written in EXEC, EXEC2 and REXX, and some CMS commands were really wrappers around XEDIT macros. The Hessling Editor (THE), a fractional clone of XEDIT, supports Rexx macros using Regina and Open Object REXX (oorexx). Many common applications, and some on PCs, utilise Rexx as a scripting language.

Macro virus [edit]

VBA has admission to most Microsoft Windows system calls and executes when documents are opened. This makes it relatively easy to write reckoner viruses in VBA, commonly known as macro viruses. In the mid-to-late 1990s, this became one of the about common types of figurer virus. Even so, during the tardily 1990s and to engagement, Microsoft has been patching and updating their programs. In add-on, current anti-virus programs immediately counteract such attacks.

Parameterized macro [edit]

A parameterized macro is a macro that is able to insert given objects into its expansion. This gives the macro some of the power of a function.

As a uncomplicated instance, in the C programming language, this is a typical macro that is not a parameterized macro:

          #ascertain          PI   iii.14159        

This causes PI to always be replaced with three.14159 wherever information technology occurs. An case of a parameterized macro, on the other hand, is this:

          #ascertain          pred(x)  ((x)-i)        

What this macro expands to depends on what argument ten is passed to it. Here are some possible expansions:

          pred(ii)    →  ((ii)   -ane)  pred(y+2)  →  ((y+2) -1)  pred(f(5)) →  ((f(5))-i)        

Parameterized macros are a useful source-level machinery for performing in-line expansion, but in languages such every bit C where they employ simple textual substitution, they have a number of severe disadvantages over other mechanisms for performing in-line expansion, such as inline functions.

The parameterized macros used in languages such every bit Lisp, PL/I and Scheme, on the other mitt, are much more powerful, able to brand decisions almost what code to produce based on their arguments; thus, they can finer be used to perform run-time code generation.

Text-substitution macros [edit]

Languages such equally C and some assembly languages have rudimentary macro systems, implemented equally preprocessors to the compiler or assembler. C preprocessor macros work by unproblematic textual substitution at the token, rather than the character level. However, the macro facilities of more than sophisticated assemblers, e.g., IBM High Level Assembler (HLASM) can't exist implemented with a preprocessor; the code for assembling instructions and information is interspersed with the lawmaking for assembling macro invocations.

A classic utilise of macros is in the computer typesetting system TeX and its derivatives, where almost of the functionality is based on macros.

MacroML is an experimental system that seeks to reconcile static typing and macro systems. Nemerle has typed syntax macros, and one productive mode to call up of these syntax macros is as a multi-stage computation.

Other examples:

  • m4 is a sophisticated stand-alone macro processor.
  • TRAC
  • Macro Extension TAL, accompanying Template Attribute Language
  • SMX: for web pages
  • ML/1 (Macro Linguistic communication One)
  • The General Purpose Macroprocessor is a contextual pattern matching macro processor, which could exist described as a combination of regular expressions, EBNF and AWK[ commendation needed ]
  • SAM76
  • troff and nroff: for typesetting and formatting Unix manpages.
  • CMS EXEC: for command-line macros and application macros
  • EXEC 2 in Conversational Monitor System (CMS): for command-line macros and awarding macros
  • CLIST in IBM's Fourth dimension Sharing Option (TSO): for command-line macros and application macros
  • REXX: for control-line macros and awarding macros in, e.g., AmigaOS, CMS, OS/2, TSO
  • SCRIPT: for formatting documents
  • Various shells for, due east.g., Linux

Some major applications accept been written every bit text macro invoked by other applications, e.g., by XEDIT in CMS.

Embeddable languages [edit]

Some languages, such as PHP, can exist embedded in free-format text, or the source code of other languages. The mechanism by which the code fragments are recognised (for case, being bracketed past <?php and ?>) is like to a textual macro linguistic communication, merely they are much more powerful, fully featured languages.

Procedural macros [edit]

Macros in the PL/I language are written in a subset of PL/I itself: the compiler executes "preprocessor statements" at compilation time, and the output of this execution forms function of the code that is compiled. The power to utilise a familiar procedural language as the macro language gives power much greater than that of text substitution macros, at the expense of a larger and slower compiler.

Frame engineering science's frame macros take their ain command syntax only tin can also incorporate text in any language. Each frame is both a generic component in a bureaucracy of nested subassemblies, and a procedure for integrating itself with its subassembly frames (a recursive procedure that resolves integration conflicts in favor of higher level subassemblies). The outputs are custom documents, typically compilable source modules. Frame technology tin avoid the proliferation of like but subtly different components, an result that has plagued software development since the invention of macros and subroutines.

Most associates languages have less powerful procedural macro facilities, for example assuasive a cake of lawmaking to be repeated Due north times for loop unrolling; simply these have a completely dissimilar syntax from the actual assembly language.

Syntactic macros [edit]

Macro systems—such as the C preprocessor described earlier—that work at the level of lexical tokens cannot preserve the lexical construction reliably. Syntactic macro systems work instead at the level of abstract syntax trees, and preserve the lexical construction of the original programme. The about widely used implementations of syntactic macro systems are plant in Lisp-like languages. These languages are especially suited for this style of macro due to their uniform, parenthesized syntax (known equally Due south-expressions). In particular, uniform syntax makes information technology easier to determine the invocations of macros. Lisp macros transform the programme structure itself, with the full language available to express such transformations. While syntactic macros are often constitute in Lisp-like languages, they are also available in other languages such as Prolog,[6] Erlang,[7] Dylan,[eight] Scala,[9] Nemerle,[10] Rust,[eleven] Elixir,[12] Nim,[13] Haxe,[14] and Julia.[15] They are too available as third-party extensions to JavaScript,[sixteen] C#[17] and Python.[18]

Early on Lisp macros [edit]

Earlier Lisp had macros, it had and so-called FEXPRs, function-like operators whose inputs were non the values computed past the arguments but rather the syntactic forms of the arguments, and whose output were values to be used in the computation. In other words, FEXPRs were implemented at the same level as EVAL, and provided a window into the meta-evaluation layer. This was generally institute to exist a difficult model to reason about effectively.[xix]

In 1963, Timothy Hart proposed calculation macros to Lisp i.5 in AI Memo 57: MACRO Definitions for LISP.[twenty]

Anaphoric macros [edit]

An anaphoric macro is a type of programming macro that deliberately captures some form supplied to the macro which may be referred to by an anaphor (an expression referring to another). Anaphoric macros first appeared in Paul Graham's On Lisp and their name is a reference to linguistic anaphora—the utilise of words every bit a substitute for preceding words.

Hygienic macros [edit]

In the mid-eighties, a number of papers[21] [22] introduced the notion of hygienic macro expansion (syntax-rules), a pattern-based organisation where the syntactic environments of the macro definition and the macro employ are distinct, allowing macro definers and users not to worry about inadvertent variable capture (cf. referential transparency). Hygienic macros have been standardized for Scheme in the R5RS, R6RS, and R7RS standards. A number of competing implementations of hygienic macros exist such equally syntax-rules, syntax-instance, explicit renaming, and syntactic closures. Both syntax-rules and syntax-case take been standardized in the Scheme standards.

Recently, Racket has combined the notions of hygienic macros with a "tower of evaluators", so that the syntactic expansion time of one macro system is the ordinary runtime of another block of lawmaking,[23] and showed how to apply interleaved expansion and parsing in a not-parenthesized language.[24]

A number of languages other than Scheme either implement aseptic macros or implement partially hygienic systems. Examples include Scala, Rust, Elixir, Julia, Dylan, Nim, and Nemerle.

Applications [edit]

Evaluation society
Macro systems have a range of uses. Being able to choose the guild of evaluation (see lazy evaluation and non-strict functions) enables the creation of new syntactic constructs (due east.g. control structures) indistinguishable from those built into the linguistic communication. For instance, in a Lisp dialect that has cond just lacks if, it is possible to define the latter in terms of the former using macros. For case, Scheme has both continuations and hygienic macros, which enables a programmer to blueprint their own control abstractions, such as looping and early on exit constructs, without the need to build them into the language.
Information sub-languages and domain-specific languages
Next, macros arrive possible to define data languages that are immediately compiled into code, which means that constructs such every bit state machines can be implemented in a way that is both natural and efficient.[25]
Bounden constructs
Macros tin can likewise be used to introduce new binding constructs. The most well-known example is the transformation of let into the awarding of a function to a set of arguments.

Felleisen conjectures[26] that these three categories make upward the chief legitimate uses of macros in such a system. Others have proposed culling uses of macros, such as anaphoric macros in macro systems that are unhygienic or allow selective unhygienic transformation.

The interaction of macros and other linguistic communication features has been a productive expanse of research. For case, components and modules are useful for large-scale programming, merely the interaction of macros and these other constructs must exist defined for their apply together. Module and component-systems that can interact with macros have been proposed for Scheme and other languages with macros. For example, the Noise language extends the notion of a macro system to a syntactic tower, where macros can be written in languages including macros, using hygiene to ensure that syntactic layers are distinct and allowing modules to consign macros to other modules.

Macros for machine-independent software [edit]

Macros are normally used to map a short string (macro invocation) to a longer sequence of instructions. Another, less common, utilise of macros is to exercise the reverse: to map a sequence of instructions to a macro string. This was the approach taken past the STAGE2 Mobile Programming System, which used a rudimentary macro compiler (called SIMCMP) to map the specific instruction set of a given computer into machine-contained macros. Applications (notably compilers) written in these auto-independent macros tin then be run without change on whatsoever computer equipped with the rudimentary macro compiler. The first application run in such a context is a more sophisticated and powerful macro compiler, written in the auto-independent macro linguistic communication. This macro compiler is applied to itself, in a bootstrap mode, to produce a compiled and much more efficient version of itself. The advantage of this arroyo is that complex applications can be ported from 1 figurer to a very dissimilar computer with very trivial try (for each target motorcar architecture, merely the writing of the rudimentary macro compiler).[27] [28] The appearance of mod programming languages, notably C, for which compilers are available on virtually all computers, has rendered such an approach superfluous. This was, however, one of the first instances (if not the first) of compiler bootstrapping.

Assembly language [edit]

While macro instructions can be defined by a programmer for any set of native assembler program instructions, typically macros are associated with macro libraries delivered with the operating system allowing access to operating arrangement functions such as

  • peripheral access by access methods (including macros such as OPEN, CLOSE, READ and WRITE)
  • operating organisation functions such as Adhere, WAIT and Postal service for subtask cosmos and synchronization.[29] Typically such macros expand into executable code, e.g., for the EXIT macroinstruction,
  • a list of ascertain constant instructions, e.one thousand., for the DCB macro—DTF (Ascertain The File) for DOS[thirty]—or a combination of lawmaking and constants, with the details of the expansion depending on the parameters of the macro instruction (such as a reference to a file and a data area for a READ teaching);
  • the executable lawmaking often terminated in either a co-operative and link register didactics to phone call a routine, or a supervisor call instruction to call an operating organisation role straight.
  • Generating a Phase 2 job stream for arrangement generation in, e.chiliad., Bone/360. Unlike typical macros, sysgen stage ane macros do not generate data or code to be loaded into storage, but rather utilize the PUNCH argument to output JCL and associated data.

In older operating systems such as those used on IBM mainframes, total operating system functionality was but bachelor to assembler language programs, not to high level linguistic communication programs (unless assembly language subroutines were used, of grade), as the standard macro instructions did non always have counterparts in routines available to loftier-level languages.

History [edit]

In the mid-1950s, when associates language programming was commonly used to write programs for digital computers, the use of macro instructions was initiated for two main purposes: to reduce the corporeality of program coding that had to be written past generating several assembly language statements from one macro didactics and to enforce program writing standards, eastward.chiliad. specifying input/output commands in standard ways.[31] Macro instructions were effectively a eye step between associates language programming and the high-level programming languages that followed, such every bit FORTRAN and COBOL. Two of the primeval programming installations to develop "macro languages" for the IBM 705 reckoner were at Dow Chemical Corp. in Delaware and the Air Material Command, Ballistics Missile Logistics Office in California. A macro didactics written in the format of the target associates language would be processed by a macro compiler, which was a pre-processor to the assembler, to generate one or more assembly language instructions to exist processed next past the assembler program that would interpret the assembly language instructions into motorcar language instructions.[32]

By the belatedly 1950s the macro language was followed by the Macro Assemblers. This was a combination of both where one plan served both functions, that of a macro pre-processor and an assembler in the same package.[32] [ failed verification ]

In 1959, Douglas East. Eastwood and Douglas McIlroy of Bell Labs introduced conditional and recursive macros into the popular SAP assembler,[33] creating what is known as Macro SAP.[34] McIlroy's 1960 paper was seminal in the area of extending any (including high-level) programming languages through macro processors.[35] [33]

Macro Assemblers allowed assembly language programmers to implement their own macro-language and allowed limited portability of code betwixt 2 machines running the same CPU but different operating systems, for example, early versions of MSDOS and CPM-86. The macro library would need to be written for each target machine but not the overall assembly linguistic communication program. Note that more powerful macro assemblers allowed use of provisional associates constructs in macro instructions that could generate unlike code on different machines or different operating systems, reducing the need for multiple libraries.[ commendation needed ]

In the 1980s and early on 1990s, desktop PCs were simply running at a few MHz and assembly language routines were commonly used to speed upward programs written in C, Fortran, Pascal and others. These languages, at the time, used unlike calling conventions. Macros could be used to interface routines written in assembly linguistic communication to the front end of applications written in almost whatsoever language. Again, the basic associates language code remained the same, only the macro libraries needed to exist written for each target linguistic communication.[ citation needed ]

In modern operating systems such as Unix and its derivatives, operating system access is provided through subroutines, usually provided by dynamic libraries. Loftier-level languages such every bit C offering comprehensive access to operating organization functions, obviating the need for assembler language programs for such functionality.[ citation needed ]

Come across also [edit]

  • Anaphoric macros
  • Assembly linguistic communication § Macros (the origin of the concept of macros)
  • Extensible programming
  • Aseptic macros
  • Programming past demonstration – Technique for teaching a figurer or a robot new behaviors
  • String interpolation – Replacing placeholders in a string with values
  • Computer science and engineering
  • Computer science

References [edit]

  1. ^ Oxford English language Dictionary, s.v. macro, macro-didactics, and macro-
  2. ^ Greenwald, Irwin D.; Maureen Kane (April 1959). "The Share 709 System: Programming and Modification". Journal of the ACM. New York, NY, U.s.a.: ACM. 6 (2): 128–133. doi:10.1145/320964.320967. S2CID 27424222. One of the important uses of developer macros is to save fourth dimension and clerical-type errors in writing sequence of instructions which are often repeated in the class of a program.
  3. ^ Strachey, Christopher (Oct 1965). "A General Purpose Macrogenerator". Reckoner Periodical. 8 (iii): 225–241. doi:10.1093/comjnl/viii.3.225.
  4. ^ "Runescape: The Massive Online Adventure Game by Jagex Ltd". Retrieved 2008-04-03 .
  5. ^ "scripts : vim online". world wide web.vim.org.
  6. ^ "Prolog Macros". world wide web.metalevel.at . Retrieved 2021-04-05 .
  7. ^ "Erlang -- Preprocessor". erlang.org . Retrieved 2021-05-24 .
  8. ^ "The Dylan Macro System — Open up Dylan". opendylan.org . Retrieved 2021-04-05 .
  9. ^ "Def Macros". Scala Documentation . Retrieved 2021-04-05 .
  10. ^ "About - Nemerle programming language official site". nemerle.org . Retrieved 2021-04-05 .
  11. ^ "Macros - The Rust Programming Language". doc.rust-lang.org . Retrieved 2021-04-05 .
  12. ^ "Macros". elixir-lang.github.com . Retrieved 2021-04-05 .
  13. ^ "macros". nim-lang.org . Retrieved 2021-04-05 .
  14. ^ "Macros". Haxe - The Cross-platform Toolkit.
  15. ^ "Metaprogramming · The Julia Linguistic communication". docs.julialang.org . Retrieved 2021-04-05 .
  16. ^ "Sweet.js - Aseptic Macros for JavaScript". www.sweetjs.org.
  17. ^ "LeMP Dwelling Folio · Enhanced C#". ecsharp.net.
  18. ^ "Macros in Python: quasiquotes, instance classes, LINQ and more than!: lihaoyi/macropy". 7 Feb 2022 – via GitHub.
  19. ^ Marshall, Joe. "untitled email". Retrieved May 3, 2012.
  20. ^ Hart, Timothy P. (October 1963). "AIM-057, MACRO Definitions for LISP, Timothy P. Hart". hdl:1721.1/6111.
  21. ^ Kohlbecker, Eugene; Friedman, Daniel; Felleisen, Matthias; Duba, Bruce. "Hygienic Macro Expansion". doi:10.1145/319838.319859.
  22. ^ [one] Clinger, Rees. "Macros that Work"
  23. ^ Flatt, Matthew. "Composable and compilable macros: you desire it when?" (PDF).
  24. ^ Rafkind, Jon; Flatt, Matthew. "Honu: Syntactic Extension for Algebraic Annotation through Enforestation" (PDF).
  25. ^ "Automata via Macros". cs.brown.edu.
  26. ^ [2], Matthias Felleisen, LL1 mailing list posting
  27. ^ Orgass, Richard J.; William Thou. Waite (September 1969). "A base of operations for a mobile programming system". Communications of the ACM. New York, NY, The states: ACM. 12 (9): 507–510. doi:x.1145/363219.363226. S2CID 8164996.
  28. ^ Waite, William One thousand. (July 1970). "The mobile programming system: STAGE2". Communications of the ACM. New York, NY, USA: ACM. xiii (7): 415–421. doi:10.1145/362686.362691. S2CID 11733598.
  29. ^ "University of North Florida" (PDF).
  30. ^ "DTF (DOS/VSE)".
  31. ^ "IBM Knowledge Center". IBM Cognition Center. xvi Baronial 2013.
  32. ^ a b "Assembler Language Macro Instructions". Cisco.
  33. ^ a b Holbrook, Bernard D.; Chocolate-brown, Due west. Stanley. "Calculating Science Technical Report No. 99 – A History of Computing Research at Bell Laboratories (1937–1975)". Bell Labs. Archived from the original on September 2, 2014. Retrieved Feb 2, 2020.
  34. ^ "Macro SAP – Macro compiler modification of SAP". HOPL: Online Historical Encyclopaedia of Programming Languages. Archived from the original on August 13, 2008.
  35. ^ Layzell, P. (1985). "The History of Macro Processors in Programming Linguistic communication Extensibility". The Computer Periodical. 28 (1): 29–33. doi:10.1093/comjnl/28.i.29.

External links [edit]

  • How to write Macro Instructions
  • Rochester Found of Technology, Professors Powerpoint

wentztherip63.blogspot.com

Source: https://en.wikipedia.org/wiki/Macro_%28computer_science%29

0 Response to "A Macro Is a Series of Instructions That Can Be Grouped Together as a Single Command.ã¢â‚¬â€¹"

Enviar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel