Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICE1341 Programming Languages Spring 2005 Lecture #8 Lecture #8 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.

Similar presentations


Presentation on theme: "ICE1341 Programming Languages Spring 2005 Lecture #8 Lecture #8 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University."— Presentation transcript:

1 ICE1341 Programming Languages Spring 2005 Lecture #8 Lecture #8 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University (ICU)

2 Spring 2005 2 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Announcements The due date of the midterm project is postponed to Thursday April 14 th (a week after the midterm exam) The due date of the midterm project is postponed to Thursday April 14 th (a week after the midterm exam) There will be the project presentation session on the due date There will be the project presentation session on the due date

3 Spring 2005 3 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Axiomatic Semantics (cont.) Axiomatic Semantics (cont.) Names Names Variables Variables Bindings Bindings Binding Lifetimes Binding Lifetimes Last Lecture

4 Spring 2005 4 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University This Lecture Binding Lifetimes (cont.) Binding Lifetimes (cont.) WWW Concepts WWW Concepts WWW Languages WWW Languages XML (Extended Markup Language) XML (Extended Markup Language)

5 Spring 2005 5 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Program Memory Structure Static Area Static Area Program code Program code Non-local variables Non-local variables Static variables Static variables Dynamic Storage Dynamic Storage Stack Area Stack Area Local variables Local variables Parameters and return values Parameters and return values Heap Area Heap Area Dynamically allocated memory blocks Dynamically allocated memory blocks Dynamic storage control e.g., java –xm1024m MyProgram Stack Area Static Area Heap Area … Dynamic Storage

6 Spring 2005 6 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Binding Lifetimes Static: Storage bindings remain throughout execution Static: Storage bindings remain throughout execution e.g. all FORTRAN 77 variables, Java static variables Advantages: efficiency (direct addressing); history-sensitive subprogram support Advantages: efficiency (direct addressing); history-sensitive subprogram support Disadvantage: lack of flexibility (no recursion) Disadvantage: lack of flexibility (no recursion) Stack-Dynamic: Storage bindings are created when their declaration statements are elaborated Stack-Dynamic: Storage bindings are created when their declaration statements are elaborated e.g. local variables in C subprograms and Java methods Advantage: allows recursion; conserves storage Advantage: allows recursion; conserves storage Disadvantages: overhead of allocation and deallocation; subprograms cannot be history sensitive; slower accesses (indirect addressing) Disadvantages: overhead of allocation and deallocation; subprograms cannot be history sensitive; slower accesses (indirect addressing) * AW Lecture Notes

7 Spring 2005 7 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Binding Lifetimes – cont. Explicit Heap-Dynamic: Storages are allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution Explicit Heap-Dynamic: Storages are allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution e.g. dynamic objects in C++ (via new and delete) all objects in Java (new int[100]) all objects in Java (new int[100]) Advantage: provides for dynamic storage management Advantage: provides for dynamic storage management Disadvantage: inefficient and unreliable Disadvantage: inefficient and unreliable Implicit Heap-Dynamic: Storages are allocation and deallocation caused by assignment statements Implicit Heap-Dynamic: Storages are allocation and deallocation caused by assignment statements e.g. all variables in APL; all strings and arrays in Perl and JavaScript Advantage: flexibility Advantage: flexibility Disadvantages: inefficient, because all attributes are dynamic; loss of error detection by the compiler Disadvantages: inefficient, because all attributes are dynamic; loss of error detection by the compiler * AW Lecture Notes

8 Spring 2005 8 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Type Checking Type Checking: the activity of ensuring that the operands of an operator are of compatible types Type Checking: the activity of ensuring that the operands of an operator are of compatible types Compatible Type: a type that is either legal for an operator, or is allowed under language rules to be implicitly converted to a legal type (coercion) Compatible Type: a type that is either legal for an operator, or is allowed under language rules to be implicitly converted to a legal type (coercion) Type Error: the application of an operator to an operand of an inappropriate type Type Error: the application of an operator to an operand of an inappropriate type A programming language is strongly typed if type errors are always detected A programming language is strongly typed if type errors are always detected * AW Lecture Notes

