Макро

Въведение

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.

Типични приложения на макроси

Macroscanspeedupdailyeditingandformatting.Combinemultiplecommandstomaketheoptionsinthedialogboxeasiertoaccess.Makeaseriesofcomplextasksautomaticallyexecuted

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

Макропрограмиране

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

Macro

Макрос на клавиатурата

Макрос на клавиатуратаandeditormacroareusedinteractivelyinthegraphicaluserinterfaceandeditorrespectively.Theycanbeusedtoreplacelengthycommandsequenceswithshortkeystrokesandprovideasimpleformofautomationforrepetitivetasks,butthishaschangedin2009.

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

Макроезик

Макроезикisatypeofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Макроезикisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,CпрепроцесорCпрепроцесорИнтернет макроси (iOpus)M4(asmentionedabove,originatedfromAT&T,bundledwithUnix)

Макродефиниция

providedbythecprogramOneofthepreprocessingfunctions.Includingmacrodefinitionswithparametersandmacrodefinitionswithoutparameters.Specifically,itreferstoasimplestringreplacementorexplanatoryreplacementwithaspecifiedidentifier.Theformis:

#defineflag[(параметрична таблица)]низ

име на макрос

inthedefinitionaboveTheidentifieriscalleda"име на макрос".

Макроразширение

Theprocessofreplacingtheиме на макросwithacharacterstringwhenthecprogramiscompilediscalled"macroexpansion".

Макроезикisakindofprogramminglanguage,allormostofitscalculationsarecompletedbyexpansionmacros.Макроезикisnotwidelyusedingeneralprogramming,butitiswidelyusedintextprocessingprograms.Forexample,

CпрепроцесорCпрепроцесор

Интернет макроси (iOpus)

M4(asmentionedearlier,originatedfromAT&T,bundledwithUnix)

Microsoft Word и макровируси

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