Programming Language Pragmatics Chapter 1&2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the difference between a compiler and a preprocessor

A compiler has 2 significant features that a preprocessor doesnt: A translation from one nontrivial language to another, and a full analysys of the meaning of the input

What is a just-in-time compiler

A just-in time compiler converts bytecode (in java) or intermediate forms into machine language immedietly before each execution of the program

Keyword vs identifier

A keyword is a reserved word (if, while, int) identifier = variable names

What is backus Naur form?

A metalanguage used to formally describe the syntax of a language.

What is the longest possible token rule?

A parser should and will always scan for the longest possible token when reading characters

what is the difference between a phase and pass of compilation? When do compilers have multiple passes

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 associativity and precedence and why are they important?

Assiciativity is how to group operators, precedence is what goes first. Without knowing this you can't evaluate a prase tree correctly

Advantage of auto generated scanner vs hand written? Why are commercial compilers sometimes from handwritten

Autogenerated scanners are easier to implement, but handwritten ones are better for filtering out comments and whitespace which are hard to represent in a grammer

What is bootstrapping

Bootstrapping i sa way to build/assemble a compiler by using one created in a a different language translated into a different mini-interpreter (honestly I'm not sure)

What whas the intermediate form of employed by the original AT&T C++ compiler

C++ was transformed into C, and then compiled with a C compiler

Describe th eform a program goes from scanner--> intermediate code gen

Character stream -> scanner --> token stream -> parser -> parse tree -> semantic analysis -> abstract parse tree -> intermediate code gen

Explain the distinction between interpretation and compilation? Advantages and Disadvantages of each?

Compilation - Quicker/more efficient, only happens once then cna run many times Interpretation - more control over running, better debugging, more portable

Three basic operatiosn that can be used to build complex regular expressions from simpler ones?

Concatenation, Alternation, Kleene Closure

Difference between NFA and DFA? Why is DFA better for scanning?

DFA - only one state-input pair NFA, 0 or more state-input transition pairs DFA's dont rely on a computer handling guessing/decision making like an NFA does

What organization spearheaded the development of Ada?

Department of Defense

What is a sentential form? (For a CFG)

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

Why are there so many programming languages

Evolution, Special Purposes, Personal Preference

What makes a programming language successful?

Expressive Power, Ease of Use for Novice, Ease of Implementation, Standardization, Open Source, Excellent Compilers, Economics, Patronage, Inertia

why does a scanner have to save the text of tokens

For string literals, numeric values, error messaging, etc.

what is generally considered the first high-level programming language?

Fortran

What distinguishes the front end vs back end of a compiler

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 tasks does a scanner do?

Groups chars into tokens, removes comments, saves ID's and strings and stuff with line and column numbers

How are high level languages an improvement on assembly? Does it ever make sense to program in assembler?

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

What is a pragma?

Hint/directive to compiler, like run time checks, code improvements, etc.

what does the 1 in LR(1) mean?

How many lookaheads are needed

How do we know when a grammar is not LL(1)

If If you cannot predict which CFG rule it goes to then the grammer is LL(1)

What is the dangling else problem? How is it avoided?

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

What does it mean if a CFG is ambigious

If there is more than one parse tree, it is ambigious

What distinguishes declarative languages from imperitive

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 is the big-O of parsing, what is the complexity in real compilers?

Inherently O(n^3), in real compilers O(n)

What is the purpose of the compilers symbol table?

It is a data structure that maps each identifier to the information known about it including the identifier's type, internal structure , and scope.

Is Java compiled, interpreted, or both?

Java is both compiled and interpreted It's compiled inot java bytecode, then interpreded by a bytecode interpreter for output, but it can also be compiled as well by the JIT compiler

What was the first functional language

LISP

Why might we want/need different grammers for different parsing algorithms?

LL can't do left-recursive CFG's

Difference between LL and LR Parsing? Which one is predictive? Shift-reduce?

LL) left to right, left most. Top down, predictive parsing LR) left to right, right most derivation, bottom up, shift-reduce

Left most derivation vs right most derivation

Left most expandts the left most non-terminal, rightmost is the right most nonterminal first

What are the two things that LL top-down parsers can't deal with

Left recursion and common prefixes (Can't determine which path to go to based on upcoming token)

What is the difference between machine language and assembly language?

Machine language is binary 1's and 0's, assembly is a 1-1 human readable translation of machine language.

What is P-code

P-code is a stack-based lanugage similar to bytecode of modern Java compilers

What are recursive descent parsers? Why are they used for small languages?

Parse tree from top down usign recursive sub routines when you see non-terminals (LL parsers)

Similarities and differences between recursive descent and table-driven top down parsing?

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

How do you turn a RegEx to a DFA

RegEx to NFA DFA = NFA but each state is a set of states

What phases of compilation happen with interpretation as well?

Scanner Parser Semantic analysis

List the principle phases of compilation

Scanner (lexical analysis) Parser (syntax analysis) Semantic analysis and intermediate code gen code improvement (optional) Target code generation code improvement (optional)

Why do scanners have to sometimes peek ahead?

Sometimes tokens may start the same but end differently, like = and == are both tokens

what is the difference between static and dynamic semantics

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?

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.

Why aren't concurrent languages listed as a separate family?

They are written in conjunction with sequential languages like C or Fortran, so they don't fit into a unique family.

Why are right-most derivations sometimes called canonical?

They have been carefully studied, so they are called canonical

Name 3 languages from each category: Von Neumman, functional, obj-oriented? Name 2 logic languages, name 2 concurrent languages

Von Neumann: Ada, Fortran, C Functional: List, ML, Haskell obj-oriented: Java, C++, Smalltalk Logic Languages: SQL, Prolog concurrent: Java, C# v

How does a scanner identify lexical errors? And how does it respond

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 an epsilon production

When a non-terminal is an empty string, start the next token right away

Is top down or bottom up most common in production compilers

bottom up (LR) parsers

What additional operation can you use besides the main 3?

recursion


Set pelajaran terkait

Chapter 29 - Development and Inheritance

View Set

BIO156: Lesson 9 (9.5, Chapter 10)

View Set

Amoeba Sisters Video Recap; Photosynthesis and Cellular Respiration

View Set

Homework #4 - Ch's 12, 13, 16, 17

View Set