9 Spring 2005 9 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Type Compatibility Name Type Compatibility: two variables have compatible types if they are in either the same declaration or in declarations that use the same type name Name Type Compatibility: two variables have compatible types if they are in either the same declaration or in declarations that use the same type name Easy to implement but highly restrictive Easy to implement but highly restrictive Subranges of integer types are not compatible with integer types Subranges of integer types are not compatible with integer types e.g.,type Indextype is 1..100; count: Integer; index: Indextype; Formal parameters must be the same type as their corresponding actual parameters (Pascal) Formal parameters must be the same type as their corresponding actual parameters (Pascal) Structure Type Compatibility: two variables have compatible types if their types have identical structures Structure Type Compatibility: two variables have compatible types if their types have identical structures More flexible, but harder to implement More flexible, but harder to implement

10 Spring 2005 10 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Type Compatibility – cont. Derived Type: a new type that is based on some previously defined type Derived Type: a new type that is based on some previously defined type Derive types inherit all the properties of their parent types Derive types inherit all the properties of their parent types Derived types allow types with the same structure to be different Derived types allow types with the same structure to be different e.g., type celsius is new Float; type fahrenheit is new Float; type fahrenheit is new Float; Subtype: a range-constrained version of an existing type Subtype: a range-constrained version of an existing type A subtype is compatible with its parent type A subtype is compatible with its parent type e.g., subtype Small_type is Integer range 0..99; Anonymous Type: Unnamed type Anonymous Type: Unnamed type Anonymous types are all unique, even in Anonymous types are all unique, even in e.g., C, D : array (1..10) of Integer;

11 Spring 2005 11 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University The World Wide Web (WWW) “Information Management: A Proposal”, Tim Berners- Lee, CERN, March 1989 “Information Management: A Proposal”, Tim Berners- Lee, CERN, March 1989CERN A proposal to build a global hypertext system for CERN A proposal to build a global hypertext system for CERN www.w3.org/History/1989/ proposal.html www.w3.org/History/1989/ proposal.html www.w3.org/History/1989/ proposal.html www.w3.org/History/1989/ proposal.html The original proposal of the WWW

12 Spring 2005 12 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University WWW Concepts Hypertext Universal Readership Searching Client-Server Model FormatNegotiation Image formatsImage formats Text fontsText fonts FramesFrames www.w3.org/Talks/General/Concepts.html

13 Spring 2005 13 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Languages for WWW HTML (Hypertext Markup Language) HTML (Hypertext Markup Language) Scripting Languages (e.g., Perl, JavaScript) Scripting Languages (e.g., Perl, JavaScript) XML (Extended Markup Language) XML (Extended Markup Language) RDF (Resource Description Framework) RDF (Resource Description Framework) DAML (DARPA Agent Markup Language) DAML (DARPA Agent Markup Language) SOAP (Simple Object Access Protocol) SOAP (Simple Object Access Protocol) WSDL (Web Services Description Language) WSDL (Web Services Description Language) WSFL (Web Services Flow Language) WSFL (Web Services Flow Language) …

14 Spring 2005 14 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University SGML (Standard Generalized Markup Language) SGML is a meta-markup language developed in the early 1980s (ISO 8879, 1986) SGML is a meta-markup language developed in the early 1980s (ISO 8879, 1986)ISO 8879ISO 8879 HTML was developed using SGML in the early 1990s - specifically for Web documents HTML was developed using SGML in the early 1990s - specifically for Web documents Problems with HTML: Problems with HTML: 1. Fixed set of tags and attributes User cannot define new tags or attributes User cannot define new tags or attributes So, the tags cannot connote any particular meaning So, the tags cannot connote any particular meaning 2. No restrictions on arrangement or order of tag appearance SGML is too large and complex to use, and it is very difficult to build a parser for it SGML is too large and complex to use, and it is very difficult to build a parser for it AW lecture notes

15 Spring 2005 15 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML (Extended Markup Language) XML is a light version of SGML that provides a way of storing and transferring data of any kind XML is a light version of SGML that provides a way of storing and transferring data of any kind XML vs. HTML XML vs. HTML HTML is a markup language used to describe the layout of any kind of information HTML is a markup language used to describe the layout of any kind of information XML is a meta-markup language that can be used to define markup languages that can define the meaning of specific kinds of information XML is a meta-markup language that can be used to define markup languages that can define the meaning of specific kinds of information XML does not predefine any tags XML does not predefine any tags All documents described with an XML-derived markup language can be parsed with a single parser All documents described with an XML-derived markup language can be parsed with a single parser AW lecture notes

16 Spring 2005 16 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University A Sample XML Document <class> Prog. Lang. Prog. Lang. ICE1341 ICE1341 <students> K.D. Ko K.D. Ko 820304 820304 </student> C.S. Lee C.S. Lee 830512 830512 </student></students></class>

