Post on 19-Aug-2020
February 13, 2020 Sam Siewert
CS 332Programming Language Concepts
Lecture 8 – Exam #1 Review
Learning Objectives – Part-1Define and use fundamental concepts
– Lexicon and lexical analysis– Syntax and syntactic analysis– Semantics and code generation or interpreter execution– Chomsky Hierarchy – Regular expression, CFG, CSG, Recursively Enumerable (programming
languages vs. NLP)– Regular Expressions and CFG [p. 42-48] – 1) alternation (selection of alternatives), 2)
concatenation, 3) Kleene star (arbitrary repetition)Regex – lexical element (character), epsilon (empty white space), 2 regex concatenated, alternation, Kleene start [parenthesis to group subexpressions]CFG adds recursion – define the construct in terms of itself
Front end of a compiler or interpreter– Lexical, syntactical scanning and parsing– AST – Abstract Syntax Tree (Parse Tree simplified)– Decorated Syntax Tree and S-attributed Grammars for code generation or interpretation
Intermediate layer of compiler (ignore) – e.g. RTL (Register Transfer Language in GCC)
Back end of a compiler or interpreter– Code generation in ISA (Instruction Set Architecture) according to ABI and basic blocks– Direct interpretation and execution of semantic productions
Programming Language Design– Basic Classification – Imperative Procedural (C), Imperative Procedural OO (C++, Java), Functional
(Lisp, Scheme), Dataflow (Verilog, CUDA), Logic (Prolog), Imperative scripted (R, MATLAB)– Names, Scope and Bindings– Type systems– Procedural abstraction
Sam Siewert 2
Chapter 1 – Lexicon, Syntax, SemanticsLexicon, Syntax - P. 27 – 28
Code Generation – P. 29 – 35 [Notes on ARM]
Notes and Assignment– Generating and analyzing ASM (ARM) blocks– LCD, GCD examples
Linguistic complexity vs. Computational complexity– Linguistic: RE, CFG, CSG, Recursively Enumerable– Computational: Boolean Logic, State Machines, PDA, Turing Machine
(Lambda-Calc)– Turing Machine (Lambda-Calc) Automation possible given CFG/CSG PLs
and underlying ALU in Von Neumann architecture
Differences between an interpreter and compiler are?
Gurus of Computability and Linguistics – Chomsky, Church, Gödel, Turing, Shannon
Sam Siewert 3
Chapter 2 – PL SyntaxRegex and CFG – P. 42-48
Scanning (NFA, DFA, no table driven) – P. 51-55, 63– NFA can be simplified into DFA to remove ambiguity– NFA is more compact (abstract) and therefore useful
Parsing– Recursive descent, p. 67– LL (top down) – O(n3), p. 72– LR (bottom up) – see example p. 88– Optimized versions of LR (LALR), p. 68, p. 91, p. 109
Ambiguity and rules to disambiguate – e.g. arithmetic, p. 50
Sam Siewert 4
Chapter 3 – Names, Scope, BindingsMemory
– Code segment– Data segment, p. 114– Stack segment, p. 115– Heap, p. 118– Garbage collection, p. 120
Scoping rules– Static [e.g. in C, what are semantics of use], p. 123– Nested functions, p. 124– Declaration order [C, C++], p. 127– Files and modules [visibility, cohesion, coupling], p. 132-136– Classes vs. modules– Dynamic scoping
Symbols, addresses, bindings, scope – p. 143Aliases, overloading, compile time polymorphism, run-time (late binding) – p. 144-148Notes - Pre-processor, compiler [object files], linker, loader, executionNotes - GCC binutils [nm, objdump]
Sam Siewert 5
Chapter 4 – Semantic AnalysisAttribute grammars, tie BNF for CFG to Semantic Rules – p. 185 [180]Evaluation of attributes – p. 187 [182]Action routines – p. [191]Decorated parse tree or AST – p. 180, Fig. 4.2 on 187 [197]An AST is a Parse tree with non-neccesary nodes eliminated (simplified)Extend to define Attribute GrammarProduction Semantic Rules = Attribute GrammarSemantic Rules {copy rules, semantic functions}
CFG Rule Semantic Rule or Production Type (p. 185)1) E → E + T E1.val = E2.val + T.val Funct2) E → E – T E1.val = E2.val - T.val Funct3) E → T E.val = T.val Copy4) T → T * F T1.val = T2.val * F.val Funct5) T → T / F T1.val = T2.val / F.val Funct6) T → F T.val = F.val Copy7) F → - F F1.val = - F2.val Funct8) F → (E) F.val = E.val Copy9) F → const F.val = C.val Copy
Sam Siewert 6
Chapter 5 – Target Code GenerationABI - Application Binary Interface defines how to use registers, frame pointer, stack pointer for function calls
Notes - ARM ASM examples
Embedded ABI (EABI) for C calling ASM with parameters
ASM blocks
ASM subroutines
Sam Siewert 7
Chapter 6 – Control FlowExpression evaluation– Precedence and associativity (well parenthesized C)– Assignment vs. compare– Initialization (constructors, destructors)– Ordering in expressions– C conditional expression– Short circuit logic in C
Structured control (loops, switch/case, if/then/else) vs. unstructured (goto, arithmetic if)
Sequencing and selectionIterationRecursion
Sam Siewert 8
Chapter 7 – Data TypesType systems – {dynamic or static} X {strong or weak}
Type extension – polymorphism
Type orthogonality (can I use types with all operators and without restriction)
Type equivalence – shallow or deep (structural)
Type compatibility and interference
Aggregates – (records and variants, arrays), stringsPointers and recursive data types (linked-list)Files
Sam Siewert 9
Intro to ProceduresPart of Chapter 8
Calling conventions (EABI)
Purpose
Nesting and recursion (tail recursion)
Example programs provided in class
Don’t worry about parameter passing (yet)
Sam Siewert 10
Part 1 - Take AwayFundamental PL organization– CLI – Command Line Interface and Regex processing– Interpreter and Scripts – interpreted programming languages– Compilers – Front-end and Back-end
Theory of parsing PL input (valid or invalid) and producing action or code in response
High level imperative procedural PL features
Start on selection of PL by paradigm (imperative, OO/procedural, functional, declarative, logic, dataflow)
Sam Siewert 11