CSCI 318 Midterm Review

Ace your homework & exams now with Quizwiz!

Non-terminal, terminal, and pre-terminal symbols

- A non-terminal symbol is any symbol in the LHS (or RHS) of a rule. They represent abstractions in the language, e.g. <if-then-else-statement> ::= if <test> then <statement> else <statement> - A terminal symbol (AKA lexemes) is a symbol that's NOT in any rule's LHS. They are literal symbols that will appear in a program (e.g., if, then, else in rule above) <if-then-else-statement> ::= if <test> then <statement> else <statement> - A pre-terminal symbol is one that appears as a LHS of rules, but in every case, the RHSs consist of single terminal symbol, e.g., <digit> in <digit> ::= 0 | 1 | 2 | 3 ... 7 | 8 | 9

PL Implementation approaches

- Direct execution by hardware e.g. native machine language - Compilation to another language e.g. C compiled to Intel Pentium 4 native machine language - Interpretation: direct execution by software e.g. Compilation to another language then interpreted by another language. - Just-in-time compilation e.g. Dynamically compile some bytecode to native (V8 JavaScript).

What are some basic concepts of Polymorphism?

- If Employee is a class that extends Person, an Employee "is-a" Person and polymorphism can occur. Person [] p = new Person[2]; p[0] = new Employee(); p[1] = new Person();

Big Four PL Paradigms

- Imperative or Procedural (e.g. Fortran or C) - Object-oriented (e.g. Smalltalk or Java) - Functional (e.g. Lisp or ML) - Rule Based (e.g. Prolog or Jess)

Why shall we study PL concepts?

- Increased capacity to express programing concepts. - Improved background for choosing appropriate languages. - Enhanced ability to learn new languages. - Improved understanding of the significance of implementation. - Increased ability to design new languages. - Mastering different programming paradigms.

What are some basic concepts of Inheritance?

