Macro

Introduction

Amacroisagroupofcommandstogethertocompleteaspecifictaskasasinglecommand.ThedefinitionofmacroinMicrosoftWordis:"Macroisaseriesofwordcommandsthatcanbeorganizedtogetherandusedasanindependentcommand,whichcanmakedailyworkeasier."WordusesthemacrolanguageVisualBasictowritemacrosasaseriesofinstructions.

Macrosincomputerscienceareabstract,replacingcertaintextpatternsaccordingtoaseriesofpredefinedrules.TheExcelofficesoftwareautomaticallyintegratesthe"VBA"high-levelprogramminglanguage,andtheprogramcompiledinthislanguageiscalled"macro".Theuseof"VBA"requiresacertainprogrammingfoundationandalsoconsumesalotoftime.Therefore,thevastmajorityofusersonlyusethegeneraltabulationfunctionofExcelandrarelyuse"VBA".

Theinterpreterorcompilerwillautomaticallyperformthispatternreplacementwhenitencountersamacro.Forcompiledlanguages,macroexpansionoccursatcompiletime,andthetoolformacroexpansionisoftencalledamacroexpander.Thetermmacroisalsooftenusedinmanysimilarenvironments.Theyarederivedfromtheconceptofmacroexpansion,whichincludeskeyboardmacrosandmacrolanguages.Inmostcases,theuseoftheword"macro"impliestheconversionofsmallcommandsoractionsintoaseriesofinstructions.

Thepurposeofmacrosistoautomatefrequentlyusedsequencesortoobtainamorepowerfulabstractionability.

Computerlanguages​​suchasCorassemblylanguagehavesimplemacrosystems,whichareimplementedbythepreprocessorofacompilerorassembler.ThejobofC'smacropreprocessorissimpletextsearchandreplacement.Usingadditionaltextprocessinglanguages​​suchasM4,Cprogrammerscangetmoresophisticatedmacros.

Lisp-likelanguages​​suchasCommonLispandSchemehavemoresophisticatedmacrosystems:Macrosbehavelikeafunction'stransformationoftheirownprogramtext,andalllanguages​​canbeusedtoexpressthistransformation.ACmacrocandefinethesubstitutionofasectionofgrammar,butaLispmacrocancontrolthecalculationofasectionofcode.Gainedtheabilitytocontroltheexecutionorderofcode(seelazycalculationandunrestrictedfunctions),makingthenewlycreatedgrammaticalstructureindistinguishablefromthebuilt-ingrammaticalstructureofthelanguage.Forexample,ifaLispdialecthascondbutnoif,youcanusemacrostodefinethelatter.ThemainextensionsofLispsyntax,suchastheobject-orientedCLOSsystem,canbedefinedbymacros.

Typicalapplicationsofmacros

Macroscanspeedupdailyeditingandformatting.Combinemultiplecommandstomaketheoptionsinthedialogboxeasiertoaccess.Makeaseriesofcomplextasksautomaticallyexecuted

Applicationscanalsouseasystemwithamechanismsimilartomacrostoallowuserstocustomizeaseriesof(usuallythemostcommonlyusedoperations)asastep.Thatis,theuserperformsaseriesofoperationsandallowstheapplicationto"remember"theseoperationsandthesequence.Moreadvanceduserscandirectlyusethefunctionsofthoseapplicationsthroughthebuilt-inmacroprogramming.Whenusinganunfamiliarmacrolanguagetoprogram,amoreeffectivemethodistorecordaseriesofoperationsthattheuserhopestoget,andthenunderstandthestructureofthemacrocommandbyreadingthemacrofilerecordedbytheapplication.

Macroprogramming

Whenusinganunfamiliarmacrolanguageformacroprogramming,youcandothis.Firstrecordwhattheuserwantsthemacrotoaccomplish,thenopenthemacrofileandtryUnderstandhowthecommandstructureworks.Youcanalsomodifythecommandtoadjustthemacro.Somemacrolanguages,suchastheDexterityruntimeengineofGreatPlainsaccountingsoftware,cannotimportdatafromotherdatasources(suchastextfilesseparatedbycommas).Thislimitationcanbesolvedbyusingamorepowerfulprogramminglanguage,suchasVBA,tocreateacomputerprogramtogenerateaspecialmacrointhisweakprogramminglanguage.Forexample,youcanprogramMicrosoftExcelmacrostoreaddatafromanextendedstylesheetortextfileandcreateaGreatPlains.macfile.ThisfileisusedtoimportspecificdataintoGreatPlains.ItneedstobegeneratedforeachnewdatasetNew.macfile.

Macro

Keyboardmacro

Keyboardmacroandeditormacroareusedinteractivelyinthegraphicaluserinterfaceandeditorrespectively.Theycanbeusedtoreplacelengthycommandsequenceswithshortkeystrokesandprovideasimpleformofautomationforrepetitivetasks,butthishaschangedin2009.

Theprogrammer'stexteditorEmacs(shortfor"EditingMACroS")isaproductofthisidea.Infact,mosteditorsarecomposedofmacros.EmacswasoriginallydesignedasamacrosetoftheeditinglanguageTECO,andlaterportedtoEmacsLisp,adialectofLisp.Vimalsoallowsuserstorecordandplaysimplekeyboardmacros.

Macrolanguage

Macrolanguageisatypeofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Macrolanguageisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,CpreprocessorCpreprocessorInternetMacros(iOpus)M4(asmentionedabove,originatedfromAT&T,bundledwithUnix)

Macrodefinition

providedbythecprogramOneofthepreprocessingfunctions.Includingmacrodefinitionswithparametersandmacrodefinitionswithoutparameters.Specifically,itreferstoasimplestringreplacementorexplanatoryreplacementwithaspecifiedidentifier.Theformis:

#defineflag[(parametertable)]string

macroname

inthedefinitionaboveTheidentifieriscalleda"macroname".

Macroexpansion

Theprocessofreplacingthemacronamewithacharacterstringwhenthecprogramiscompilediscalled"macroexpansion".

Macrolanguageisakindofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Macrolanguageisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,

CpreprocessorCpreprocessor

InternetMacros(iOpus)

M4(asmentionedearlier,originatedfromAT&T,bundledwithUnix)

MicrosoftWordandmacroviruses

VisualBasicforApplications(VBA),isaprogramminglanguageinMicrosoftOffice.Butfromtheabovedefinition,itisnotamacrolanguageatall.However,itsfunctionhasevolvedfromitandeventuallyreplacedthemacroideaof​​userapplications,soitiswidelyerroneouslycalledamacrolanguage.

VBAcanaccessmanyoperatingsystemfunctionsandsupportsautomaticmacroexecutionwhenthedocumentisopened.Thismakesitpossibletowritecomputervirusesinthislanguage.Inthemidtolate1990s,macrovirusesbecameoneofthemostpopulartypesofcomputerviruses.Otherprojectsthatincludemacrolanguages,suchasOpenOffice.org,deliberatelyexcludesomefunctions(suchasautomaticexecution)fromtheirmacrolanguages​​toavoidprogramdamage.However,thisfeatureispopularinmanytransactions.

Related Articles
TOP