CSE 3341 Principles of Programming Languages - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

CSE 3341 Principles of Programming Languages

Description:

Principles of Programming Languages Neelam Soundarajan Computer Sc. & Eng. Dreese Labs 579 e-mail: neelam_at_cse * Slide 16 notes How to do this in pure BNF? – PowerPoint PPT presentation

Number of Views:243
Avg rating:3.0/5.0
Slides: 17
Provided by: jeremyl7
Category:

less

Transcript and Presenter's Notes

Title: CSE 3341 Principles of Programming Languages


1
CSE 3341Principles of Programming Languages
  • Neelam Soundarajan
  • Computer Sc. Eng.
  • Dreese Labs 579
  • e-mail neelam_at_cse

2
Goals of the Course
  • Main Goal
  • Discuss key concepts underlying PLs
  • Sub-Goals
  • Alternative programming paradigms
  • Implementation issues
  • At end of course Given a feature, you should
    be able to
  • Decide whether you like it or not, and why
  • Have an idea how to implement it
  • Decide what kinds of problems it is suited for.

3
How do we study a language?
  • Syntax What do legal programs in L look like?
  • Semantics What do the various instructions of L
    do (when exec.)?
  • Programming Methodology How are you supposed to
    use the features of L? For solving what kinds of
    problems?

4
Compilers
5
Compilers (contd.)
6
Compilers Intermediate Langs.
  • Identify a language I
  • For each L, write
  • For each M, write
  • New machines are easy to handle
  • New languages are easy to handle
  • Common intermediate language C

7
Interpreters
8
Compilers Interpreters
  • What is an assembler?A simulator?The JVM?
  • JIT Just-in-time compilation
  • Running theme for the course Runtime versus
    compile-time
  • "Interpreter interprets each line into binary
    code which can be run on different platforms"
    Not true!

9
Syntax
  • BNF (Backus Normal Form) Notation for
    describing syntax of languages precisely.
  • Example Set of all non-negative
    integers ltnogt ltdigitgt ltdigitgt
    ltnogt ltdigitgt 0 1 2 3 4 5 6 7
    8 9
  • Set of all non-neg. nos. not starting with
    0ltnlznogt ltnlzdigitgt ltnlzdigitgt
    ltnlznogtltnlzdigitgt 1 2 3 4 5 6 7
    8 9 ??
  • lt, gt, , are reserved (meta)
    symbolsltdigitgt, ltnogt Non-terminals 0, 1, 2,
    ... Terminals
  • To define a BNF grammar Specify terminal and
    non-termnial symbols Define the production for
    each non-terminal.

10
Derivation trees/Parse trees
How do you derive 655 from this grammar?
ltnogt
(There is a bug in this tree!)
The string derived (or parsed) by the tree
Append together the labels at the leaves in
left-to- right order.
11
Example Grammar of expressions
ltexpgt ltnogt ltidgt ltexpgt ltexpgt ltexpgt
ltexpgt ltidgt X Y Z
Parse tree for X Y
12
Grammar of expressions (contd.)
Parse tree for X Y Z
ltexpgt
13
Grammar of expressions (contd.)
Another tree for X Y Z
Which is the right tree? The grammar is
ambiguous.
14
Another grammar for expressions
  • ltexpgt ltfacgt ltfacgt ltexpgtltfacgt ltnogt
    ltidgt ltnogt ltfacgt ltidgt ltfacgt
  • This grammar is not ambiguous
  • Reintroduce ambiguity among s and s (but
    not between and )
  • Parenthesized expressions?

15
Grammars (contd.)
  • Exercise Make precedence left to right or
    right to left
  • Ambiguous grammar for numbers ltnogt ltdigitgt
    ltnogt ltnogt
  • Even the following is not a good grammar ltnogt
    ltdigitgt ltdigitgt ltnogtProblem Wrong
    semantics.Q Can you fix it?

16
Grammars (contd.)
  • Syntax graphs Pictorial representation of BNF
    grammars.
  • Extended BNF (see Ch. 2.1.2 of book) ...
    optional item ... repetition (0 or more
    times) repetition (0 or more times)
    repetition (1 or more times)
  • ltifgt if ltcondgt then ltstmtgt ltelse-ifgt
    else ltstmtsgt end-ifltelse-ifgt elseIf
    ltcondgt then ltstmtsgt
Write a Comment
User Comments (0)
About PowerShow.com