11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

awk 33automatic programmingFrom the beginning <strong>of</strong> the computer age, computer scientistshave grappled with the fact that writing programsin any computer language, even relatively high-level onessuch as FORTRAN or C, requires painstaking attention todetail. While language developers have responded to thischallenge by trying to create more “programmer friendly”languages such as COBOL with its English-like syntax,another approach is to use the capabilities <strong>of</strong> the computerto automate the task <strong>of</strong> programming itself. It is truethat any high-level language compiler does this to someextent (by translating program statements into the underlyingmachine instructions), but the more ambitious taskis to create a system where the programmer would specifythe problem <strong>and</strong> the system would generate the high-levellanguage code. In other words, the task <strong>of</strong> programming,which had already been abstracted from the machine codelevel to the assembler level <strong>and</strong> from that level to the highlevellanguage, would be abstracted a step further.During the 1950s, researchers began to apply artificialintelligence principles to automate the solving <strong>of</strong> mathematicalproblems (see artificial intelligence). For example,in the 1950s Anthony Hoare introduced the definition <strong>of</strong>preconditions <strong>and</strong> postconditions to specify the states <strong>of</strong>the machine as it proceeds toward an end state (the solution<strong>of</strong> the problem). The program Logic Theorist demonstratedthat a computer could use a formal logical calculus to solveproblems from a set <strong>of</strong> conditions or axioms. Techniquessuch as deductive synthesis (reasoning from a set <strong>of</strong> programmedprinciples to a solution) <strong>and</strong> transformation (stepby-steprules for converting statements in a specificationlanguage into the target programming language) allowed forthe creation <strong>of</strong> automated programming systems, primarilyin mathematical <strong>and</strong> scientific fields (see also prolog).The development <strong>of</strong> the expert system (combining aknowledge base <strong>and</strong> inference rules) <strong>of</strong>fered yet anotherroute toward automated programming (see expert systems).Herbert Simon’s 1963 Heuristic Compiler was anearly demonstration <strong>of</strong> this approach.ApplicationsSince many business applications are relatively simple inlogical structure, practical automatic principles have beenused in developing application generators that can create,for example, a database management system given adescription <strong>of</strong> the data structures <strong>and</strong> the required reports.While some systems output code in a language such as C,others generate scripts to be run by the database managements<strong>of</strong>tware itself (for example, Micros<strong>of</strong>t Access).To simplify the underst<strong>and</strong>ing <strong>and</strong> specification <strong>of</strong> problems,a visual interface is <strong>of</strong>ten used for setting up the applicationrequirements. Onscreen objects can represent itemssuch as data files <strong>and</strong> records, <strong>and</strong> arrows or other connectinglinks can be dragged to indicate data relationships.The line between automated program generators <strong>and</strong>modern s<strong>of</strong>tware development environments is blurry. Aprogramming environment such as Visual Basic encapsulatesa great deal <strong>of</strong> functionality in objects called controls,which can represent menus, lists, buttons, text input boxes,<strong>and</strong> other features <strong>of</strong> the Windows interface, as well asother functionalities (such as a Web browser). The VisualBasic programmer can design an application by assemblingthe appropriate interface objects <strong>and</strong> processing tools, setproperties (characteristics), <strong>and</strong> write whatever additionalcode is necessary. While not completely automating programming,much <strong>of</strong> the same effect can be achieved.Further ReadingAndrews, James H. Logic Programming: Operational Semantics <strong>and</strong>Pro<strong>of</strong> Theory. New York: Cambridge University Press, 1992.“Automatic Programming Server.” Available online. URL: http://www.cs.utexas.edu/users/novak/cgi/apserver.cgi. AccessedApril 14, 2007.“Programming <strong>and</strong> Problem Solving by Connecting Diagrams.”Available online. URL: http://www.cs.utexas.edu/users/novak/cgi/vipdemo.cgi. Accessed April 14, 2007.Tahid, Walid, ed. Semantics, Applications <strong>and</strong> Implementation <strong>of</strong>Program Generation. New York: Springer-Verlag, 2000.awkThis is a scripting language developed under the UNIXoperating system (see scripting languages) by Alfred V.Aho, Brian W. Kernighan, <strong>and</strong> Peter J. Weinberger in 1977.(The name is an acronym from their last initials.) The languagebuilds upon many <strong>of</strong> the pattern matching utilities<strong>of</strong> the operating system <strong>and</strong> is designed primarily for theextraction <strong>and</strong> reporting <strong>of</strong> data from files. A number <strong>of</strong>variants <strong>of</strong> awk have been developed for other operatingsystems such as DOS.As with other scripting languages, an awk program consists<strong>of</strong> a series <strong>of</strong> comm<strong>and</strong>s read from a file by the awkinterpreter. For example the following UNIX comm<strong>and</strong>line:awk -f MyProgram > Reportreads awk statements from the file MyProgram into theawk interpreter <strong>and</strong> sends the program’s output to the fileReport.Language FeaturesAn awk statement consists <strong>of</strong> a pattern to match <strong>and</strong> anaction to be taken with the result (although the pattern canbe omitted if not needed). Here are some examples:{print $1} # prints the first field <strong>of</strong> every# line <strong>of</strong> input (since no pattern# is specified)/debit/ {print $2} # print the second field <strong>of</strong># every line that contains the# word “debit”if ( Code == 2 ) # if Code equals 2,print $3 # print third field# <strong>of</strong> each linePattern matching uses a variety <strong>of</strong> regular expressions familiarto UNIX users. Actions can be specified using a limitedbut adequate assortment <strong>of</strong> control structures similar to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!