1.0 Languages, Expressions, Automata
Alphabet: a finite set, typically a set of symbols.
Language: a particular subset of the strings that can be made from the alphabet.
ex:
an alphabet of digits = cf
Lexical Analysis
Here is an overview of a compiler:
High level
Language
Program
Machine
Language
Program
Intermediate
Representation
Front end: Analysis
Scanner
Parser
Back end: Synthesis
Intermediate
Handout #2
EXERCISES ON RECURSION
Solve the following problems recursively:
1.
Count the number of zeros in an array.
2.
Print out an array.
3.
Print out the data in a linked list forward.
4.
Print ou
Turing Machines
Previously we discussed increasingly complex machines to accept languages. The
power was increased by providing additional storage. Specifically:
FAs could only remember via their sta
Syntactic Analysis, Recursive Descent Parsing
Syntactic Analysis/Parsing
The parser is the second phase of a compiler, it is significantly more complex than
the scanner. It assembles the tokens into c
Handout # 12
CSC 135
SOLUTIONS - EXERCISES ON PROLOG
1. Define a third predicate so that third(X, Y) says that Y is the third element of the list X. The
predicate should fail if X has fewer than three
import java.io.*;
import java.util.Scanner;
/-/ Recognizer for simple expression grammar
/ Written by Scott Gordon 1/03
/ minor modifications made 2/04, 9/06, 2/09, 9/11, 2/15
/
/
/ to run on Athena (
Handout # 9A
CSC 135
SOLUTIONS - EXERCISES ON PUMPING LEMMA
Using the pumping Lemma, prove that the following languages are not regular:
1.
L = cfw_anb2n
Assume L is regular. From the pumping lemma t
Handout # 3
CSC 135
EXERCISES ON REGULAR EXPRESSIONS AND FINITE AUTOMATA
Give regular expressions representing the following languages on cfw_a, b or cfw_0, 1:
1. all stringsstrings which begin and en
Handout # 8A
CSC 135
SOLUTIONS - EXERCISES ON SCHEME
1. Compute the values of the following expressions.
Expression
Value
( car (6
3
2)
)
6
( car (6
3
2)
)
error ( 6 3 2 ) has no value
( let
( ( L ( 6
Languages, Automata, Grammars, and Regular Expressions
Note: some of this is material you should have seen in CSc 28 (or its equivalent).
Languages, automata and grammars (regular expressions although
CSc 135 Fall 2016 - Programming Languages
Homework 2
due Wednesday November 2 at 11:59:00 pm
Write the following Scheme functions:
1. "digitinc4" -takes as input a 4-digit integer, and returns another
Handout # 4
CSC 135
EXERCISES ON LEXICAL ANALYSIS
Imagine you have a language that has only operators, identifiers, and two reserved words, and the following
characteristics:
the only legal character
Logic Programming and Prolog
See Handout # 11 on Logic History
Logic has a long standing history going back to the Greek philosophers. Aristotle is
regarded as the father of logic. He devised systemat
Evolution of Programming Languages
Evolution has been influenced by a number of factors, among which are:
computer architecture: the Von Neuman model where the CPU is separate
from the memory. Both p
Handout # 12
CSC 135
EXERCISES ON PROLOG
1. Define a third predicate so that third(X, Y) says that Y is the third element of the list X. The
predicate should fail if X has fewer than three elements. H
Non-Regular Languages
After studying the regular languages, a legitimate question is: Are all languages
(i.e. sets of strings) regular?
Given what we have just studied there are several other ways to
2.0 Formal Grammars
Context-Free Grammar (CFG). A language generator consisting of:
1.
2.
3.
4.
a set T of terminals (usually denoted with lowercase letters)
a set N of non-terminals (usually denoted
5.0 EBNF (Extended BNF) and Syntax Diagrams
EBNF is the same as BNF, with three additional meta-symbols:
cfw_ which indicates 0 or more
[ ] which indicates optional
( | | ) which indicates sub-alt
6.0 Recursive-Descent Parsing
Building a simple recognizer:
1. Convert BNF grammar to EBNF and syntax diagrams.
2. There must be an identifier token that points to the current token.
3. There must be
7.0 Non-Deterministic Finite Automata (NFA)
A non-deterministic finite automaton is one that (1) allows multiple arcs with
the same label to exit a node, and (2) allows arcs with a label. It is also
c
8.0 Regular Grammars and Regular Languages
Recall the general form of regular expressions:
If A is an alphabet, and a A , then a is a regular expression.
is a regular expression.
If r and s are regul
The
Chomsky
Hierarchy
Formal Grammars,
Languages, and the
Chomsky-Schtzenberger
Hierarchy
Overview
01 Personalities
02 Grammars and languages
03 The Chomsky hierarchy
04 Conclusion
Personalities
Noam
Handout # 13
CSC 135
SOLUTIONS - EXERCISES ON TURING MACHINES
1. Construct a Turing Machine which accepts the language
L = cfw_ w | w cfw_a, b* & |w| is a positive multiple of 3.
a. Give a description
First
Follow
block
cfw_B
cfw_$ FOLLOW(statemt) cfw_L FOLLOW(ifstmt)
FOLLOW(while) = cfw_ $, L, A, W, B, I, R, O, E
statemt
cfw_ A, W, B, I, R, O
cfw_E FIRST(statemt) = cfw_ A, W, B, I, R, O, E
asi