Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 8310 Programming Languages

Similar presentations


Presentation on theme: "CSC 8310 Programming Languages"— Presentation transcript:

1 CSC 8310 Programming Languages
Meeting 1 August 30/31, 2016

2 Introduction Create name tent. Remember to bring to class each time.

3 Course Information csc.villanova.edu/~beck/csc8310/
Main source of information about the course Class meeting numbers on the course calendar are linked to slides Shows assignments, readings, etc. Topics for future class meetings may change as we develop programming language ideas.

4 Assessment Two short exams (45 minutes)
September 27/28 November 15/16 Final exam (150 minutes), December 14/15 Homework, from time to time Projects

5 Goals Examine Explore the baggage of language development
language structures language types language comparisons Explore the baggage of language development standards backwards compatibility Experiment with language features Not a goal: Learning to program well in various languages

6 Class Style Some lecture Some pair discovery Some problem solving
You are expected to build on your backgrounds; do not use the internet to find the answer. Some problem solving Some questions to answer later Somewhat formal approach, where “formal” means: Definitions Concepts described using sets and functions Use of algebraic structures where appropriate

7 Class Style (2) Course will not use Blackboard
Conversations among students should be held on piazza.com. Ask a question, answer a question, post a clarification. Watch for items mentioned in lecture that the instructor expects the students to complete. These make good discussion points on piazza.com

8 Systems Day Unix login:
LDAP userid, so the string from your address Password is followed by your 8-digit student number Other issues: Post a question or request on piazza.com

9 First Question What is a computer program?
Consult with your neighbor. Agree, or agree to disagree.

10 Available Alphabet Describe the alphabet available to you to create programs Keyboard alphabet Special symbols Blocks, in a blocky language

11 Programs, formally Let A be the alphabet of a programming language L, hence a subset of all the keyboard-producible characters. Let A* be the set of finite sequences of characters of A. L is a subset of A*. That is, any program P in L is a sequence of characters in A.

12 Programs, formally (2) Question: Why is this definition not completely correct? Sequence of successfully interlocking blocks

13 Second Question What is a space? What kinds of spaces are there?

14 Syntax The description of a language specifying structurally correct phrases in the language. As opposed to Semantics The meaning of phrases in the language

15 Syntax (2) and Pragmatics The practical use of the language
Communicating algorithms to humans Laying out a program in readable form Purpose of the language User interface to the language including IDE Efficiency of generated code

16 Simple Syntax <letter> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p| q|r|s|t|u|v|w|x|y|z Non-terminal: <letter> Terminals: lower case letters (26 choices) | means “or”

17 Simple Syntax (2) <letter seq> ::= <letter> | <letter seq><letter> Notes: Right recursion (or is it left recursion?) Does the recursive order make a difference? What are permissible lengths of letter sequences?

18 Simple Syntax (3) <digit> ::= 0|1|2|3|4|5|6|7|8|9
<digit string> ::= <digit> | <digit string><digit> Your turn: Create the syntax specification for an integer ----- Meeting Notes (8/31/16 08:50) ----- < integer > ::= [ + | - ] < digit string > But what about +0, -0, 0000, 0012?

19 BNF Backus-Naur Form (or Backus Normal Form) Use for
John Backus, developer of Fortran Peter Naur Revised Report on the Algorithmic Language Algol 60, Computer Journal, 5(1963), Use for Checking a symbol string for syntactic correctness Generating a correct symbol string

20 Extended BNF For those who dislike recursion:
[ ] surround an optional part { } surround a repeated part, repeated 0 or more times | separates choices ( ) are used to clarify hierarchy

21 Context Free Grammar Defined with four (4) elements: terminal symbols
formed as strings of the alphabet of the language lexical elements of the language non-terminal symbols each specifies a grammatical category, syntactic category, or set of strings of terminal symbols special non-terminal, the start symbol appears only on LHS of a single production productions each (recursively) defines a non-terminal symbol by showing how terminal and non-terminal symbols may be combined

22 Context Free Language Defined by a context free grammar
The set of all strings of terminal symbols generated by the context free grammar

23 Your Turn (1.1) Consider the following grammars expressed in BNF. In each case <T> is the start symbol, there is one additional non-terminal symbol <S>, and there are three terminal symbols: ( ) λ The only difference among the languages is one production. Each starts with the production <T> ::= <S>

24 Your Turn (1.2) The distinguishing productions for the three grammars are: <S> ::= <S><S> | (<S>) | λ <S> ::= (<S>)<S> | λ <S> ::= <S>(<S>) | λ If you assume that λ represents the empty string, which set of strings of terminal symbols is defined by each grammar?

25 Parse Tree Definition of a tree? Root labeled with start symbol
Interior nodes labeled with non-terminal symbols (syntactic categories) Leaves labeled with terminal symbols

26 Grammars for Expressions
Assume that we have definitions for the syntactic categories <constant> as a string of digits and <variable> as a string of letters. Define <aop> ::= + | − <mop> ::= * | /

27 Expressions (2) <exp> ::= <E> (the start symbol) <E> ::= <E><aop><T> | <T> <T> ::= <T><mop><F> | <F> <F> ::= ( <E> ) | <constant> | <variable>

28 Your Turn (2.1) Construct the parse tree for a-b-c
How are parentheses inferred in each of these expressions from traversing the parse tree using an inorder traversal?

29 Expressions (3) Using the same initial definitions as before, use the following grammar <exp> ::= <E> (the start symbol) <E> ::= <T><aop><E> | <T> <T> ::= <F><mop><T> | <F> <F> ::= ( <E> ) | <constant> | <variable> and construct the parse trees for a-b-c and a+b*c

30 Expressions (4) Using the same initial definitions as before, use the following grammar <exp> ::= <E> (the start symbol) <E> ::= <E><mop><T> | <T> <T> ::= <T><aop><F> | <F> <F> ::= ( <E> ) | <constant> | <variable> and construct the parse trees for a-b-c and a+b*c

31 Expressions (5) Using the same initial definitions as before, use the following grammar <exp> ::= <E> (the start symbol) <E> ::= <F> (<mop> | <aop> ) <E> | <F> <F> ::= ( <E> ) | <constant> | <variable> and construct the parse trees for a-b-c and a+b*c

32 Your Turn (2.2) Summary: How do associativity of operations and precedence of operations relate to the structure of the grammar for expressions? On your own: How do you fit unary operators into the expression grammars? Examples are sgn, log, cos

33 Sequences In many instances, we need to specify a sequence of items. This may be done recursively: <seq> ::= <id> | <seq> , <id> or <seq> ::= <id> | <id> , <seq> or with ellipses … as another operator in EBNF <seq> ::= <id> [ , <id> ] …

34 EBNF ::= is defined as | or < > syntactic category, grammatical category [ ] optional item { } repetition of enclosed production phrase 0 or more times … repetition of preceding production phrase 0 or more times

35 Assignment Due at beginning of next class meeting.
Work by yourself. Ask questions only of the instructor. Answers may be handwritten. Syntax Exercises 1, 5, 10 (The exercises can be found on the Resource part of the course website.)


Download ppt "CSC 8310 Programming Languages"

Similar presentations


Ads by Google