17 Spring 2005 17 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML Syntax A flexible text format that is originally designed for large-scale electronic publishing of documents A flexible text format that is originally designed for large-scale electronic publishing of documents An XML document is a hierarchical organization of one or more named elements An XML document is a hierarchical organization of one or more named elements An element is composed of an opening-tag, data (string or another element), and a closing-tag An element is composed of an opening-tag, data (string or another element), and a closing-tag An opening-tag is an element name surrounded by ‘ ’ An opening-tag is an element name surrounded by ‘ ’ A closing-tag is an element name surrounded by ‘ ’ A closing-tag is an element name surrounded by ‘ ’ An element may have zero or more attributes An element may have zero or more attributes An attribute is a name-value pair that specifies a property of the element An attribute is a name-value pair that specifies a property of the element

18 Spring 2005 18 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML Syntax – cont. All XML documents begin with an XML declaration: All XML documents begin with an XML declaration: XML comments are just like HTML comments XML comments are just like HTML comments XML names: XML names: Must begin with a letter or an underscore Must begin with a letter or an underscore They can include digits, hyphens, and periods They can include digits, hyphens, and periods There is no length limitation There is no length limitation They are case sensitive (unlike HTML names) They are case sensitive (unlike HTML names) Syntax rules for XML: Syntax rules for XML: Every XML document defines a single root element, whose opening tag must appear as the first line of the document Every XML document defines a single root element, whose opening tag must appear as the first line of the document Every element that has content must have a closing tag Every element that has content must have a closing tag Tags must be properly nested Tags must be properly nested All attribute values must be quoted All attribute values must be quoted AW lecture notes

19 Spring 2005 19 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University A Sample XML Document <class> Prog. Lang. Prog. Lang. ICE1341 ICE1341 <students> K.D. Ko K.D. Ko 820304 820304 </student> C.S. Lee C.S. Lee 830512 830512 </student></students></class> An opening-tag A closing-tag An element An attribute The root element A value

20 Spring 2005 20 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University The XML Grammar document ::= prolog element Misc* document ::= prolog element Misc* element ::= EmptyElemTag | STag content ETag element ::= EmptyElemTag | STag content ETag EmptyElemTag ::= ' ' EmptyElemTag ::= ' ' STag ::= ' ' STag ::= ' ' content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* ETag ::= ' ' ETag ::= ' ' S ::= (#x20 | #x9 | #xD | #xA)+ S ::= (#x20 | #x9 | #xD | #xA)+ Attribute ::= Name '=' AttValue Attribute ::= Name '=' AttValue Name ::= (Letter | '_' | ':') (NameChar)* Name ::= (Letter | '_' | ':') (NameChar)* Comment ::= ' ' Comment ::= ' ' XML Spec: http://www.w3.org/TR/2004/REC-xml-20040204/ http://www.w3.org/TR/2004/REC-xml-20040204/

21 Spring 2005 21 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University An XML Document Grammar <class> Prog. Lang. Prog. Lang. ICE1341 ICE1341 <students> K.D. Ko K.D. Ko 830304 830304 </student> C.S. Lee C.S. Lee 840512 840512 </student></students></class> class  “ ” node “ class  “ ” node “ node  name code students name  “ ” string “ ” code  “ ” string “ ” students  “ ” student* “ ” student  “ ” name birthday “ ” birthday  “ ” num “ ”

22 Spring 2005 22 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML APIs SAX (Simple API for XML) – XML-DEV SAX (Simple API for XML) – XML-DEV Stream-based Access Interface (Sequential Access) Stream-based Access Interface (Sequential Access) Notifies an application of a stream of parsing events Notifies an application of a stream of parsing events Needs a Content Handler to handle the parsing events (e.g., start and end of an element) Needs a Content Handler to handle the parsing 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) – W3C DOM (Document Object Model) – W3C Object-oriented Access Interface (Random Access) Object-oriented Access Interface (Random Access) Builds a tree of nodes based on the structure and information in an XML document Builds a tree of nodes based on the structure and information in an XML document Types of nodes: Document, Element, Attr, … Types of nodes: Document, Element, Attr, …

23 Spring 2005 23 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University DOM Representation <class> Prog. Lang. Prog. Lang. ICE1341 ICE1341 Y.K. Ko Y.K. Ko 820304 820304 D.W. Kim D.W. Kim 830512 830512 </class> XML Document DOM Representation Document (Root Node) Elements (Child Nodes) Node Values (Text Nodes)

