Macro (computer science)

Macro (computer science)

A macro (from the Greek 'μάκρο' for long or far) in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure. The mapping process which instantiates a macro into a specific output sequence is known as "macro expansion".

The term originated with macro-assemblers, where the idea is to make available to the programmer a sequence of computing instructions as a single program statement, making the programming task less tedious and less error-prone. [cite journal | last = Greenwald | first = Irwin D. | coauthors = Maureen Kane | title = The Share 709 System: Programming and Modification | journal = Journal of the ACM | volume = 6 | issue = 2 | pages = 128–133 | publisher = ACM | location = New York, NY, USA | date = April 1959 | url = | format = PDF | doi = 10.1145/320964.320967 Quotation: "One of the important uses of programmer macros is to save time and clerical-type errors in writing sequence of instructions which are often repeated in the course of a program."] [cite journal | last = Strachey| first = Christopher | title = A General Purpose Macrogenerator| journal = Computer Journal| volume = 8 | issue = 3 | pages = 225–241|date=October 1965 | doi = 10.1093/comjnl/8.3.225]

Keyboard and Macros

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

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

Keyboard macros have in more recent times come to life as a method of exploiting the economy of massively multiplayer online role-playing game (MMORPG)s. By tirelessly performing a boring, repetitive, but low risk action, a player running a macro can earn a large amount of the game's currency. This effect is even larger when a macro-using player operates multiple accounts simultaneously, or operates the accounts for a large amount of time each day. As this money is generated without human intervention, it can dramatically upset the economy of the game by causing runaway inflation. For this reason, use of macros is a violation of the TOS or EULA of most MMORPGs, and administrators of MMORPGs fight a continual war to identify and punish macro users [cite web |url= |title=Runescape: The Massive Online Adventure Game by Jagex Ltd. |accessdate=2008-04-03] .

Application macros and scripting

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

The programmers' text editor Emacs (short for "editing macros") follows this idea to a conclusion. In effect, most of the editor is made of macros. Emacs was originally devised as a set of macros in the editing language TECO; it was later ported to dialects of Lisp.

Visual Basic for Applications (VBA) is a programming language included in Microsoft Office and some other applications. However, its function has evolved from and replaced the macro languages which were originally included in some of these applications.

Macro virus

VBA has access to most Microsoft Windows system calls and executes when documents are opened. This makes it relatively easy to write computer viruses in VBA, commonly known as macro viruses. In the mid-to-late 1990s, this became one of the most common types of computer virus. However, during the late 1990's and to date, Microsoft has been patching and updating their programs. In addition, current anti-virus programs immediately counteract such attacks.

Text substitution macros

Languages such as C and assembly language have simple macro systems, implemented as preprocessors to the compiler or assembler. C preprocessor macros work by simple textual search-and-replace at the token, rather than the character, level.A classic use of macros is in the computer typesetting system TeX and its derivatives, where most 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 way to think of these syntax macros is as a multi-stage computation.Other examples:
* M4 is a sophisticated, stand-alone, macro processor.
* Macro Extension TAL, accompanying Template Attribute Language
* ml/1
* The General Purpose Macroprocessor is a contextual pattern matching macro processor, which could be described as a combination of regular expressions, EBNF and AWK
* SAM76

Procedural macros

Macros in the PL/I are written in a subset of PL/I itself: the compiler executes "preprocessor statements" at compilation time, and the output of this execution forms part of the code that is compiled. The ability to use 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 Technology's frame macros have their own command syntax but can also contain text in any language. Each frame is both a generic component in a hierarchy of nested subassemblies, and a procedure for integrating itself with its subassembly frames (a recursive process that resolves integration conflicts in favor of higher level subassemblies). The outputs are custom documents, typically compileable source modules. Frame Technology can avoid the proliferation of similar but subtly different components, an issue that has plagued software development since the invention of macros and subroutines.

Most assembly languages have less powerful procedural macro facilities, for example allowing a block of code to be repeated N times for loop unrolling; but these have a completely different syntax from the actual assembly language.

Lisp macros

