Johdanto
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.
ComputerlanguagessuchasCorassemblylanguagehavesimplemacrosystems,whichareimplementedbythepreprocessorofacompilerorassembler.ThejobofC'smacropreprocessorissimpletextsearchandreplacement.UsingadditionaltextprocessinglanguagessuchasM4,Cprogrammerscangetmoresophisticatedmacros.
Lisp-likelanguagessuchasCommonLispandSchemehavemoresophisticatedmacrosystems:Macrosbehavelikeafunction'stransformationoftheirownprogramtext,andalllanguagescanbeusedtoexpressthistransformation.ACmacrocandefinethesubstitutionofasectionofgrammar,butaLispmacrocancontrolthecalculationofasectionofcode.Gainedtheabilitytocontroltheexecutionorderofcode(seelazycalculationandunrestrictedfunctions),makingthenewlycreatedgrammaticalstructureindistinguishablefromthebuilt-ingrammaticalstructureofthelanguage.Forexample,ifaLispdialecthascondbutnoif,youcanusemacrostodefinethelatter.ThemainextensionsofLispsyntax,suchastheobject-orientedCLOSsystem,canbedefinedbymacros.
Tyypilliset makrojen sovellukset
Macroscanspeedupdailyeditingandformatting.Combinemultiplecommandstomaketheoptionsinthedialogboxeasiertoaccess.Makeaseriesofcomplextasksautomaticallyexecuted
Applicationscanalsouseasystemwithamechanismsimilartomacrostoallowuserstocustomizeaseriesof(usuallythemostcommonlyusedoperations)asastep.Thatis,theuserperformsaseriesofoperationsandallowstheapplicationto"remember"theseoperationsandthesequence.Moreadvanceduserscandirectlyusethefunctionsofthoseapplicationsthroughthebuilt-inmacroprogramming.Whenusinganunfamiliarmacrolanguagetoprogram,amoreeffectivemethodistorecordaseriesofoperationsthattheuserhopestoget,andthenunderstandthestructureofthemacrocommandbyreadingthemacrofilerecordedbytheapplication.
Makroohjelmointi
Whenusinganunfamiliarmacrolanguageformacroprogramming,youcandothis.Firstrecordwhattheuserwantsthemacrotoaccomplish,thenopenthemacrofileandtryUnderstandhowthecommandstructureworks.Youcanalsomodifythecommandtoadjustthemacro.Somemacrolanguages,suchastheDexterityruntimeengineofGreatPlainsaccountingsoftware,cannotimportdatafromotherdatasources(suchastextfilesseparatedbycommas).Thislimitationcanbesolvedbyusingamorepowerfulprogramminglanguage,suchasVBA,tocreateacomputerprogramtogenerateaspecialmacrointhisweakprogramminglanguage.Forexample,youcanprogramMicrosoftExcelmacrostoreaddatafromanextendedstylesheetortextfileandcreateaGreatPlains.macfile.ThisfileisusedtoimportspecificdataintoGreatPlains.ItneedstobegeneratedforeachnewdatasetNew.macfile.
Näppäimistömakro
Näppäimistömakroandeditormacroareusedinteractivelyinthegraphicaluserinterfaceandeditorrespectively.Theycanbeusedtoreplacelengthycommandsequenceswithshortkeystrokesandprovideasimpleformofautomationforrepetitivetasks,butthishaschangedin2009.
Theprogrammer'stexteditorEmacs(shortfor"EditingMACroS")isaproductofthisidea.Infact,mosteditorsarecomposedofmacros.EmacswasoriginallydesignedasamacrosetoftheeditinglanguageTECO,andlaterportedtoEmacsLisp,adialectofLisp.Vimalsoallowsuserstorecordandplaysimplekeyboardmacros.
Makrokieli
Makrokieliisatypeofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Makrokieliisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,CesiprosessoriCesiprosessoriInternetMacros (iOpus)M4(asmentionedabove,originatedfromAT&T,bundledwithUnix)
Makromäärittely
providedbythecprogramOneofthepreprocessingfunctions.Includingmacrodefinitionswithparametersandmacrodefinitionswithoutparameters.Specifically,itreferstoasimplestringreplacementorexplanatoryreplacementwithaspecifiedidentifier.Theformis:
#defineflag[(parametritaulukko)]merkkijono
makronimi
inthedefinitionaboveTheidentifieriscalleda"makronimi".
Makrolaajeneminen
Theprocessofreplacingthemakronimiwithacharacterstringwhenthecprogramiscompilediscalled"macroexpansion".
Makrokieliisakindofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Makrokieliisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,
CesiprosessoriCesiprosessori
InternetMacros (iOpus)
M4(asmentionedearlier,originatedfromAT&T,bundledwithUnix)
Microsoft Word ja makrovirukset
VisualBasicforApplications(VBA),isaprogramminglanguageinMicrosoftOffice.Butfromtheabovedefinition,itisnotamacrolanguageatall.However,itsfunctionhasevolvedfromitandeventuallyreplacedthemacroideaofuserapplications,soitiswidelyerroneouslycalledamacrolanguage.
VBAcanaccessmanyoperatingsystemfunctionsandsupportsautomaticmacroexecutionwhenthedocumentisopened.Thismakesitpossibletowritecomputervirusesinthislanguage.Inthemidtolate1990s,macrovirusesbecameoneofthemostpopulartypesofcomputerviruses.Otherprojectsthatincludemacrolanguages,suchasOpenOffice.org,deliberatelyexcludesomefunctions(suchasautomaticexecution)fromtheirmacrolanguagestoavoidprogramdamage.However,thisfeatureispopularinmanytransactions.