Upload
merryl-bryant
View
216
Download
1
Tags:
Embed Size (px)
Citation preview
ICE1341 ICE1341 Programming LanguagesProgramming Languages
Spring 2005Spring 2005
Lecture #8Lecture #8
In-Young Koiko .AT. icu.ac.kr
Information and Communications University (ICU)
Spring 2005 2 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
AnnouncementsAnnouncements
The due date of the midterm project is The due date of the midterm project is postponed to postponed to Thursday April 14Thursday April 14thth (a (a week after the midterm exam)week after the midterm exam)
There will be the There will be the project presentationproject presentation session on the due datesession on the due date
Spring 2005 3 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Axiomatic Semantics (cont.)Axiomatic Semantics (cont.) NamesNames VariablesVariables BindingsBindings Binding LifetimesBinding Lifetimes
Last LectureLast Lecture
Spring 2005 4 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
This LectureThis Lecture
Binding Lifetimes (cont.)Binding Lifetimes (cont.) WWW ConceptsWWW Concepts WWW LanguagesWWW Languages
XML (Extended Markup Language)XML (Extended Markup Language)
Spring 2005 5 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Program Memory StructureProgram Memory Structure
Static AreaStatic Area Program codeProgram code Non-local variablesNon-local variables Static variablesStatic variables
Dynamic StorageDynamic Storage Stack AreaStack Area
Local variablesLocal variables Parameters and return valuesParameters and return values
Heap AreaHeap Area Dynamically allocated memory Dynamically allocated memory
blocksblocks
Dynamic storage controlDynamic storage controle.g., e.g., java java –xm1024m–xm1024m MyProgram MyProgram
Stack AreaStack Area
Static AreaStatic Area
Heap AreaHeap Area
……
Dyn
amic
Sto
rage
Dyn
amic
Sto
rage
Spring 2005 6 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Binding LifetimesBinding Lifetimes
StaticStatic: Storage bindings remain throughout execution: Storage bindings remain throughout executione.g. e.g. all FORTRAN 77 variables, Java static variablesall FORTRAN 77 variables, Java static variables
AdvantagesAdvantages: efficiency (direct addressing); : efficiency (direct addressing); history-sensitivehistory-sensitive subprogram supportsubprogram support
DisadvantageDisadvantage: lack of flexibility (no recursion): lack of flexibility (no recursion)
Stack-DynamicStack-Dynamic: Storage bindings are created when : Storage bindings are created when their declaration statements are elaboratedtheir declaration statements are elaborated
e.g. e.g. local variables in C subprograms and Java methodslocal variables in C subprograms and Java methods Advantage: allows recursion; conserves storageAdvantage: allows recursion; conserves storage Disadvantages: overhead of allocation and deallocation; Disadvantages: overhead of allocation and deallocation;
subprograms cannot be history sensitive; slower accesses subprograms cannot be history sensitive; slower accesses ((indirect addressingindirect addressing))
* AW Lecture Notes
Spring 2005 7 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Binding Lifetimes Binding Lifetimes – cont.– cont.
Explicit Heap-DynamicExplicit Heap-Dynamic: Storages are allocated and deallocated : Storages are allocated and deallocated by explicit directives, specified by the programmer, which take by explicit directives, specified by the programmer, which take effect during executioneffect during execution
e.g. e.g. dynamic objects in C++ (via new and delete)dynamic objects in C++ (via new and delete)
all objects in Java (new int[100])all objects in Java (new int[100]) AdvantageAdvantage: provides for dynamic storage management: provides for dynamic storage management DisadvantageDisadvantage: inefficient and unreliable: inefficient and unreliable
Implicit Heap-DynamicImplicit Heap-Dynamic: Storages are allocation and deallocation : Storages are allocation and deallocation caused by assignment statementscaused by assignment statements
e.g. e.g. all variables in APL; all strings and arrays in Perl and JavaScriptall variables in APL; all strings and arrays in Perl and JavaScript AdvantageAdvantage: flexibility: flexibility DisadvantagesDisadvantages: inefficient, because all attributes are dynamic; loss of : inefficient, because all attributes are dynamic; loss of
error detection by the compilererror detection by the compiler
* AW Lecture Notes
Spring 2005 8 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Type CheckingType Checking
Type CheckingType Checking: the activity of ensuring that the : the activity of ensuring that the operands of an operator are of compatible typesoperands of an operator are of compatible types
Compatible TypeCompatible Type: a type that is either legal for : a type that is either legal for an operator, or is allowed under language rules to an operator, or is allowed under language rules to be implicitly converted to a legal type (be implicitly converted to a legal type (coercioncoercion))
Type ErrorType Error: the application of an operator to an : the application of an operator to an operand of an inappropriate typeoperand of an inappropriate type
A programming language is A programming language is strongly typedstrongly typed if if type errors are always detectedtype errors are always detected
* AW Lecture Notes
Spring 2005 9 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Type CompatibilityType Compatibility
Name Type CompatibilityName Type Compatibility: two variables have : two variables have compatible types if they are in either the same declaration compatible types if they are in either the same declaration or in declarations that use the same type nameor in declarations that use the same type name Easy to implement but highly restrictiveEasy to implement but highly restrictive
Subranges of integer types are not compatible with integer typesSubranges of integer types are not compatible with integer types
e.g.,e.g., type Indextype is 1..100;type Indextype is 1..100;
count: Integer;count: Integer;
index: Indextype;index: Indextype; Formal parameters must be the same type as their corresponding Formal parameters must be the same type as their corresponding
actual parameters (Pascal)actual parameters (Pascal)
Structure Type CompatibilityStructure Type Compatibility: : two variables have two variables have compatible types if their types have identical structurescompatible types if their types have identical structures More flexible, but harder to implementMore flexible, but harder to implement
Spring 2005 10
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Type Compatibility Type Compatibility – cont.– cont.
Derived TypeDerived Type: a new type that is based on some : a new type that is based on some previously defined typepreviously defined type Derive types inherit all the properties of their parent typesDerive types inherit all the properties of their parent types Derived types allow types with the same structure to be differentDerived types allow types with the same structure to be different
e.g., type celsius is new Float;e.g., type celsius is new Float;
type fahrenheit is new Float;type fahrenheit is new Float;
SubtypeSubtype: a range-constrained version of an existing type: a range-constrained version of an existing type A subtype is compatible with its parent typeA subtype is compatible with its parent type
e.g., subtype Small_type is Integer range 0..99;e.g., subtype Small_type is Integer range 0..99;
Anonymous TypeAnonymous Type: Unnamed type: Unnamed type Anonymous types are all unique, even inAnonymous types are all unique, even in
e.g., C, D : array (1..10) of Integer;e.g., C, D : array (1..10) of Integer;
Spring 2005 11
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
The World Wide Web (WWW)The World Wide Web (WWW)
““Information Management: Information Management: A Proposal”, A Proposal”, Tim Berners-Tim Berners-LeeLee, , CERNCERN, March 1989, March 1989
A proposal to build a A proposal to build a global global hypertext systemhypertext system for CERNfor CERN
www.w3.org/History/1989/www.w3.org/History/1989/proposal.htmlproposal.html
The original proposal of the WWWThe original proposal of the WWW
Spring 2005 12
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
WWW ConceptsWWW Concepts
HypertextHypertext
Universal ReadershipUniversal Readership
SearchingSearching Client-Server ModelClient-Server Model
FormatFormatNegotiationNegotiation• Image formatsImage formats• Text fontsText fonts• FramesFrames
www.w3.org/Talks/General/Concepts.htmlwww.w3.org/Talks/General/Concepts.html
Spring 2005 13
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Languages for WWWLanguages for WWW
HTMLHTML (Hypertext Markup Language) (Hypertext Markup Language) Scripting Languages (e.g., Perl, JavaScript)Scripting Languages (e.g., Perl, JavaScript) XMLXML (Extended Markup Language) (Extended Markup Language) RDFRDF (Resource Description Framework) (Resource Description Framework) DAMLDAML (DARPA Agent Markup Language) (DARPA Agent Markup Language) SOAPSOAP (Simple Object Access Protocol) (Simple Object Access Protocol) WSDLWSDL (Web Services Description Language) (Web Services Description Language) WSFLWSFL (Web Services Flow Language) (Web Services Flow Language) ……
Spring 2005 14
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
SGML (Standard Generalized Markup SGML (Standard Generalized Markup Language)Language)
SGML is SGML is a a metameta-markup language-markup language developed in developed in the early 1980s (ISO 8879, 1986)the early 1980s (ISO 8879, 1986)
HTMLHTML was developed was developed using SGMLusing SGML in the early in the early 1990s - 1990s - specifically for Web documentsspecifically for Web documents
Problems with HTML:Problems with HTML:1. 1. Fixed set of tags and attributesFixed set of tags and attributes
User cannot define new tags or attributesUser cannot define new tags or attributes So, the tags cannot connote any particular meaningSo, the tags cannot connote any particular meaning
2. 2. No restrictions on arrangement or order of tagNo restrictions on arrangement or order of tag appearanceappearance
SGML is SGML is too large and complextoo large and complex to use, and it is to use, and it is very very difficult to build a parserdifficult to build a parser for it for it
AW lecture notes
Spring 2005 15
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML (Extended Markup Language)XML (Extended Markup Language)
XML is XML is a light version of SGMLa light version of SGML that provides a that provides a way of way of storing and transferring data of any kindstoring and transferring data of any kind
XML vs. HTMLXML vs. HTML HTML is a markup language used to describe the HTML is a markup language used to describe the
layoutlayout of any kind of information of any kind of information XML is a meta-markup language that can be used to XML is a meta-markup language that can be used to
define markup languages that can define markup languages that can define the meaningdefine the meaning of specific kinds of informationof specific kinds of information
XML does XML does not predefine any tagsnot predefine any tags All documents described with an XML-derived All documents described with an XML-derived
markup language can be markup language can be parsed with a single parsed with a single parserparser
AW lecture notes
Spring 2005 16
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
A Sample XML DocumentA Sample XML Document<?xml version = "1.0“?><?xml version = "1.0“?>
<class><class><name><name>Prog. Lang.Prog. Lang.</name></name><code><code>ICE1341ICE1341</code></code><students><students>
<student <student id=“20041233”id=“20041233”>> <name><name>K.D. KoK.D. Ko</name></name> <bday><bday>820304820304</bday></bday></student></student><student <student id=“20041234”id=“20041234”>> <name><name>C.S. C.S.
LeeLee</name></name> <bday><bday>830512830512</bday></bday></student></student>
</students></students></class></class>
Spring 2005 17
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML SyntaxXML Syntax A flexible text format that is originally designed for A flexible text format that is originally designed for
large-scale electronic publishing of documentslarge-scale electronic publishing of documents An An XML documentXML document is a is a hierarchical organizationhierarchical organization
of one or more named elementsof one or more named elements An An elementelement is composed of an opening-tag, data is composed of an opening-tag, data
(string or another element), and a closing-tag(string or another element), and a closing-tag An An opening-tagopening-tag is an element name surrounded by is an element name surrounded by
‘<’ and ‘>’‘<’ and ‘>’ A A closing-tagclosing-tag is an element name surrounded by ‘<’ is an element name surrounded by ‘<’
and ‘/>’and ‘/>’ An element may have zero or more An element may have zero or more attributesattributes An An attributeattribute is a name-value pair that specifies a is a name-value pair that specifies a
property of the elementproperty of the element
Spring 2005 18
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML Syntax XML Syntax – cont.– cont.
All XML documents begin with an XML declaration:All XML documents begin with an XML declaration:<?xml version = "1.0"?><?xml version = "1.0"?> XML comments are just like HTML commentsXML comments are just like HTML comments
XML names: XML names: Must begin with a letter or an underscoreMust begin with a letter or an underscore They can include digits, They can include digits, hyphenshyphens, and , and periodsperiods There is There is no length limitationno length limitation They are They are case sensitivecase sensitive (unlike HTML names) (unlike HTML names)
Syntax rules for XML:Syntax rules for XML: Every XML document defines Every XML document defines a single root elementa single root element, whose , whose
opening tag must appear as the first line of the documentopening tag must appear as the first line of the document Every element that has content must have a Every element that has content must have a closing tagclosing tag Tags must be properly nestedTags must be properly nested All All attribute values must be quotedattribute values must be quoted
AW lecture notes
Spring 2005 19
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
A Sample XML DocumentA Sample XML Document
<?xml version = "1.0“?><?xml version = "1.0“?>
<class><class><name><name>Prog. Lang.Prog. Lang.</name></name><code><code>ICE1341ICE1341</code></code><students><students>
<student <student id=“20041233”id=“20041233”>> <name><name>K.D. KoK.D. Ko</name></name> <bday><bday>820304820304</bday></bday></student></student><student <student id=“20041234”id=“20041234”>> <name><name>C.S. C.S.
LeeLee</name></name> <bday><bday>830512830512</bday></bday></student></student>
</students></students></class></class>
An opening-tagAn opening-tag
A closing-tagA closing-tag
An elementAn element
An attributeAn attribute
The root elementThe root element
A valueA value
Spring 2005 20
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
The XML GrammarThe XML Grammar
document ::= document ::= prologprolog elementelement MiscMisc** element ::= element ::= EmptyElemTagEmptyElemTag | | STagSTag contentcontent ETagETag EmptyElemTag ::= 'EmptyElemTag ::= '<<' ' NameName ( (SS AttributeAttribute)* )* SS? '? '/>/>'' STag ::= 'STag ::= '<<' ' NameName ( (SS AttributeAttribute)* )* SS? '? '>>'' content ::= content ::= CharDataCharData? ((? ((elementelement | | ReferenceReference | |
CDSectCDSect | | PIPI | | CommentComment) ) CharDataCharData?)*?)* ETag ::= 'ETag ::= '</</' ' NameName SS? '? '>>'' S ::= (S ::= (#x20 #x20 | | #x9#x9 | | #xD#xD | | #xA#xA)+)+ Attribute ::= Attribute ::= NameName ' '==' ' AttValueAttValue Name ::= (Name ::= (LetterLetter | ' | '__' | '' | '::') (') (NameCharNameChar)*)* Comment ::= 'Comment ::= '<!--<!--' ((' ((CharChar - ' - '--') | ('') | ('--' (' (CharChar - ' - '--')))* '')))* '-->-->''
XML Spec: http://www.w3.org/TR/2004/REC-xml-20040204/XML Spec: http://www.w3.org/TR/2004/REC-xml-20040204/
Spring 2005 21
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
An XML Document GrammarAn XML Document Grammar
<class><class><name><name>Prog. Lang.Prog. Lang.</name></name><code><code>ICE1341ICE1341</code></code><students><students>
<student <student id=“20041233”id=“20041233”>> <name><name>K.D. KoK.D. Ko</name></name> <bday><bday>830304830304</bday></bday></student></student><student <student id=“20041234”id=“20041234”>> <name><name>C.S. C.S.
LeeLee</name></name> <bday><bday>840512840512</bday></bday></student></student>
</students></students></class></class>
class class “<class>” node “</class> “<class>” node “</class>
node node name code students name code students
name name “<name>” string “</name>” “<name>” string “</name>”
code code “<code>” string “</code>” “<code>” string “</code>”
students students “<students>” student* “<students>” student* “</students>”“</students>”
student student “<student” S “id=\”” num “<student” S “id=\”” num “\”” S “/>” name birthday “\”” S “/>” name birthday “</student>”“</student>”
birthday birthday “<bday>” num “</bday>” “<bday>” num “</bday>”
Spring 2005 22
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML APIsXML APIs
SAX (Simple API for XML)SAX (Simple API for XML) – – XML-DEVXML-DEV Stream-based Access InterfaceStream-based Access Interface (Sequential Access) (Sequential Access) Notifies an application of a stream of Notifies an application of a stream of parsing eventsparsing events Needs a Needs a Content HandlerContent Handler to handle the parsing to handle the parsing
events (e.g., start and end of an element)events (e.g., start and end of an element) Appropriate to handle a large XML document Appropriate to handle a large XML document
DOM (Document Object Model)DOM (Document Object Model) – – W3CW3C Object-oriented Access Interface Object-oriented Access Interface (Random Access)(Random Access) Builds a Builds a tree of nodestree of nodes based on the structure and based on the structure and
information in an XML documentinformation in an XML document Types of nodes: Types of nodes: DocumentDocument, , ElementElement, , AttrAttr, …, …
Spring 2005 23
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
DOM RepresentationDOM Representation
classclass
namename codecode studentsstudents
ProgProg. Lang. Lang ICE1341ICE1341 studentstudent studentstudent
namename bdaybday namename bdaybday
Y.K. KoY.K. Ko 820304820304 D.W. KimD.W. Kim 830512830512
classclass
namename codecode studentsstudents
ProgProg. Lang. Lang ICE1341ICE1341 studentstudent studentstudent
namename bdaybday namename bdaybday
Y.K. KoY.K. Ko 820304820304 D.W. KimD.W. Kim 830512830512
<class><class> <name><name>Prog. Lang.Prog. Lang.</name></name> <code><code>ICE1341ICE1341</code></code> <students><students>
<student <student id=“20037001”id=“20037001”>> <name><name>Y.K. KoY.K. Ko</name></name> <bday><bday>820304820304</bday></bday> </student></student> <student <student id=“20037002”id=“20037002”>> <name><name>D.W. KimD.W. Kim</name></name> <bday><bday>830512830512</bday></bday> </student></student>
</students></students></class></class>
XML DocumentXML Document DOM RepresentationDOM Representation
Document Document (Root Node)(Root Node)
Elements Elements (Child Nodes)(Child Nodes)
Node Values Node Values (Text Nodes)(Text Nodes)
Spring 2005 24
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML ProcessorsXML Processors
XML ParsersXML Parsers: read XML documents and : read XML documents and provide access to their content and structure via provide access to their content and structure via DOM (e.g., Xerces, Sun’s Java XML Parser)DOM (e.g., Xerces, Sun’s Java XML Parser)
Document Filtering (Validation)Document Filtering (Validation) Document Type Declaration (DTD)Document Type Declaration (DTD): a : a grammargrammar for for
a class of XML documents a class of XML documents XML Schema (XSD)XML Schema (XSD): a successor of DTD. : a successor of DTD.
Describes the structure of an XML documentDescribes the structure of an XML document XML PresentationXML Presentation
eXtensible Stylesheet Language (XSL)eXtensible Stylesheet Language (XSL): a : a language to define the transformation and language to define the transformation and presentation of an XML documentpresentation of an XML document
Spring 2005 25
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML ProcessorsXML Processors
XML XML DocumentDocument
DatabasesDatabases
XML ParserXML Parser
DTD/ DTD/ XMLSchemaXMLSchema
XSL XSL DescriptionDescription
XSL ProcessorXSL Processor
XML Grammar XML Grammar (Structure) Validation(Structure) Validation
DOM ObjectsDOM Objects
HTML HTML PresentationPresentation
classclass
namename codecode studentsstudents
ProgProg. Lang. Lang ICE1341ICE1341 studentstudent studentstudent
namename bdaybday namename bdaybday
Y.K. KoY.K. Ko 820304820304 D.W. KimD.W. Kim 830512830512
classclass
namename codecode studentsstudents
ProgProg. Lang. Lang ICE1341ICE1341 studentstudent studentstudent
namename bdaybday namename bdaybday
Y.K. KoY.K. Ko 820304820304 D.W. KimD.W. Kim 830512830512
Parsing EventsParsing Events
DOM APIDOM API SAX APISAX API
Spring 2005 26
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
XML Logical Structure ExamplesXML Logical Structure Examples
<!-- A tag with one attribute --><!-- A tag with one attribute --><patient name = "Maggie Dee <patient name = "Maggie Dee
Magpie">Magpie"> ......</patient></patient>
AW lecture notes
<!-- Multi-level nested tags --><!-- Multi-level nested tags -->
<patient><patient>
<name><name>
<first> Maggie </first><first> Maggie </first>
<middle> Dee </middle><middle> Dee </middle>
<last> Magpie </last><last> Magpie </last>
</name></name>
......
</patient></patient>
<!-- A tag with one nested tag --><!-- A tag with one nested tag -->
<patient><patient>
<name> Maggie Dee Magpie <name> Maggie Dee Magpie
</name></name>
......
</patient></patient>
Spring 2005 27
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Logical Structure of an XML DocumentLogical Structure of an XML Document
A new A new nested tagnested tag needs to be defined to needs to be defined to provide more info about the content of a provide more info about the content of a tagtag
Nested tags are better than attributes, Nested tags are better than attributes, because because attributes cannot describe attributes cannot describe structurestructure and the structural complexity and the structural complexity may growmay grow
AttributesAttributes should always be used should always be used to to identify numbers or namesidentify numbers or names of elements of elements (like HTML id and name attributes)(like HTML id and name attributes)
AW lecture noteshttp://tech.irt.org/articles/js212/
Spring 2005 28
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Related MaterialsRelated Materials
W3C’s XML Web Site: http://www.w3.org/XML/W3C’s XML Web Site: http://www.w3.org/XML/ XML Specification: http://www.w3.org/TR/2004/REC-XML Specification: http://www.w3.org/TR/2004/REC-
xml-20040204/xml-20040204/ XML Concepts: XML Concepts:
http://www.w3.org/Talks/General/Concepts.htmlhttp://www.w3.org/Talks/General/Concepts.html DTD Tutorial: http://www.w3schools.com/dtd/DTD Tutorial: http://www.w3schools.com/dtd/ XML Schema Tutorial: XML Schema Tutorial:
http://www.w3schools.com/schema/default.asphttp://www.w3schools.com/schema/default.asp W3C’s XSL Site: http://www.w3.org/Style/XSL/W3C’s XSL Site: http://www.w3.org/Style/XSL/ Other XML-related Notes: Other XML-related Notes:
http://www.w3.org/XML/notes.htmlhttp://www.w3.org/XML/notes.html
Spring 2005 29
ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University
Midterm Term ProjectMidterm Term Project Design a Design a structured programming languagestructured programming language that includes the that includes the
following language componentsfollowing language components Type declaration statements for Type declaration statements for int, float, char, arrayint, float, char, array Operations: Operations: +, -, *, /, and, or, not+, -, *, /, and, or, not Assignment statementAssignment statement Conditional statement (Conditional statement (ifif statement) statement) Loop (Loop (whilewhile statement) statement) Program blocks (Program blocks (beginbegin … … endend))
Develop an Develop an XML-based syntaxXML-based syntax of the language of the language Write the Write the grammargrammar of the language in EBNF of the language in EBNF Write a Write a sample programsample program by using the language that you defined by using the language that you defined Display the sample program on MS Internet Explorer to validate Display the sample program on MS Internet Explorer to validate
its XML syntaxits XML syntax Explain the Explain the language design decisionslanguage design decisions such as application such as application
domains, and naming, binding, type compatibility, scoping rulesdomains, and naming, binding, type compatibility, scoping rules
Due by April 14thDue by April 14th