Lisp's uniform, parenthesized syntax works especially well with macros. Languages of the Lisp family, such as Common Lisp and Scheme, have powerful macro systems because the syntax is simple enough to be parsed easily. Lisp macros transform the program structure itself, with the full language available to express such transformations. Common Lisp and Scheme differ in their macro systems: Scheme's is based on pattern matching, while Common Lisp macros are functions that explicitly construct sections of the program.

Being able to choose the order of evaluation (see lazy evaluation and non-strict functions) enables the creation of new syntactic constructs (e.g. control structures) indistinguishable from those built into the language. For instance, in a Lisp dialect that has cond but lacks if, it is possible to define the latter in terms of the former using macros.

Macros also make it possible to define data languages which are immediately compiled into code, which means that constructs such as state machines can be implemented in a way that is both natural and efficient. [ [ Brown University Paper on Automata Macros ] ]

Macros as solution to machine independent software

Macros are normally used to map a short string (macro invocation) to a longer sequence of instructions. Another, less common, use of macros is to do the reverse: to map a sequence of instructions to a macro string. This was the approach taken by the STAGE2 Mobile Programming System, which used a rudimentary macro compiler (called SIMCMP) to map the specific instruction set of a given computer to counterpart "machine-independent" macros. Applications (notably compilers) written in these machine-independent macros can then be run without change on any 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 machine-independent macro language. This macro compiler is applied to itself, in a bootstrap fashion, to produce a compiled and much more efficient version of itself. The advantage of this approach is that complex applications can be ported from one computer to a very different computer with very little effort (for each target machine architecture, just the writing of the rudimentary macro compiler). [cite journal
last = Orgass | first = Richard J. | coauthors = William M. Waite | title = A base for a mobile programming system | journal = Communications of the ACM | volume = 12 | issue = 9 | pages = 507–510 | publisher = ACM | location = New York, NY, USA | date = September 1969 | url = | doi = 10.1145/363219.363226
] [cite journal | last = Waite | first = William M. | title = The mobile programming system: STAGE2 | journal = Communications of the ACM | volume = 13 | issue = 7 | pages = 415–421 | publisher = ACM | location = New York, NY, USA | date = July 1970 | url = | doi = 10.1145/362686.362691 ] The advent of modern 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.


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Binding (computer science) — In computer science, binding is the creation of a simple reference to something that is larger and more complicated and used frequently. The simple reference can be used instead of having to repeat the larger thing. A binding is such a… …   Wikipedia

  • Zombie (computer science) — This article is about the computing term. For the Irish electro band, see Zombie Computer (Band). Zombie virus redirects here. For the use of the term in science fiction, see Zombie apocalypse. In computer science, a zombie is a computer… …   Wikipedia

  • Optimization (computer science) — In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating …   Wikipedia

  • Reflection (computer science) — In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior. The programming paradigm driven by reflection is called reflective programming .In most modern computer… …   Wikipedia

  • Macro — may refer to: * Macro (computer science) (for macroinstruction ), a computer science term for a set of instructions that is represented in an abbreviated format. * Macro photography, a type of close up photography * image macro, a picture with… …   Wikipedia

  • Advice (computer science) — In aspect and functional programming, advice describes a class of functions which modify other functions when the latter are run; it is a certain function, method or procedure that is to be applied at a given join point of a program.The following …   Wikipedia

  • Computer music — is a term that was originally used within academia to describe a field of study relating to the applications of computing technology in music composition; particularly that stemming from the Western art music tradition. It includes the theory and …   Wikipedia

  • MACRO-11 — is an assembly language with macro facilities for PDP 11 minicomputers from Digital Equipment Corporation (DEC). It is the successor to PAL 11 (Program Assembler Loader), an earlier version of the PDP 11 assembly language without macro facilities …   Wikipedia

  • Computer worm — Morris Worm source code disk at the Computer History Museum …   Wikipedia

  • computer programming language — Introduction       any of various languages for expressing a set of detailed instructions for a digital computer. Such instructions can be executed directly when they are in the computer manufacturer specific numerical form known as machine… …   Universalium

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”