Note 2 for CS 403 at UA-Programming Languages
Note 2 for CS 403 at UA-Programming Languages
Popular in Course
Popular in Department
This 4 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Alabama - Tuscaloosa taught by a professor in Fall. Since its upload, it has received 20 views.
Reviews for Note 2 for CS 403 at UA-Programming Languages
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
Lecture 2 Tuesday 1l15l02 Pure Interpretation Today Compilation vs interpretation Chapter14 Specifying syntax Chapter 21 Reading Assignments For Next Class Continue reading Chapter 21 22 Begin Chapter 3 Assignments Assignment 1 will be due Tuesday 12202 So lute pingram a lnpul Example Visual Basic can be run as interpreted or compiled Spnrg 2mm cs 403 Chss Names 1 Spnrg 2m2 cs 4030355wa F e A Compilation vs Interpretation Hybrid Approach Pure compilation Translate program into machine language object code Object code directly executable on target machine Pure interpretation No translation of source code interpreter runs on platform machine and executes source language statements Sommgm immmmm Imamin ux promn ltw 5 2mm cs 403 Chss Names 5 n ma cs 4030355wa F Pure Compilation Separate Compilation Source piogmm gt Compiler gtngei progmm lupin p 39quotrgclprugram gtOulpni Example Visual C is compiled Definition Different modules of the program are compiled separately ie at different times Sometimes difficult to see this in an integrated programming environment like Visual Studio A separate object file is produced for each module Linker must be run separately at the end to produce the final executable 5 2mm cs 403 Chss Names 5 n ma cs 4030355wa F Use of Libraries Linker can link object les for userwritten program modules or can link prewn39tllen library object files Wm lmmplmmumWW Incomplete machine langnzgz Libraiy iouunzs smznnzcs AUZChssNatzs P 27 Backus Naur Form BNF BNF Backus Naur Form A notation for defining programming language syntax Based on regular expressions and context free grammars Define what strings are syntactically correct vs incorrect Some basic notation Terminal symbols Actual items that are part of the language 01etc NonTerminal symbols ltexprgt ltopgt etc Ruleproduction A single line of BNF Alternatives Expressed with 0 or more occurrences 1 or more occurrences Spnrg 2mm cs mzcuss Nukes P e m Case Study Java Java compiled into bytecodes Standard format for distribution ofJava programs Allows programs to be transferred from one machine to another on the Internet and run on new machine Requires presence of Java Virtual Machine JVM Original paradigm Bytecodes were interpreted by the JVM More recent approach JVM provides a justintime bytecode compiler Actual machine language is then executed on the target machine 2mm es 403 Class Nukes P Defining Identifiers Identifier Typically used to name a variable constant or subprogram Identifier ltLettergt ABCD z ltDigitgt 012345 9 ltSymbolgt ltLettergt ltDigitgt ltdentifiergt ltSymbolgt Slight modification Restrict identifiers to not start with digits ltdentifiergt ltLettergt ltSymbolgt s mznnzcsmcusst P n New Topic Syntax Specification Practical problem Describing to someone the syntax of a C assignment statement Variable Expression But what is an expression Very difficult to capture unambiguously in English smznnzcs AUZChssNatzs P 29 Another Approach to Repetition Two approaches to repeated elements ltdenti ergt ltSymbolgt VS ltdenti ergt ltSymbolgtltSymbolgtltldenti ergt The other version of identifier ltdenti ergt ltLettergtltSymbolgt VS ltdenti ergt ltLettergtltSymbol Seqgt ltSymbol Seqgt ltSymbolgtltSymbol Seqgtc In these situations either approach works For some situations only the recursive approach works Spnrg 2mm cs mzcuss Nukes P 212 BNF for Assinment Statement ltassigngt ltvariablegt ltegtltprgt ltvariablegt ltettergtltchargt Parse Tree Explurion ltettergt AlBlCl Zabc z Wm ltegtltprgt ltvariablegtltnumbergt 0W0 lteXPrgt lteXPrgt ltegtltprgt ltOpgtltexprgt slope x intercept ltopgtIII SpngOOZCSAOEClasanms Pa 213 SPWZWZCSW3C1ESNWS Pa 16 BNF for While Another Parse Tree ltwhiegt while ltegtltprgt ltbodygt ltbodygt ltstmtgt ltstmt seqgt ltstmt seqgt ltstmtgtltstmt seqgt s ltstmtgt ltassrgngtltfunc cagtltlfgtltwhllegt 7 r 1 1 rs exrruxr39mr pernor wrmim Spm39gZOOZCS 403 crassnm Pa 214 Also slope x intercept This garrrnar is ambiguous Not an issue for us in specifying syntax Would be an isaJe for the compiler writer because precedence is derived 39orn the shape of the tree 5pm 2002 cs 403Clasantes Pa 2 17 BNF for ltexpressiongt ltexpressiongt ltidenti ergt ltnumbergt ltexpressiongt ltexpressiongt ltexpressiongtltoperatorgtltexpressiongt ltoperatorgt ltidentifiergt ltcharactergt ltcharactergt abcd Spm39gZOOZCS 403 crassnm Pa 215 NonStandard BNF Extensions optional zero or more repetitions We will not use the extensions in our work here Not easily compatible with parse trees derivations Use of these extensions will be penalized in grading For the same reason and should only be used in limited contexts eg fortokens constants etc 5pm 2002 cs 403Clasantes Pa 2 12 A More Abstract Context Its difficult to make up lots of interesting problems with actual programming languages Actual programming languages are complex Hard to get all of the assumptions in A More Abstract Context Write BNF for the language of all strings consisting of any number of As any number of B s and exactly one C Two approaches ltab5tract Stringsgt A B C OR ltab5tract String5gt ltAgtltBgtC ltAgt AltAgt i g ltBgt BltBgt i g smznnz cs 402st P 219 Group Work ltSgt ltAgtaltBgtb ltAgt ltAgtb b ltBgt altBgt a Which ofthe following strings are in the language defined by this BNF specification baab bbbab bbaaaaa bbaab smznnz cs 402st P an Homework Assignment 1 Due next Tuesday See class Web site for details Spring 2mm cs 403 Class Notes Pun
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'