Unit 1

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

Write a regular expression that recognizes the set of all strings with two consecutive repeated words

/ ([a-zA-Z]\w+\s)\1/g

Write a regular expression that recognizes the set of all alphabetic strings.

/( [a-zA-Z])+/g

Write a regular expression that recognizes the set of all identifiers. An identifier begins with a letter (lowercase or uppercase) and is followed by zero or more of letters and digits.

/([a-zA-Z][0-z]+)/g

Write a regular expression that recognizes the set of all lower case alphabetic strings ending in a b

/([a-z]\w+)b\b/g

Write a regular expression that recognizes the set of all strings from the alphabet a, b such that each a is immediately preceded by and immediately followed by a b

/(b+(ab+)+)/g

Write a regular expression that recognizes the set of all strings that start at the beginning of the line with an integer and that end at the end of the line with a word

/^\d\w+$/gm

Write a regular expression that recognizes the set of all strings that have both the word grotto and the word raven in them (but not, e.g., words like grottos that merely contain the word grotto)

/grotto\S*raven|raven\S*grotto/gm

Some programming languages are characterized as dynamic. What factors contribute to making a language dynamic?

A dynamic programming language is one that is executed at runtime. They can compile with errors in the code and will run with those errors. Dynamic languages also do not require variables to have types. The runtime execution will interpret the value assigned to a given variable and know what to do with it.

What does it mean to say that a language is Turing complete?

A language is considered to be Turing complete if it can accomplish algorithmic tasks correctly like adding numbers together or comparing if two values are equivalent.

Some languages support more than one programming paradigm — multi-programming paradigm. Explain this statement using a lan- guage such as Scala.

A language that could be interpreted along several paradigms means that functions in a very fluid way. The example of Scala is a combination of OOP and the functional paradigm that allows the language to be very flexible in its user definitions.

What is a declarative programming language?

Declarative programming is where you type a command that says what you want and it is left up to the compiler to figure out how to make that happen.

Compare and contrast general-purpose and application-specific pro- gramming languages. That is, in what ways are they similar and what features contribute to make them different

General purpose languages have a simple execution and task set like html that is just built to put things on a screen and can be interpreted by many different browsers. Application specific is a language that was invented with a specific purpose like SQL. It is for modeling and constructing a database and can not be used for any other purpose.

support for abstractions

How easy it is conceptually to use pre-built tools. Like importing MATH functions and using the square root functionality. You don't need to know the exact way the task is accomplished. You know you can send in MATH.sqrt( X ). And will receive the square root of X back.

Reliability

How likely your program is to fail. Ensuring the right entries are submitted and not used incorrectly.

Expressivity

How simple it is to define things. Like creating your functions or using > or < to evaluate things expressly

How do programs written in interpreted languages get executed?

Interpretation is done as a single step process. The interpreter has control and reads lines one by one and executes them simultaneously.

Compare and contrast compiled and interpreted programming lan- guages. Consider type safety, program execution efficiency, program- mer productivity, and debugging ease

Interpretation scans line by line and provides better error detection mechanisms Interpretation doesn't convert input program into another form so it provides better and earlier debugging Compilation is faster than interpretation. Compilation caches the result and saves time on interpretation where interpretation runs the code line by line each time. Compilation is more efficient

What is a "Just-in-Time" (JIT implementation System? How is it different from an interpreter? What are its advantages?

It is a system that helps a program compile faster, eventually. It converts the program into an intermediate language between yours and machine code. That intermediate code is stored and kept so that it can be quickly turned into machine code at run-time. Used in java and .NET

A preprocessor is often used in C programming. Please describe what a preprocessor accomplishes and its benefits. Does Java have a preprocessor?

It's a step that runs before compiling. These steps would be like importing the libraries that are in the beginning of your files and adding them to the program before adding your custom code. Java does not have a preprocessor because of the way it uses class files.

Some languages use a hybrid approach — both compilation and inter- pretation — to execute programs. Explain this approach

Java uses both compilation and interpretation. It does compile that language but not all the way down to machine code, it makes it into byte code then that code is interpreted by JVM and run.

What is an imperative programming language?

Language based on the Von Neumann architecture and the fetch-execute cycle. Has a lot of variables and standard naming conventions.

What aspects does the syntax of a programming language specify?

Syntax specifies the general form and structure of the language. The set of ruls that defines arrangement of symbols. Closely related to grammar

How do programs written in compiled languages get executed?

The program is executed, sent into a compiler which turns the program into machine code, then sends that code to the machine that then runs it.

What aspects does the semantics of a programming language specify?

The semantics of a programming language specifies the meaning or logic of the language

Why do we categorize procedural and object-oriented languages as imperative?

These languages follow certain patterns and have to have their instructions spelled out very clearly and not much is left up to the compiler for interpretation like a declarative language would

Why do we categorize functional and logic-based languages as declar-ative?

These languages will use vague commands and much of the decision making is being done behind the scenes by the machine and not by the programmer.

orthogonality

Whether or not you are allowed to do things in many different ways. It's simpler if you have more orthogonality because that means there is a specific way you have to accomplish a task and it will be more predictable.

How do you specify semantics of a programming language?

With the semantic analyzer which is a table that maps identifiers. Enforces rules not captured by CFGs. Rules checked at compile time are static semantics and rules checked at run time are dynamic semantics

How do you specify syntax of a programming language?

You allot rules through CFGs and regexp to define what are valid inputs

consistent and common syntax

if your program uses common naming conventions like having if and while as keywords

simplicity

simple in terms of not being too expansive. More complex will have large numbers of tools and functions often using the same name.

List and briefly explain the various phases of compilation

❍ Lexical analysis: breaks apart your code into pieces called token using the key symbols like ( [ ; using regexp ❍ Syntax analysis: this checks the logical structure of the program. Checks that there is a closing bracket for every opening bracket and things like that. ❍ Semantics analysis: generates a hallway step to machine code that is ready to be optimized further ❍ Code generation: actually finishes the process of turning your code into machine code


Set pelajaran terkait

QUIZ 2: FAMILIES OF FUNCTIONS Mathmatics

View Set

Chapter 3 Section 3: Phase Changes

View Set

CCNA 1 v7 Modules 8 - 10: Communicating Between Networks pt 3

View Set

PN Comprehensive Online Practice 2023 A 12.11.23

View Set

Government Insurance Programs Overview

View Set

Business Law II-Exam 4 (Chapters 41, 42, 43)

View Set

Ch 5 Ratios & Proportion Vocabulary

View Set