24 Spring 2005 24 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML Processors XML Parsers: read XML documents and provide access to their content and structure via DOM (e.g., Xerces, Sun’s Java XML Parser) XML Parsers: read XML documents and provide access to their content and structure via DOM (e.g., Xerces, Sun’s Java XML Parser) Document Filtering (Validation) Document Filtering (Validation) Document Type Declaration (DTD): a grammar for a class of XML documents Document Type Declaration (DTD): a grammar for a class of XML documents XML Schema (XSD): a successor of DTD. Describes the structure of an XML document XML Schema (XSD): a successor of DTD. Describes the structure of an XML document XML Presentation XML Presentation eXtensible Stylesheet Language (XSL): a language to define the transformation and presentation of an XML document eXtensible Stylesheet Language (XSL): a language to define the transformation and presentation of an XML document

25 Spring 2005 25 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML Processors XML Document Databases XML Parser DTD/ XMLSchema XSL Description XSL Processor XML Grammar (Structure) Validation DOM Objects HTML Presentation Parsing Events DOM API SAX API

26 Spring 2005 26 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University XML Logical Structure Examples......</patient> AW lecture notes <patient> Maggie Maggie Dee Dee Magpie Magpie......</patient> <patient> Maggie Dee Magpie Maggie Dee Magpie......</patient>

27 Spring 2005 27 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Logical Structure of an XML Document A new nested tag needs to be defined to provide more info about the content of a tag A new nested tag needs to be defined to provide more info about the content of a tag Nested tags are better than attributes, because attributes cannot describe structure and the structural complexity may grow Nested tags are better than attributes, because attributes cannot describe structure and the structural complexity may grow Attributes should always be used to identify numbers or names of elements (like HTML id and name attributes) Attributes should always be used to identify numbers or names of elements (like HTML id and name attributes) AW lecture notes http://tech.irt.org/articles/js212/

28 Spring 2005 28 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Related Materials W3C’s XML Web Site: http://www.w3.org/XML/ W3C’s XML Web Site: http://www.w3.org/XML/http://www.w3.org/XML/ XML Specification: http://www.w3.org/TR/2004/REC- xml-20040204/ XML Specification: http://www.w3.org/TR/2004/REC- xml-20040204/http://www.w3.org/TR/2004/REC- xml-20040204/http://www.w3.org/TR/2004/REC- xml-20040204/ XML Concepts: http://www.w3.org/Talks/General/Concepts.html XML Concepts: http://www.w3.org/Talks/General/Concepts.html http://www.w3.org/Talks/General/Concepts.html DTD Tutorial: http://www.w3schools.com/dtd/ DTD Tutorial: http://www.w3schools.com/dtd/http://www.w3schools.com/dtd/ XML Schema Tutorial: http://www.w3schools.com/schema/default.asp XML Schema Tutorial: http://www.w3schools.com/schema/default.asp http://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/http://www.w3.org/Style/XSL/ Other XML-related Notes: http://www.w3.org/XML/notes.html Other XML-related Notes: http://www.w3.org/XML/notes.html http://www.w3.org/XML/notes.html

29 Spring 2005 29 ICE 1341 – Programming Languages © In-Young Ko, Information and Communications University Midterm Term Project Design a structured programming language that includes the following language components Design a structured programming language that includes the following language components Type declaration statements for int, float, char, array Type declaration statements for int, float, char, array Operations: +, -, *, /, and, or, not Operations: +, -, *, /, and, or, not Assignment statement Assignment statement Conditional statement (if statement) Conditional statement (if statement) Loop (while statement) Loop (while statement) Program blocks (begin … end) Program blocks (begin … end) Develop an XML-based syntax of the language Develop an XML-based syntax of the language Write the grammar of the language in EBNF Write the grammar of the language in EBNF Write a sample program by using the language that you defined Write a sample program by using the language that you defined Display the sample program on MS Internet Explorer to validate its XML syntax Display the sample program on MS Internet Explorer to validate its XML syntax Explain the language design decisions such as application domains, and naming, binding, type compatibility, scoping rules Explain the language design decisions such as application domains, and naming, binding, type compatibility, scoping rules Due by April 14th


Download ppt "ICE1341 Programming Languages Spring 2005 Lecture #8 Lecture #8 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University."

Similar presentations


Ads by Google