- Inheritance is implemented using the keyword extends. public class Employee extends Person { //Class definition goes here - only the //implementation for the specialized behavior } - A class may only inherit from only one superclass. - If a class is not derived from a super class then it is derived from java.lang.Object. The following two class declarations are equivalent: public class Person {...} public class Person extends Object {...}

Various Programming Language application domains?

- Scientific Applications - Business Applications - Artificial Intelligence - Systems Programming - Scripting Languages - Special Purpose Languages - Mobile, educational, web, massively parallel

Generics

- Since JDK 1.5 (Java 5), the Collections framework has been parameterized. - A class that is defined with a parameter for a type is called a generic or a parameterized class. - If you compare the Collection interface in the API for 1.4.2 to the one in version 1.5.0, you will see the interface is now called Collection<E>.

Abstract Classes and Methods

-Java also has abstract classes and methods. If a class has an abstract method, then it must be declared abstract. public abstract class Node{ String name; public abstract void type(); public String toString(){ return name;} public Node(String name){ this.name = name; } }

What composes a PC?

1. CPU - Central Processing Unit controls all other functions. 2. Bus - a group of parallel wires that carry control signals and data between components. 3. Main Memory - holds information such as programs, numeric data, or documents created. 4. Secondary Storage Media - Disks, Tapes, CDs, DVDs. Stores: data, programs, other types of information. 5. I/O devices - mouse, keyboard, monitor, printers etc.

How to work out a leftmost derivation?

<sentence> ::= <article><noun><verbPhrase>. <sentence> ::= The<noun><verbPhrase>. <sentence> ::= The man <verbPhrase>. <sentence> ::= The man <verb><nounPhrase>. <sentence> ::= The man throws <nounPhrase>. <sentence> ::= The man throws <article><noun>. <sentence> ::= The man throws a <noun>. <sentence> ::= The man throws a football.

Formal grammar and its role in PL

A (formal) grammar is a set of rules for strings in a formal language. The rules describe how to form strings from the language's alphabet that are valid according to the language's syntax. A grammar does not describe the meaning of the strings or what can be done with them in whatever context — only their form.

Sentence, language, lexeme, and token concepts

A sentence is a string of characters over some alphabet (e.g., def add1(n): return n + 1) A language is a set of sentences A lexeme is the lowest level syntactic unit of a language (e.g., *, add1, begin) A token is a category of lexemes (e.g., identifier)

Finite and infinite language

A simple language may have a finite number of sentences The set of strings representing integers between -10**6 and +10**6 is a finite language A finite language can be defined by enumerating the sentences, but using a grammar is usually easier (e.g., small integers) Most interesting languages have an infinite number of sentences

What are the widely-used coding-schemes?

ASCII Code: American Standard Code for Information Interchange. Upper/Lowercase letters, digits and punctuation marks with an 7-bit number. Unicode: 16 bit per character, include world's all language and mathematical symbols. Consistent with ASCII Code.

Ada

Ada was "mandated" for use in DoD work during late 80's and early 90's. Contributions: 1. Packages - support for data abstraction 2. Exception handling - elaborate 3. Generic program units 4. Concurrency - through the tasking model

Meaning and usage of Epsilons

An epsilon (ε) symbol expands to 'nothing' It is used as a compact way to make something optional For example: NP -> DET NP PP PP -> PREP NP | ε PREP -> in | on | of | under You can always rewrite a grammar with ε symbols to an equivalent one without ε

Interfaces and an example

An interface is like class without the implementation. It contains only -public, static and final fields, and -public and abstract method headers (no body). A public interface, like a public class, must be in a file of the same name. The methods and fields are implicitly public and abstract by virtue of being declared in an interface. e.g: public interface Employable { void raiseSalary(double d); double getSalary(); }

BASIC

Beginner's All purpose Symbolic Instruction Code Designed by Kemeny & Kurtz at Dartmouth for the GE 225 with the goals: - Easy to learn and use for non-science students and as a path to Fortran and Algol - Must be "pleasant and friendly" - Fast turnaround for homework - Free and private access - User time is more important than computer time Well suited for implementation on first PCs

Usage and meaning of COBOL?

COBOL (Common Business-Oriented Language) is a high-level programming language for business applications. It was the first popular language designed to be operating system-agnostic and is still in use in many financial and business applications today.

Context-free grammar and BNF

Context-Free Grammars - Developed by Noam Chomsky in the mid-1950s - Language generators, meant to describe the syntax of natural languages - Define a class of languages called context-free languages Backus Normal/Naur Form (1959) - Invented by John Backus to describe Algol 58 and refined by Peter Naur for Algol 60. - BNF is equivalent to context-free grammars

Simula

Designed and built by Ole-Johan Dahl and Kristen Nygaard at the Norwegian Computing Centre (NCC) in Oslo between 1962 and 1967 Originally designed and implemented for discrete event simulation Based on ALGOL 60 Primary Contributions: - Coroutines - a kind of subprogram - Classes (data plus methods) and objects - Inheritance - Dynamic binding

PASCAL

Designed by Wirth, who quit the ALGOL 68 committee because he didn't like the direction of that work. Designed for teaching structured programming. Small, simple. Introduces some modest improvements, such as the case statement. Was widely used for teaching programming in the 1980s.

C

Designed for systems programming at Bell Labs by Dennis Richie and colleagues. Evolved primarily from B, but also ALGOL 68 Powerful set of operators, but poor type checking Initially spread through UNIX and the availability of high quality, free compilers.

Java

Developed at Sun in the early 1990s with original goal of a language for embedded computers Principals: Bill Joy, James Gosling, Mike Sheradin, Patrick Naughton Original name, Oak, changed for copyright reasons Based on C++ but significantly simplified Supports only OOP Has references, but not pointers Includes support for applets and a form of concurrency

Prolog

Developed at the University of Aix Marseille, by Comerauer and Roussel, with some help from Kowalski at the University of Edinburgh. Based on formal logic. Non-procedural. Can be summarized as being an intelligent database system that uses an inferencing process to infer the truth of given queries.

Shortcomings of Machine Code

Each aspect of machine code created in the 1940s was a significant flaw. In particular, it had poor readability, inherited hardware defects, modifiability, and code expression that was not clear and understandable like that of other languages.

Who developed Fortran and what does it stand for?

FORmula TRANslator. Developed at IBM under the guidance of John Backus primarily for scientific, computational programming.

What is JDK and JRE?

JRE is the Java Runtime Environment and it creates a virtual machine within your computer known as the JVM a.k.a. Java Virtual Machine. JRE is specific to your platform and is the environment in which Java bytecode is run. JDK (formerly SDK) is the Java Development Kit. JDK = JRE + development tools.

LISP

LISt Processing language (Designed at MIT by McCarthy) AI research needed a language that: - Process data in lists (rather than arrays) - Symbolic computation (rather than numeric)

What are Three Levels of Computer Languages?

Machine Language is binary numbers made up of bits consisting of 0's and 1's. Assembly Language is computer operations that have been written into English-like abreviations. High Level Langauge is close to assembly but has structures well recognized by humans.

C# (C sharp)

Microsoft and Sun were bitter rivals in the 90s C# is Microsoft's answer to Java C# is very similar to Java with (maybe) some minor improvements If you know Java, learning C# should be easy However: both languages have extensive libraries, and mastering them is a big part of mastering the language.

Precedence and associativity of Operators

Precedence operators mean the order in which they are evaluated as. Associativity operators mean the order in a language would evaluate two identical operations. However, for associativity, there are two ways, which are left-associative and right-associative. Example for an expression like 4+5+4. Associative operators can be utilized as 4+(5+4) or (4+5)+4. depending on the rules in a specific programming language. The majority of the time, the correct way to evaluate the language would be (4+5)+4. For precedence operators, an expression such as 1*4+5, the * has higher precedence over the +, making the * be evaluated first. The answer would end up being 9. The right-associativity of the = operator allows expressions such as a = b = c to be interpreted as a = (b = c)

What are the four access control rules in Java?

Public, Private, Protected and Default. Public classes allow any methods and variables to be accessed within any class, package, subclass, or any other packages stored. Private can only access the methods and variables within the same class only. Protected is when you can access methods and variables throughout the same class, package and subclasses. However, for default you can only access the same class, same package; not subclass however.

Language Evaluation Criteria

Readability: explains how easy it is to read for programmers and non-programmers. Writability: Shows how a program is written. Cost: How much it would cost programmers to learn the language and maintain it. Reliability: Does the language have exception handling, spell checker and etc.

Scripting language

Scripting languages like Perl, Ruby, Javascript and PHP have become important They shine at connecting diverse pre-existing components to accomplish new tasks Cf. shell languages in Unix Typical properties include: - privileging rapid development over execution efficiency -implemented with interpreters rather than compilers -strong at communication with program components in other languages

Repetition is done using recursion

Syntactic lists are described in BNF using recursion - Repetition is done with recursion - E.g., Syntactic lists are described in BNF using recursion - An <ident_list> is a sequence of one or more <ident>s separated by commas. <ident_list> ::= <ident> | <ident> , <ident_list>

Meaning of Syntactic sugar

Syntactic sugar: syntactic features designed to make code easier to read or write while alternatives exist Makes a language sweeter for humans to use: things can be expressed more clearly, concisely or in an preferred style Syntactic sugar can be removed from language without effecting what can be done All applications of the construct can be systematically replaced with equivalents that don't use it

Difference between syntax and semantics

Syntax - the form or structure of the expressions, statements, and program units Semantics - the meaning of the expressions, statements, and program units There's NOT always a clear boundary between the two

C++

Takes C to an object-oriented level. Developed at Bell Labs by Stroustrup Evolved from C and SIMULA 67 Facilities for object-oriented programming, taken partially from SIMULA 67, added to C Also has exception handling A large and complex language, in part because it supports both procedural and OO programming

Two phases: scanning and parsing

The structure of its lexemes (words or tokens) -token is a category of lexeme The scanning phase (lexical analyser) collects characters into tokens Parsing phase (syntactic analyser) determines syntactic structure

How to draw a parse tree?

To draw a parse tree, you can follow these steps: 1) Start with the root node, which represents the start symbol of the grammar. 2) For each non-terminal symbol in the current node of the parse tree, create a new child node and label it with the non-terminal symbol. 3) Apply a production rule to the non-terminal symbol, replacing it with the right-hand side of the production rule. If the right-hand side contains non-terminal symbols, create child nodes for each of them. 4) Repeat steps 2 and 3 until you have derived the desired string or until no more non-terminal symbols remain in the parse tree. 5) Label each leaf node with a terminal symbol that matches the corresponding character in the input string.


Related study sets

Financial Markets and Institutions Week 10 - Derivatives

View Set

RADT 1030 Workbook practice part 3

View Set