Docsity

Programming Language Pragmatics — Lecture Slides (5th Ed., All Chapters), Exams of Nursing

Toggle sidebar
bg1
Programming Language Pragmatics — Lecture
Slides (5th Ed., All Chapters)
What is the difference between machine language and assembly language? - answer-Machine
language is binary 1's and 0's, assembly is a 1-1 human readable translation of machine
language.
How are high level languages an improvement on assembly? Does it ever make sense to
program in assembler? - answer-High level languages provide higher levels of abstraction, so
the user doesn't need to worry about minute details. Assembly programming can be good to
optimize code to make it as efficient as possible though
Why are there so many programming languages - answer-Evolution, Special Purposes, Personal
Preference
What makes a programming language successful? - answer-Expressive Power, Ease of Use for
Novice, Ease of Implementation, Standardization, Open Source, Excellent Compilers, Economics,
Patronage, Inertia
Name 3 languages from each category: Von Neumman, functional, obj-oriented? Name 2 logic
languages, name 2 concurrent languages - answer-Von Neumann: Ada, Fortran, C
Functional: List, ML, Haskell
obj-oriented: Java, C++, Smalltalk
Logic Languages: SQL, Prolog
concurrent: Java, C# v
What distinguishes declarative languages from imperitive - answer-Imperitive: Tell computer
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Programming Language Pragmatics — Lecture Slides (5th Ed., All Chapters) and more Exams Nursing in PDF only on Docsity!

Programming Language Pragmatics — Lecture

Slides (5th Ed., All Chapters)

What is the difference between machine language and assembly language? - answer-Machine language is binary 1's and 0's, assembly is a 1-1 human readable translation of machine language. How are high level languages an improvement on assembly? Does it ever make sense to program in assembler? - answer-High level languages provide higher levels of abstraction, so the user doesn't need to worry about minute details. Assembly programming can be good to optimize code to make it as efficient as possible though Why are there so many programming languages - answer-Evolution, Special Purposes, Personal Preference What makes a programming language successful? - answer-Expressive Power, Ease of Use for Novice, Ease of Implementation, Standardization, Open Source, Excellent Compilers, Economics, Patronage, Inertia Name 3 languages from each category: Von Neumman, functional, obj-oriented? Name 2 logic languages, name 2 concurrent languages - answer-Von Neumann: Ada, Fortran, C Functional: List, ML, Haskell obj-oriented: Java, C++, Smalltalk Logic Languages: SQL, Prolog concurrent: Java, C# v What distinguishes declarative languages from imperitive - answer-Imperitive: Tell computer

how to do something Ex -> find words greater than length 9 in array of strings: for loop, check each word, add long words to new arary Declarative: Tell computer what to do Ex-> find words greater than length 9 in array of strings: (*javascript) long_words = words.filter(word, word.length>=9, long_words += word) declarative calls function which does work instead of strictly telling computer how to calculate it. What organization spearheaded the development of Ada? - answer-Department of Defense what is generally considered the first high-level programming language? - answer-Fortran What was the first functional language - answer-LISP Why aren't concurrent languages listed as a separate family? - answer-They are written in conjunction with sequential languages like C or Fortran, so they don't fit into a unique family. Explain the distinction between interpretation and compilation? Advantages and Disadvantages of each? - answer-Compilation - Quicker/more efficient, only happens once then cna run many times Interpretation - more control over running, better debugging, more portable

code improvement (optional) What phases of compilation happen with interpretation as well? - answer-Scanner Parser Semantic analysis Describe th eform a program goes from scanner--> intermediate code gen - answer-Character stream -> scanner --> token stream -> parser -> parse tree -> semantic analysis -> abstract parse tree -> intermediate code gen What distinguishes the front end vs back end of a compiler - answer-Front end -> processing code independent of machine from characters to parse tree, figure out meaning of program back end -> generally machine specific code generation, substantial changes being made to target program what is the difference between a phase and pass of compilation? When do compilers have multiple passes - answer-A phase is each distinct part of compilation, a pass is a single or series of phases that don't start until previous phase completed. Compilers often broken into passes so the front end may be shared by compilers for more than one machine What is the purpose of the compilers symbol table? - answer-It is a data structure that maps each identifier to the information known about it including the identifier's type, internal structure , and scope. what is the difference between static and dynamic semantics - answer-Static semantics are semantics that can be determined from reading code, dynamic is when the runninf of the

program reveals/shows errors in a program (array out of bounds in java) Difference between syntax and semantics? - answer-Syntax refers to the structure/form of the code that a specific programming language specifies but Semantics deal with the meaning assigned to the symbols, characters and words. Three basic operatiosn that can be used to build complex regular expressions from simpler ones? - answer-Concatenation, Alternation, Kleene Closure What additional operation can you use besides the main 3? - answer-recursion What is backus Naur form? - answer-A metalanguage used to formally describe the syntax of a language. What is a sentential form? (For a CFG) - answer-Derivation: A series of replacement to show how a string of all terminals is made from the start sentential form is each string of symbols along the way Left most derivation vs right most derivation - answer-Left most expandts the left most non- terminal, rightmost is the right most nonterminal first What does it mean if a CFG is ambigious - answer-If there is more than one parse tree, it is ambigious What is associativity and precedence and why are they important? - answer-Assiciativity is how to group operators, precedence is what goes first. Without knowing this you can't evaluate a prase tree correctly

identifier = variable names why does a scanner have to save the text of tokens - answer-For string literals, numeric values, error messaging, etc. How does a scanner identify lexical errors? And how does it respond - answer-When a character is read that isn't part of the curren tor next token an error message is thrown and it tries to continue compiling bu doing one of 3 things:

  1. Throw away current
  2. skip forward until a proper character is found
  3. restart scanning What is a pragma? - answer-Hint/directive to compiler, like run time checks, code improvements, etc. What is the big-O of parsing, what is the complexity in real compilers? - answer-Inherently O(n^ 3), in real compilers O(n) Difference between LL and LR Parsing? Which one is predictive? Shift-reduce? - answer-LL) left to right, left most. Top down, predictive parsing LR) left to right, right most derivation, bottom up, shift-reduce Is top down or bottom up most common in production compilers - answer-bottom up (LR)

parsers Why are right-most derivations sometimes called canonical? - answer-They have been carefully studied, so they are called canonical what does the 1 in LR(1) mean? - answer-How many lookaheads are needed Why might we want/need different grammers for different parsing algorithms? - answer-LL can't do left-recursive CFG's What is an epsilon production - answer-When a non-terminal is an empty string, start the next token right away What are recursive descent parsers? Why are they used for small languages? - answer-Parse tree from top down usign recursive sub routines when you see non-terminals (LL parsers) What are the two things that LL top-down parsers can't deal with - answer-Left recursion and common prefixes (Can't determine which path to go to based on upcoming token) What is the dangling else problem? How is it avoided? - answer-If an else if optional, it can be ambigious what grouping of if's and else's go to. Solved by adding ending statements or braces. When encountered, group the "closest" if to the danlging else in the parse tree Similarities and differences between recursive descent and table-driven top down parsing? - answer-Recursive descent relies of subroutines to match and has an implicit call stack Table driven uses a stack containing upcoming calls, and the start maintains list of sybmots expected from here to end of program