Úvod
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.
Typické aplikace maker
Macroscanspeedupdailyeditingandformatting.Combinemultiplecommandstomaketheoptionsinthedialogboxeasiertoaccess.Makeaseriesofcomplextasksautomaticallyexecuted
Applicationscanalsouseasystemwithamechanismsimilartomacrostoallowuserstocustomizeaseriesof(usuallythemostcommonlyusedoperations)asastep.Thatis,theuserperformsaseriesofoperationsandallowstheapplicationto"remember"theseoperationsandthesequence.Moreadvanceduserscandirectlyusethefunctionsofthoseapplicationsthroughthebuilt-inmacroprogramming.Whenusinganunfamiliarmacrolanguagetoprogram,amoreeffectivemethodistorecordaseriesofoperationsthattheuserhopestoget,andthenunderstandthestructureofthemacrocommandbyreadingthemacrofilerecordedbytheapplication.
Makroprogramování
Whenusinganunfamiliarmacrolanguageformacroprogramming,youcandothis.Firstrecordwhattheuserwantsthemacrotoaccomplish,thenopenthemacrofileandtryUnderstandhowthecommandstructureworks.Youcanalsomodifythecommandtoadjustthemacro.Somemacrolanguages,suchastheDexterityruntimeengineofGreatPlainsaccountingsoftware,cannotimportdatafromotherdatasources(suchastextfilesseparatedbycommas).Thislimitationcanbesolvedbyusingamorepowerfulprogramminglanguage,suchasVBA,tocreateacomputerprogramtogenerateaspecialmacrointhisweakprogramminglanguage.Forexample,youcanprogramMicrosoftExcelmacrostoreaddatafromanextendedstylesheetortextfileandcreateaGreatPlains.macfile.ThisfileisusedtoimportspecificdataintoGreatPlains.ItneedstobegeneratedforeachnewdatasetNew.macfile.
Makro klávesnice
Makro klávesniceandeditormacroareusedinteractivelyinthegraphicaluserinterfaceandeditorrespectively.Theycanbeusedtoreplacelengthycommandsequenceswithshortkeystrokesandprovideasimpleformofautomationforrepetitivetasks,butthishaschangedin2009.
Theprogrammer'stexteditorEmacs(shortfor"EditingMACroS")isaproductofthisidea.Infact,mosteditorsarecomposedofmacros.EmacswasoriginallydesignedasamacrosetoftheeditinglanguageTECO,andlaterportedtoEmacsLisp,adialectofLisp.Vimalsoallowsuserstorecordandplaysimplekeyboardmacros.
Makrojazyk
Makrojazykisatypeofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Makrojazykisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,CpreprocessorCpreprocessorInternetMacros (iOpus)M4(asmentionedabove,originatedfromAT&T,bundledwithUnix)
Makrodefinice
providedbythecprogramOneofthepreprocessingfunctions.Includingmacrodefinitionswithparametersandmacrodefinitionswithoutparameters.Specifically,itreferstoasimplestringreplacementorexplanatoryreplacementwithaspecifiedidentifier.Theformis:
#defineflag[(tabulka parametrů)]řetězec
název makra
inthedefinitionaboveTheidentifieriscalleda"název makra".
Makroexpanze
Theprocessofreplacingthenázev makrawithacharacterstringwhenthecprogramiscompilediscalled"macroexpansion".
Makrojazykisakindofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Makrojazykisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,
CpreprocessorCpreprocessor
InternetMacros (iOpus)
M4(asmentionedearlier,originatedfromAT&T,bundledwithUnix)
Microsoft Word a makroviry
VisualBasicforApplications(VBA),isaprogramminglanguageinMicrosoftOffice.Butfromtheabovedefinition,itisnotamacrolanguageatall.However,itsfunctionhasevolvedfromitandeventuallyreplacedthemacroideaofuserapplications,soitiswidelyerroneouslycalledamacrolanguage.
VBAcanaccessmanyoperatingsystemfunctionsandsupportsautomaticmacroexecutionwhenthedocumentisopened.Thismakesitpossibletowritecomputervirusesinthislanguage.Inthemidtolate1990s,macrovirusesbecameoneofthemostpopulartypesofcomputerviruses.Otherprojectsthatincludemacrolanguages,suchasOpenOffice.org,deliberatelyexcludesomefunctions(suchasautomaticexecution)fromtheirmacrolanguagestoavoidprogramdamage.However,thisfeatureispopularinmanytransactions.