Mimir:Spring 2014 Lectures


 * Home
 * Textbook

= Week 1: Introduction: categorizing programming languages = Content author Mike Jonas

= Week 2: Compilers, interpreters and BNF grammars = Content authors (Group #1) Colby Johnson and Pauline Wilk

Outline by Casey Eyring


 * What drives programming languages?
 * A Grammer. Explain why this matters.
 * What is Backus-Naur Form (BNF)
 * Production Rules
 * Non-terminals
 * Terminals
 * Give example of BNF grammar


 * Compiled Languages
 * Talk about what compiled languages are
 * Show the diagram that Prof Jonas drew in class how we go from source to exec
 * Give an overview of the different phases
 * Preprocessing phase
 * Parser
 * Code generation
 * dynamic linker


 * Interpreted Languages
 * Do the same thing here. Show the diagram from class.


 * How is Java different from other languages with regard to compiled vs interpreted?
 * e.g. compiles into classes > run in Java Virtual Machine > which runs on computer

Grammars
Grammars are used to completely specify syntax rules of languages. The structure imposed by a grammar gives a systemic way of processing expressions.

A grammar consists of four main pieces identifiers, terminals, non-terminals, and production rules. A grammar must contain at least one rule and this rule must have an identifier. Identifiers distinguish rules from other rules, while also acting as a reference for the rule. They must begin with either an alpha character or an underscore. Following can be either an alpha, a numeric, or an underscore. Non-terminals are symbols that are used to write out the grammar. They can be expanded and are represented in < >. Terminals are symbols that appear in the language generated by the grammar. They are written exactly as they are, inside single quotes ' '. Production Rules are composed of of a non-terminal followed by ::= followed by a combination terminal &/or non-terminal.

The main notation used to represent grammars is Backus-Naur Form or BNF for short. This notation looks a lot like HTML and is used to describe the structure of a language.

Additional meta-symbols of BNF are:

 |     means "or"

Example of a BNF Grammar: production rules for context free grammar (CFG) of an identifier
 ::= |  ::=  |    ::= | | ::= _ ::= a | b | ... | z | A | B | ... | Z ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

This captures legal identifiers such as:

count count1 _count2 _count34 __count_

A non-legal identifiers would be:

0count

Compiled and Interpreted Languages
Programming languages usually fall into one of two categories, compiled or interpreted. With a compiled language, code you enter is reduced to a set of very efficient machine-specific instructions before being saved as an executable file. With interpreted languages, the code is saved in the same format that you entered. The benefit of a compiled language is that it runs faster because once it has already been translated through the compiler, it only needs to be loaded and executed each following time. Where as interpreted languages are usually less efficient than compiled languages because each time the program is run, the language needs to be parsed, interpreted, and executed.

Compiled languages
Compiled languages do not contain source code but can run without it.




 * The Preprocesser is a very powerful step in compilation and generally used by C++.
 * The Parser applies grammar and makes sure you're following the rules of the language.
 * The Code Generation creates a relocatable object code.
 * Optimization
 * The Executable generates machine code.
 * The Dynamic Linker links all the files together.

Interpreted Languages
Interpreted languages contain the source code.




 * The Executable does not generate machine code, it just runs the code.

Imperitive Languages
Imperative languages have been around for a long time. Some of the most basic languages are imperative, such as FORTRAN. An important paradigm in imperative languages is that they change the state of a machine. The lower-level languages communicate through Machine Code. Most of the hardware in your computer uses imperative languages. There are some higher-level imperative languages, such as Perl. Perl : Practical Extraction and Report Language

This is considered a higher-level languages because it uses variables but still follows the same paradigm as a low-level imperative language. These languages can be more traditionally looked at as a protocol or checklist, each step being an instruction to a larger goal.

A key paradigm for these type of languages is their ability to utilize assignment statements. These statements perform an operation on a piece of information that is contained in the memory, then store the results back in the memory. Higher level languages are able to perform certain computations on the information before it is put back in memory.

Examples of imperative languages
 * FORTRAN
 * COBOL
 * BASIC
 * Perl
 * Python
 * Visual Basic
 * Visual C++
 * Java
 * PHP
 * Ruby
 * .NET

= Week 3: CLOSED =

Snow storm...no classes

= Week 4: Programming paradigms; an overview of Perl = Content author (Group #2) Sinisa Vidic

Outline by Pavlos Myroftsalis


 * How we categorize Programming Language?
 * Programming Paradigms. What is a Paradigm?
 * Imperative - give a definition and a language that Prof Jonas used as an example
 * Functional - definition and example
 * Procedural - definition and example
 * Logic - definition and example
 * Visual- definition and example
 * Object Oriented - definition and example
 * Multi-paradigm - definition and examples


 * Perl - give a one paragraph introduction about the history of the language
 * A couple of paragraphs discussing its basic structure (i.e. it's a statement based/imperative language)
 * add an example to highlight that (all examples should be in a wiki code box)
 * Types in Perl - one paragraph discussion of three types: scalar, array, hash
 * Scalar - add an example to show syntax
 * Array - add an example to show syntax
 * Hash - add an example to show syntax
 * Print statement - on paragraph discussion of what it's used for
 * add example to show syntax on how to construct printed strings via concatenation operator "."
 * Conditionals - one paragraph discussion of the two types if & if/else
 * add example to show syntax of if
 * add example to show syntax of if/else
 * Loops - one paragraph discussion of both while and for loops
 * add example to show syntax of while loop
 * add example to show syntax of for loop
 * File I/O - one paragraph discussion of file i/o
 * add example to show syntax of how to read from a file (use a while loop like we did in class)
 * Subroutines - one paragraph discussion of subroutines (i.e. what they are)
 * add example to show syntax of a subroutine, specifically how to pass parameters

Programming Paradigms. What is a Paradigm?
Paradigm is a model or a pattern by which a programming language constructs its programs. There are six main programming paradigms: imperative, functional, logic, visual, procedural, and object-oriented. Most of older languages are based on one of the paradigms, modern languages on the other hand are developed to include multiple paradigms.

Imperative - language is a statement driven.
 * Perl, MS-DOS batch, csh/bash

Functional – language based on functions
 * LISP (times (plus 1 2) 3)

Logic – language that uses logic to perform computations
 * Prolog : A cheetah is a mammal, a mammal is an animal, is cheetah an animal?

Visual – language that uses graphics to express code/algorithm
 * AppInventor, scratch, snop

Procedural – language groups statements of code into a procedures (aka subroutines& functions)
 * C, Pascal, fortune BASIC

Object-Oriented – language organizes code into classes to encapsulate information
 * C++, Java, PHP

Multi paradigm – language that supports more than one paradigm
 * C++, Java, PHP, Perl, Python, C#, JavaScript

Perl History
Perl was developed by Larry Wall in 1987 to be used as a general Unix scripting language. Perl stands for Practical Extraction and Report Language and falls under the imperative paradigm. Perl is influenced by following programming languages: AWK, Smalltalk, Lisp, C, C++, sed, Unix shell, and Pascal. Perl interpreter is written in C language and consists of approximately 150,000 lines of code.

Basic Structure
Like every other modern high-level programming language, Perl includes: scalars (variables), arrays, hashes, subroutines, loops, conditionals, regular expressions, objects, file I/O, and many more features. It is a dynamically typed language and uses leading sigils to identify different data types. With Perls' vast features makes it a flexible language to code in. Since being a high-level imperative language, Perl syntax is executed by the interpreter as it's being read. Perl uses pound(#) to distinguish between comments and code and a semi-colon to single end off line of code. $score = 0; print "Hello Player. \n"; while($score < 2) {    print "I win \n"; $score = $score + 1; } The above code has one scalar $score with assigned value of 0, in Perl scalars are represented by $ sigil. Next, the interpreter would read the print statement and since print is used to display content on to a screen, in this case it will output Hello Player and move to a new line which is represented by \n command. Now we come to a while loop, they are responsible for executing blocks of code multiple times until a specified condition evaluates to false. In the above while loop we want to output I win on a new line each time while loop executes. The condition being  means that when scalar $score is less than 2 the code inside the while loop gets executed. Every time a while loop runs it increases $score by 1 which is represented by, this prevents an infinite loop since it will make the condition sooner or later evaluate to false. In the above example this will occur after the second time while loop executes as the value of $score will be 2 and 2 is not less than 2 at which point the interpreter will end the while loop and continue to the next line of code.

Data Types
Perl has many data types but most common ones are scalars, arrays, and hashes. Scalar is an identifier of a memory location which contains information. It is a single value that may be a number, a string, a filehandler, or a reference. Array is simply a collection of scalars. Hash is a map that associates a key(string) to a value(scalars), also known as an associative array.

Sigil  Type $    scalar @    array %    hash

$name1 = "john"; $name2 = "bob"; $name3 = "david"; $num = 100;

The above code shows three scalars named $name(1-3) with each one having a single string value represented by double quotes(" "). The fourth scalar has a number value of 100, numbers do not require double quotes unless it is being made into a string.

@names = ($name1, $name2, $name3); or @names = ("john", "bob", "david");

Here we have two arrays with identical collection of data implemented in two different ways. First array is filled with the scalar identifiers from the first example, while the second array is filled with string values.

%bio = ("john" => 50,         "bob" => 37,          "david" => 20,         ) Hashes are arrays but they are more advanced. Hashes have the ability to associate a key with multiple values, its like an array within an array. In PHP language this is called an associative array. The above  hash has name strings as keys for the numerical value which we can assume to be persons age.

Print Statement
A print statement is found in most if not all modern high-level programming languages. Its function is to output information to the screen or a file in order to debug a program or simply make data visible to the user. It is one of the most frequently used statements in Perl. Print statement can be code to simply display a number or a string on the screen and complex as displaying large amounts of data from arrays, hashes, scalars, in a strictly specified format for easier reading/viewing of the data.

print "Hello World!";

The above code outputs Hello World! to the screen. This is the simplest print statement.

print "Hi, my name is ". $name. "."; The above example show how to concatenate to string using "." operator. It would output Hi, my name is (value assigned to $name).

Conditionals
Conditionals are statements used to evaluate conditions on bases of true or false in order to perform different computations. Most common conditional statements are if-else and else if statements. If-else statement evaluates one boolean condition and does the set of instructions provided under the true or false state. In Else if statements multiple conditions get to be evaluated and the first true condition gets to be executed and the rest of the conditions get skipped.

$student = "freshman"; if($student eq "senior") {   print "Almost to the finish line."; } else {   print "So much more to learn." }

The above is an if-else statement. A scalar $student is assigned a string value freshman. If statements conditional is setup to evaluate if $student is equal to a string "senior", if it's true then it displays Almost to the finish line. Otherwise it displays the else code which is So much more to learn.

$student = "senior"; if($student eq "sophomore") {   print "Make progress."; } elsif($student eq "junior") {   print "Soon to be big dogs on campus."; } elsif($student eq "senior") {   print "Yay! Almost to the finish line."; } else {   print "So much more to learn." }

Unlike if-else statement, else-if statements are a bit more complex in nature but they eliminate use of multiple if-else statements. The above example shows the Perl syntax of an else-if statement. In if-else example the interpreter had to only check one condition, in the above example there are multiple conditions to check. The first condition that is evaluated to "true", displays the given string. If once again all three conditions are false the interpreter will display the string specified under else statement. In this case  condition evaluates to true thus ''Yay! Almost to the finish line.'' gets to be displayed on the screen.

Loops
Loops are used to repeat a statement multiple times until a condition evaluates to false. While loop acts like a repeating if statement, as long as the condition evaluates as true the code inside the while loop will run over and over. For loops are a bit different, they are used to loop through a preset number of times. Do-while loop is used to run the code inside it at least once before the condition gets evaluated. If the condition evaluates to true, the code inside gets to be executed again.

$count = 0; while($count < 10) {   print "$count \n"; $count++; ) The above example of a while loop will output current $count value on a new line and increment $count by one each time the while loop evaluates to true. In this case it will print 0-9 before while loop condition evaluates false and exits the loop.

for($count = 0; $count < 10; count++) {   print "$count \n"; } The for loop syntax is a bit different than while loops but it has cleaner code. The for loop conditional needs three parameters to function. First parameter is to initializing a $count scalar and assign a starting numerical value. Next parameter is the actual condition to be evaluated and finally the last parameter is to increment our scalar $count each loop run. The for loop in this example will output the same exact result as in the while loop example. $count = 0; do { print "$count \n"; $count++; }while($count < 10); Do-while loop syntax is a bit strange compared to while and for loops. Nonetheless it's a handy loop to have, sometimes you want the code to run at least once and than decided if the code needs to be run again or move to the next line of code. These are the situations in which the do-while loop is useful for. It first runs the block of code inside the curly brackets and then evaluates the while condition to decided if it needs to run the block code again or not. The result returned from the above example will be same as the previous two examples.

File I/O (Input/Output)
Perl is a powerful language and with it come some very useful features. One of these features is file I/O, in other words ability to read and write data to a file. This a great feature to have because it gives the developer the ability to store data in files rather than using memory if the data is not being used at that moment and time.

open (FILE, "data.txt"); while() {    print "$_ \n"; } close(FILE);

In Perl reading a file is very simple. An example above shows how to read the contents of a file and output each line on the screen. Subroutine open is used to open the file stream, it requires two parameters, first parameter is a filehandle name which we call FILE(can be anything), second parameter is a actual file name or location of the file if the file is not in the same directory as the Perl script. Once the file stream is open for reading we use a while loop to read each line in the file and output it to the screen using print statement. In Perl $_ is a default scalar that while loop uses to store the data read from the file. After all the data was read and displayed on the screen, file is closed by close(FILE) subroutine.

Subroutines
Subroutines are blocks of code that performs a specific task. Once created they can be called multiple times within the program or implemented into other programs with ease. Subroutines eliminate code duplication, makes code cleaner, and easier to maintain. Unlike in other programming languages where we need to specify the parameters (if any) when creating the subroutines/functions, Perl has a special way of creating parameters. In Perl when creating a subroutine no parameters need to be specified and yet when calling the subroutine parameters can be passed. The trick is that all parameters that get passed are stored inside a default @_ array, to use the parameter in the subroutine a local variable would be created and assigned to an element in the @_ array. The example bellow shows this visually. sub readFile {   $name = $_[0]; open (FILE, $name); while() {     print "$_ \n"; }   close(FILE); } readFile("data.txt"); <--- calls the subroutine with one parameter Let's say we want to read multiple files in our script and we don't want to write duplicate code of reading a file. So we create a subroutine  that will make our code cleaner and maintainable. In the above example we will use the code from the File I/O section and create a subroutine out of it. In Perl subroutine is specified by keyword  followed by the name we want to call the subroutine. Now, in order to open a specified file we need to use a parameter and in Perl all parameters that are passed during the subroutine call are store in an array. To access the passed parameters we create a local scalar in this case we called it $name and we assign it to the default  array and we want the first parameter so it's element 0. Now we have captured our parameter inside the  scalar and we can use it throughout our subroutine. In our case our parameter represents the file name or its location that we want to read. To call the new subroutine we simply do this

= Week 5 Language concepts: variable types, scope, & implementation = Content authors (Group #3) Joshua Anderson and Forrest Surprenant

Outline by Sergiu Mihu
 * Variable types
 * What does type mean for a variable?
 * Why is variable type important? (why variable types are important - memory reservation...)
 * Strong vs weak typed language
 * Definition with examples
 * Dynamic vs static typed language
 * definition with examples
 * Data types (each with definition and a simple example if needed)
 * Primitive data types
 * Discuss/list common ones (i.e. int, flat, char, bool)
 * Complex data types
 * i.e. structs/records, classes
 * Variable scope
 * Definition
 * Scope levels - define and discuss their uses
 * Global
 * Parametric
 * Local
 * Variable scope in OOP (reasoning behind using local and global in OOP)

Variable Types
In computer programming, types or datatypes help classify one of the many different types of values a variable can hold. Some common datatypes include boolean (true or false), string, and integer. In a typed language such as Java, variables must have a type associated with them. The type of the variable is important because it determines a variety of characteristics of that specific variable like:
 * Possible values that can be assigned
 * The actual meaning of the variable
 * The operations one can do with variables of a certain datatype

For example we have some Java code below:

int count = 10;

That one line of code is saying we have a variable called  and it is of type   which in Java and many other languages is short for Integer. The Integer type ONLY allows values that are whole numbers like: -5, 0, 5, 10, 12, 20 etc. If we were writing a Java program and we do something like  and then we compile this up, we're going to get a syntactical error and the compile will fail. It will fail because we specified the type of this variable  as an.

Why are data types important?
In computers, memory is where data and information about programs is stored. That memory is made up from binary digits known as bits stored as either a 0 or 1. Computers access these bits not as individual bits, but rather as a collection of bits usually consisting of 8, 16, 32 or 64 bits. The collection length on a machine is determined by how many simultaneous operations a CPU can process. A basic rule of thumb is the larger the number of bits, the larger chunk of data can be processed.

Now that we have context of memory, let's move onto how data is stored. Any piece of data, like a variable that has the value of 10, is stored in memory at an actual physical location - a location is known as an address. Obviously it's difficult for us to know exactly where this location is or how to access it. This is why we name this address with a variable.

Variables are a much easier way of reserving a spot in memory to hold our information for our program. This way we don't have to remember random numbers like 234098.

When we specify the datatype of a variable, for instance an, we are setting aside an actual size of memory for our data. The number of bytes that can reserved for a data type can vary based on which programming language you're using. Like we said above, we have a variable that is of type. When this line of code gets hit, the computer knows exactly how much memory to reserve because we used the data type.

Strong vs Weak Typed Languages
There is a significant difference between a strong vs weakly typed language. We have already gone over a lot regarding strongly typed variables like integers and strings. When using a language with strong types, that value is known to have specific characteristics and those characteristics cannot change.

Conversely with weakly typed languages, the type and characteristics are determined on how it is used. For example, if we have an expression like this: a = 5; b = "10"; c = a + b;

Depending on the language, the value of  will be 5 + 10 if the code can interpret "10" as the integer value 10.

We could also make the  variable equal to   and the code will convert that string value to whatever ASCII values that represents.

If we did this in a strongly typed language, the compiler would through an error as any string value assigned to an integer typed variable isn't allowed.

There are of course advantages to each. For strongly typed languages, the programmer is forced to create the behavior of the program explicitly. There is no "hidden" behavior where another programmer could be modifying legacy code and the parameter names are not descriptive enough causing that programmer to have no idea what type of variable their working with.

For weakly typed languages, the advantage is writing less code. Also, it maybe faster because there is no overhead for processing and remembering the unique data types a strongly typed language has to do.

Dynamic vs Static Typed Language
Dynamic typing and static typing cause a good amount of confusion among programmers. Below will define in detail each one and also include an example snippet of code.

Dynamic typing
A dynamic type programming language is one that the type is interpreted at runtime. The pros of this type of language is that one can write less code quicker as they don't have to specify the type of each variable they use. The downside of this is when one has to error check. Because of the type being computed at runtime, there's no type-checking before hand so in order to test, a programmer must run the program and clean-up afterwards. Common languages that are dynamically typed include Python and PHP. Below is some Python code:

firstName = "Joshua" firstName = 10;

We have defined the variable name  as a string value "Joshua" - then right after that we changed the value to an integer 10. In a dynamically typed language, this would run perfectly fine and the value (until you change it again) of  would be 10.

Statically typing
In a statically typed language, the type is computed at compile time instead of runtime. If when compiled and there are no errors, then the code is guaranteed to work, syntactically. One of the many pros of a static typed language includes the speed at which a programmer can fix bugs and type mismatches because of this precision. A downside of course is this requires writing more code and making sure before compiling that all variables are typed properly. Popular programming languages that are statically typed include C, C++, Java, and C#.

// Example from above. firstName = "Joshua" firstName = 10;

string firstName = "Joshua"; int age = 22;

Above I put the example we had for a dynamically typed language and below that an example showing how it would be written correctly in Java, a statically typed language. This is a statically typed language because all variable names AND their types must be explicitly declared. If we attempted to assign the value of  to , we would get an error at compile time telling us that it cannot evaluate an integer to a string.

Primitive data types
Primitive data types are mostly found in statically typed languages such as Java. Like we said above, this means that all variable names and type must be declared explicitly in order to pass the type-check at compile time. Below is a table of the more common primitive types in statically typed languages.

Complex data types
When thinking of a common complex data type, the array has to be most popular. A complex datatype is any type that holds multiple independent values. An array is a complex data type because it is one object made of up a number of indepedent values. An example in Java:

int songs[10];

This statement is saying we want to define an array variable named  and to set aside 10 integer values in memory. It's important to note here that we did NOT initialize any of those 10 integer values inside the array, but rather just allocated the space we want to in memory.

Complex data types can also be types that you define yourself as the programmer. In Object-oriented based languages, we can create a new class which will have properties and functions inside it that actually define what the class is. For example we have this Java code:

// Creating the class Car. public class Car { private int year; private String make; private String model;

.	.	.

public setYear(int y) { year = y;	}

public getYear { return year; }

.	.	. }

// Using the Car class. Car myCar = new Car; myCar.setYear(2013); System.out.println(myCar.getYear);

This code above is creating a new class titled  which has 3 properties (year, make, model) and what I showed, 2 methods. Of course there would be "setters" and "getters" for the other properties as well. However, we now can use this Class and create a new object, or variable, of type. Once the line  compiles, we now have initialized a new object of type   and can use the public properties/methods inside that class throughout the program.

One can see exactly why the difference between a primitive data type and a complex data type is significantly different.

Variable Scope
The scope of a variable is what defines the availability of it during the executing of the program. Some programmers say that the scope of the variable is actually a property in it of itself. In other words, a variables scope is the area of a program where that specific variable has meaning and thus being visible to the code within that scope.

In most programming languages, there are different levels of scope - Global, Parametric, and Local.
 * Global variables are commonly known as variables with an indefinite scope, or visible to the entire program. Programming languages handle a global variable differently. For instance, many languages like C or C++ there is no actual  identifier, however if there is a variable defined outside a function, then that variable is treated as having "file scope" which means it's visible everywhere in the file. However in PHP, there is an actual   keyword you can place in front of defining a variable, and then you can use that variable anywhere that file is included in. For example:

// config.php 

// index.php 

In those two snippets of code, we are defining a GLOBAL variable $SITE_NAME in a file named config.php. Then in a completely different file, index.php, we are including that config.php file and using the global variable we defined.

Global variables are often viewed as bad practice because it can create confusing, and more error-prone code. Code in a more larger project can be both read and more importantly maintained when the scope of variables are limited to their specific code block or function. Using global variables can cause headaches because in any part of a program, they can be modified (if their not memory protected which some languages provide), which makes it difficult to remember exactly their intended use. Below we will introduce better ways to manage your variables within a program.


 * Local variables are ones that can be accessed and used within certain functions; it is given local scope to wherever it may be. For example, say we have a block of code like below:



When we try to run this PHP code, we will get an error. That is because we are trying to echo a variable that is NOT in scope.

In our function, we defined a variable. Then directly after the  which closes that scope, we went ahead and echo'd out that same variable $a. This is wrong because the PHP file doesn't have access to LOCAL variables inside functions.


 * Parametric variables can be accessed inside a method or function which accepts it as an argument. This is how you can solve the problem of using global variables in a program - by passing values to functions instead of creating global variables so that function can use them.



This snippet above demonstrates the power and simplicity of a parametric variable. We have a class which has a private property  ... the only way to set this value would be to create a custom setter function and pass that function a value we'd like to use. In the function  we specified arguments of   and   which we will accept in the function as parametric scoped variables - they can only be accessed within this function.

Using this concept, we can create a program that is harmonious because we always know what the variables are, and their intention. If we put  in a global variable, we may never know how that variable is even defined, never mind where. Using it this way, we are complete control of where that value is set and who has access to it.

Conclusion
This chapter goes over a variety of significant programming fundamentals for anyone who is thinking of learning how to code. The variety of programming languages out there all implement this information uniquely, but the principal is always the same.

= Week 6 Language concepts: parameter passing by value & reference; an overview Lisp = Content authors (Group #4) Jacob.McQuaid and Jason Bouchard

Outline by Daniel Mamede
 * Programming Language Generation
 * First Generation - machine language
 * Second Generation - assembly lanaguage
 * Third Generation - modern programming language (i.e. ones that are compiled or interpreted)


 * Parameter Passing
 * Pass by value
 * Provide example in Java
 * Pass by reference
 * Provide example in C++
 * Also show how in Java and C you can work around it using objects or pointers, respectively
 * Briefly mention others like In/out but don't discuss them


 * LISP
 * A little history and background
 * Give a brief overview of the language with Lisp example of each
 * Basic components
 * atoms
 * lists
 * s-expresssions
 * Some common functions
 * Assignment: set (remind readers to quote arguments with ' to prevent evaluation)
 * Math functions: +, -, *, /
 * List functions: list, cons, append, car, cdr
 * Defining functions: defun
 * Conditional functions: cond, null

Programming Language Generations
As our power of knowledge grows from generation to generation, so does that of which we create. Every generation of programming language is built on top of its predecessor's accomplishments, spawning more powerful grammar and therefore more powerful functionality with each epoch. Currently, there are three generations of programming languages.


 * First Generation languages are Machine Code. These cryptic instructions coded by the programmer as certain patters of 1s and 0s are executed directly by a CPU, there is no compilation or interpretation. The instruction is a very low level task, the lowest level--a hardware level task--such as a jump, a copy of data from one register to another, a comparison of data, or an arithmetic function on data in a register. Furthermore, not all CPUs have the same machine code instruction set, though some families of processor may.


 * Second Generation programming languages, known as assembly languages, have a one-to-one relationship with machine code, i.e. one statement in assembly language translates to exactly one statement in machine language. The difference of the two being in grammar: in assembly the programmer can read and write code much easier using labels and operations that are represented as text, where in machine code it would be represented only as binary values.

In machine code to copy data from one register to another could look something like this... 01110001 10001111 01110010

In Assembly language the same instruction could look something like.. CPY 0x71 0x72

As you can see it is much easier to decipher what the code is doing in assembly language--copying the contents at memory location 0x71 to location 0x72.

Again like first generation languages, the instruction set and specific grammars of a second generation programming language are CPU dependent. Coding on this type of platform requires specification documents that include coding syntax, register names, the built in operation names, and CPU electrical hardware information, per CPU.

Unlike the first generation, assembly language requires a conversion process called assembly, to convert the code into machine language, the only language a CPU knows.


 * Third Generation programming languages have a one-to-many mapping with assembly and machine language, i.e. one statement in a third generation language will translate to numerous statements in a first or second generation language. At this time compilers and interpreters were created; there role is to handle the conversion of source code to machine code, where the one-to-many translation occurs. Another key characteristic of a third generation language is its hardware independence, the grammar of the language is no longer dependent on the CPU.

Parameter Passing
Each programming language handles parameter passing in its own manner, defining how information is sent to the function, either by copying the value, or by allowing the function to use the memory location containing the data, and if the modification made to the parameters inside the function is seen in the scope where the function was called.


 * Passing by Value creates a new variable in the scope of the function and initializes it to the value of the argument. When the function returns the copy is destroyed (goes out of scope) and the variable used as the argument in the function call will retain its original value prior to the function call.

Example of pass by value in Java: public static void main {   int x = 5; passValue(x); //this call creates a copy of the value of x   System.out.println("The value of x = " + x); //the value of x here is still 5 }

private static void passValue(int n) { n = 6; //this value of n only exists in the scope of this function }

Sample output: The Value of x = 5


 * Pass by Reference gives the called function access to the memory location of the parameter. Thus if the value is modified inside the function the variable that was passed will be modified when the function returns. C++ has a unique implementation of this concept using the & (address of) operator:

void main {   int x = 5; passReference(&x); //this call passes the address of the variable x   cout << "The value of x = " << x << endl; //this will print the value 6 }

void passReference(int& n) { n = 6; //This is modifying the value at the address of x }

Sample output: The value of x = 6

To achieve an emulated pass by reference in C we must pass the value of a pointer: void passPointer(int* p) { *p = 6; }

void main {	int* x;	x = new int; *x = 5; passPointer(x); cout << "The value of x = " << *x;

delete x; }

Sample output: The value of x = 6;

In Java you must pass a primitive type as an array to make it a reference: public static void main {   int [] x = new int [] {5}; passArray(x); System.out.println("The value of x = " + x[0]); }

public static void passArray(int [] n) { x[0] = 6; }

Sample output: The value of x = 6

There is also other ways of passing values in some languages with "in" and "out" keywords. In would indicate input into the function, and out indicates output which would have the same effect as a pass by reference on the parameter.
 * Other types of parameter passing

The Basics of LISP
“LISP” is a simple acronym, standing for two words, list processing, and was created in 1959 by a man named John McCarthy (source). This parenthetical language was created to deal with data strings more easily than other languages that existed during the late 1950’s (source). LISP is often used for the development of artificial intelligence and is among the oldest remaining programming languages (source).

The language is highly parenthetical and uses parenthesis to designate the beginning and end of a statement, also without statement terminators such as the semicolon. The statements in LISP are made up of three basic parts: atoms, lists and S-Expressions.

Atoms- Much like their namesake--the atom-- these are the 'things'--or the building blocks--in the code that cannot be broken down further while retaining any kind of meaning (source 2). Atoms can be letters or--otherwise--just single characters (source 2). //Here is an example of a regular atom) (set 'letter '(c)) // This sets variable "letter" to the value of "c".

Atoms are not always single character, though all single characters are atoms, words are considered atoms as well and strings--potentially being sentences long--can be atoms as well if the proper symbols are applied (source 2). Here is a word being used as an atom: (set 'word '(card)) //The variable "word" holds the value of "card", the atom.

Here is a string atom: (set 'sentence '("This part is considered one element, or atom")) //This is NOT a list.

A string can only be an atom if it is enclosed in double quotation marks ("") as shown above (source 2). Arrays can also be used as atoms (source 2).

Lists- Lists are best described as a collection of atoms and are defined by LISP as a series of atoms with white space between them--this allows strings and words to be considered atoms (source 2). An empty list is unique in that it is considered as both an atom and a list (list 'example '(This is a list because there are no quotes, each word is a separate element)) //Each word is its own individual atom. This would still be a list if it was defined using set instead of list.

S-Expressions-Both atoms and lists are S-Expressions (source 3). If an S-Expression can be evaluated and continues to hold meaning then it is called a form. A form is usually a mathematical operation or is applying a function to something. If a form is a list then the first element is held to be the function name and the characters following it are evaluated towards that function (source 3). Here is a mathematical S-Expression, or a form: (+ 5 5) //This form evaluates 5 and 5 through the addition function/operator it evaluates to equal 10.

In order to set an S-Expression for evaluation the " ' " character previously applied would be removed. A regular S-Expression can also be evaluated (source 3). Here the atom S-Expression is evaluated: (set 'a (10)) (a) // The number 10 is set to be evaluated and returns just 10.

Normally evaluating an alphabetical atom would return an ASCII value, this can be avoided by assigning letters or words to a variable (source 3). EX: (letter) //This evaluates the atomic symbol "letter" and returns its previously set value of "c".

The functions used in this portion are further explained in the following section.

Basic Functions of LISP
The functions in LISP are as varied as any other programming language serving a wide range of purposes from assignment to evaluation and conditional statements. The following section is an overview of the following types of functions in LISP with an example of each: assignment, list construction, conditional functions, mathematical operators, and defining functions.

Assignment
The functions setq and set can be used to create both atoms and lists (source 4). The main difference between set and setq is in how the expression is written, the variable that you want to assign in a set expression is preceded by a single quote(')(source 4&5).

(set 'myVariable '(Hello World)) (print myVariable) // evaluates to "Hello World"

(setq myOtherVariable '(Hello World)) (print myOtherVariable) //Still evaluates to "Hello World"

If a set expression does not have a single quote before it then the named variable will be evaluated before the data has been allocated (source 4). (set myVariable '(Hello World)) (print myVariable) // Returns an error Setq can also be used to set more than one variable (source 5): (setq numberOne '(One)     numberTwo '(Two))

(print numberOne) // Returns "One" (print numberTwo) // Returns "Two"

Mathematical Operators
Mathematical operators are among the simplest of functions in LISP and are written in prefix notation, that is to say that the mathematical operators appear before the other characters in the S-Expression. The basic mathematical operators in LISP are +, -, *, and /.

+(plus)- This symbol is quite familiar to anyone who has taken fundamental mathematics in Mrs. Whatever's "Adding for Idiots" class in preschool. The symbol is used differently in LISP than in other programming languages in terms of the syntax in which it is used, it only needs to be used once in an S-Expression and it is the first character in the list. (+ 5 5) ;This adds five and five together in order to make 10. The number of numbers in an expression is not limited, you can add two things together--as shown in the example above--or you can add ten: (+ 10 10 10 10 10 10 10 10 10 10) All with just a single operator.

-(minus)- This operator subtracts the characters following it from one another, the subtraction operator--like all other operators--acts from left to right unless it is specifically told not to. The same rules apply to the subtraction operator as to the addition operator. (- 5 1) ;This subtracts 1 from 5

*(multiply)- Operator uses multiplication on all of the numbers following it, it is bound by the same rules as the previous operators. (* 20 5) ;multiplies 20 and 5 together for a value of 100. (* 10 10 10 10 10 10 10) ;Returns 10000000

/(divide)- This operator is used to...divide the values following it, it is bound by all the previous rules about operators. (/ 4 2) ;Returns a value of 2 (/ 9 3 3) ; Returns a value of 1. More complex mathematical expressions may require multiple operators, separated by parenthesis. (* (+ 2 2) (/ 49 7)) If an expression carries more than one operator then the traditional order of operations (PEMDAS) is followed.

List Construction
List operators consist of functions that help construct a list and others that help retrieve specific elements from them. The set and setq functions can be used to create lists but they are not list specific like cons, append, car, cdr. List-This function, quite simply, constructs a list similarly to set. (list '(Words separated by white-space are considered to be a list)) Car-This function is used to return the first element of a list, usually this is an atom (source 6). The function does not remove the first element from the list, it merely returns it to the user(source 6). (car '(words separated by white-space are considered to be a list)) //Returns "words" as the car of the list If a list contains lists as elements and not atoms then the first list is returned when car is used (source 6) (car '((this is the first list) (this is the second list)) // This would return "this is the first list Cdr- This function returns all the characters in a list after the first character in a list and, like car the cdr function does not delete the characters in question from the original list (source 6). (cdr '(The second through the last elements are returned by cdr)) // This returns "second through the last elements are returned by cdr" If a list is made up of list elements then all but the first list are returned (source 6). (cdr '((this is the first list)      (this is the second list)       (this is the third and final list)) //This line returns "this is the second list" and "this is the third and final list" Cons- This function is like the list function in that it constructs list-type S-Expressions (source 7). This function can be used to construct lists element by element. However cons cannot create a list from scratch, even if the original list is empty (source 8). When adding an element to a list the element that the programmer wants to add is preceded by a single quote(') (source 8). (cons 'word (two))// This line adds the "word" to the list containing the "two" element. Cons can be used to add to an empty list, effectively--but not technically--creating a list from scratch (source 8). (cons 'firstElement )//The list now contains one element: "firstElement"

Append- This method is also used to construct a list, like cons and the list function itself. However, this function is only used to join two smaller lists together into a longer one (source 9). (append '(a b c) '(d e f)) // Creates a list of "a b c d e f". This differs from cons by allowing more than one element to be added to a list (source 8) The append function differs from the cons function by allowing the lists to be combined in any way (source 8). In a cons expression the element being added is always at the front, in append both lists are being added together. (append '(d e f) '(a b c)) // Creates a list of "d e f a b c". (cons 'a (b c d)) // This will always create a list of "a b c d"

List Construction
List operators consist of functions that help construct a list and others that help retrieve specific elements from them. The set and setq functions can be used to create lists but they are not list specific like cons, append, car, cdr. List-This function, quite simply, constructs a list similarly to set. (list '(Words separated by white-space are considered to be a list)) Car-This function is used to return the first element of a list, usually this is an atom (source 6). The function does not remove the first element from the list, it merely returns it to the user(source 6). (car '(words separated by white-space are considered to be a list)) //Returns "words" as the car of the list If a list contains lists as elements and not atoms then the first list is returned when car is used (source 6) (car '((this is the first list) (this is the second list)) // This would return "this is the first list Cdr- This function returns all the characters in a list after the first character in a list and, like car the cdr function does not delete the characters in question from the original list (source 6). (cdr '(The second through the last elements are returned by cdr)) // This returns "second through the last elements are returned by cdr" If a list is made up of list elements then all but the first list are returned (source 6). (cdr '((this is the first list)      (this is the second list)       (this is the third and final list)) //This line returns "this is the second list" and "this is the third and final list" Cons- This function is like the list function in that it constructs list-type S-Expressions (source 7). This function can be used to construct lists element by element. However cons cannot create a list from scratch, even if the original list is empty (source 8). When adding an element to a list the element that the programmer wants to add is preceded by a single quote(') (source 8). (cons 'word (two))// This line adds the "word" to the list containing the "two" element. Cons can be used to add to an empty list, effectively--but not technically--creating a list from scratch (source 8). (cons 'firstElement )//The list now contains one element: "firstElement"

Append- This method is also used to construct a list, like cons and the list function itself. However, this function is only used to join two smaller lists together into a longer one (source 9). (append '(a b c) '(d e f)) // Creates a list of "a b c d e f". This differs from cons by allowing more than one element to be added to a list (source 8) The append function differs from the cons function by allowing the lists to be combined in any way (source 8). In a cons expression the element being added is always at the front, in append both lists are being added together. (append '(d e f) '(a b c)) // Creates a list of "d e f a b c". (cons 'a (b c d)) // This will always create a list of "a b c d"

Conditional Functions
There are a number of conditional functions in LISP, but at the basic level there are two main conditional functions: cond and null.

Cond- Every cond function takes a series of alternatives into account, these options are all lists (source 9). Each option is a list broken up into two parts: the condition--which is the car of the list, and the body forms--the cdr of the list (source 8). (setq variable '(a)) (cond     ((variable) (print "The variable is not empty")) ;The message prints if "variable" is not empty.     ((anotherVariable) (print "anotherVariable is not empty"))) ; prints only if "variable" is empty AND "anotherVariable" is not empty (explained later). The body form a conditional expression is only evaluated if the condition is evaluated to be not equal to nil--the LISP equivalent of false or 0, if a condition is equal to nil then the following condition will be checked and if it is found to be true then it will be evaluated (source 8). It is important to note that when a condition is tested as non-nil and the body form is evaluated then the rest of the expressions are ignored, only one is evaluated in a cond (source 8).

Null-This function is used to determine whether or not an object is equal to nil, if the object is nil then the function returns with "t" otherwise it returns as nil (source 9). (setq variable '(a)) (cond    ((null '(variable)) ; Returns as nil ((null ')) ; Returns as "t" In order to terminate a cond function when all the conditions have been evaluated as nil an additional default argument must be added (source 8). (cond     ((variable) (print "The variable is not empty")) ;The message prints if "variable" is not empty.     ((anotherVariable) (print "anotherVariable is not empty"))     ((t) (print "All conditions failed")) )

Defining Functions
While there is a wide array of functions made to suit a variety of purposes, the creators of LISP did not prepare for every eventuality, at some point a user will need to create their own function using the defun--short for "define function"--function (source 10).

Defun-This function is made up of five parts following the word defun: the new function's name, a list of arguments passed--if no arguments are to be past then an empty list "" is used instead, optional documentation of the function, another optional expression (explained further down), and the body code of the function (source 10). An non-interactive function: (defun myFunction       "This function prints a string and takes no arguments" ; optional documentation       (print "The function has been evaluated")) The arguments in a defun function are private to the function definition and--as such--can be named anything the user wants, including naming them the same as other variables outside of the function definition (source 10). The arguments' values are also private to the function definition, they cannot be manipulated from outside of the defun function and must be set within the body code (source 10). (setq numberValue '(10))

(defun myFunction (numberValue)      "prints out the value of a variable" ; optional       ((setq numberValue '(100)) (print numberValue))) ;numberValue is equal to 100 INSIDE the function. (print numberValue) ;numberValue is equal to 10 OUTSIDE the function

= Week 7: Language constructs: statements, control flow, expressions & operators; an overview of Scratch = Content authors (Group #5) Brian Doehner and Seth Thompson

Outline by Eric Hutchins
 * Terminology Basics

The easiest way to think of a variable is as a holding spot for data. This phrasing is deliberately vague because there are many different types of data to store. Individual languages will have different ways of storing data, but most modern languages tend to divide variables into types that are meant to be represented as symbols and text, and those that are meant to be used in mathematical operations. A statement is the smallest size piece written instruction in programming languages. It is contains expressions and are executed to produce results of the code contained inside them. Programs contain many statements.
 * What are Variables?
 * What are Statements?

LISP LISP is a procedural language that, over time, has been systematically retooled to incorporate modern programming concepts, such as object oriented design. Its original implementation, however, was procedural, and syntactically was built around organization of lists. Coding in LISP looks like this: (set ‘example ‘(Jim Bob Dave Steve)) In this case, each set of parentheticals encompasses a segment of the statement. The “set” command tells the program to create an atom—an identifiable unit of data—called “example”. The single-quote immediately preceding “example” tells the program that this atom is not to be evaluated mathematically. The single quote preceding the next set of parentheses also marks the included data as non-evaluative information. Each item in the second set of parentheses will be treated as individual atoms listed under the set of data called by “example”.
 * How are Statements captured in different languages such as LISP or Java?

Java Java was designed around object oriented programming from the ground up. Originally released in 1995, Java shares a great deal of its syntax with C and C++. A statement in Java setting up a simple variable looks like this: int example = 7; Where “int” is the variable type, “example” is the name of the variable, = is a simple operator allowing assignment of value to the variable, “7” is the data to be entered, and the statement caps with a semi-colon.


 * What are some examples of Statements in these languages?
 * Control Flow
 * Conditional flow

Conditional control flow executes commands depending on conditions provided by the initializing statement. Conditional control typically comes in several standard flavors: If, If/Else, case statements. if statement example: if(x < 9) return x; if/else statement example: if (x<9) return true; else return false;
 * Loops
 * Subroutine calls
 * Expressions & Operators
 * What is an expression tree (maybe a picture)?
 * What is operator precedence?
 * The Scratch Programming Language
 * What is Scratch?

Scratch is a visually-interfaced language designed for introductory programming. Scratch is designed to be used to teach grade school thru high school aged students on the concepts of programming. Its design is based upon stacking blocks or Legos to create the programs for students.


 * a paragraph on history

The Scratch Language was produced by the Lifelong Kindergarten group from MIT Media Lab in 2003. It was created through funds by the National Science Foundation, Google, Dell, Microsoft, LEGO Foundation, MacArthur Foundation, Code-To-Learn Foundation, Fastly, Inversoft, and the MIT Media Lab consortium.


 * a brief description on its paradigm
 * Brief tutorial on Scratch
 * List the 8 main categories and describe each
 * i.e. the 8 main buttons at upper left of Scratch)
 * A short code example or two for each category
 * Note: give a feel of the language without being complete

= Week 8: SPRING BREAK =

No classes

= Week 9: Language usage (utility, development) and the modern paradigm: OOP vs procedural = Content authors (Group #6) Justin Alix and Kenneth Drews

Outline by Erol Aygar


 * Discussion on Utility vs Development
 * Describe what attributes each usage has
 * What makes a language transform from one to the other
 * How does this relate to paradigm
 * Comparison of programming paradigms: OOP vs Procedural
 * Structure put on language and its purpose
 * Typed languages - restricts freedom to reduce error
 * Encapsulation (OOP) - further restrictions
 * Talk about restrictions and importance (i.e. reducing access to data)
 * Multi-paradigms and support for object oriented programming
 * A quick contrast with pre-procedural paradigm - imperative
 * lacks structure - no subroutines
 * spaghetti logic - "go-to" dilema

= Week 10: Parsing: syntax vs semantics; Tokenization - a lexical analyzer in Java = Content authors (Group #5) Brian Doehner and Seth Thompson

Outline by Eric Hutchins
 * add item 1
 * sub-item a


 * add item 2

= Week 11: Parsing: implementing a language - a recursive descent parser in Java = Content authors (Group #6) Justin Alix and Kenneth Drews

Outline by Erol Aygar
 * add item 1
 * sub-item a


 * add item 2

= Week 12: Grammers: Chomskys Hierarchy & regular expressions = Content authors (Group #3) Joshua Anderson and Forrest Surprenant

Outline by Sergiu Mihu
 * add item 1
 * sub-item a


 * add item 2

= Week 13: Grammers: Context Sensitive Grammars = Content authors (Group #4) Jacob.McQuaid and Jason Bouchard

Outline by Daniel Mamede
 * add item 1
 * sub-item a


 * add item 2

= Week 14: Table driven parsing, an overview of lex and yacc = Content authors (Group #1) Colby Johnson and Pauline Wilk

Outline by Casey Eyring
 * add item 1
 * sub-item a


 * add item 2