CS241 - Foundations of Sequential Programs Regular Language Formal Languages Assembler

Warm-up problem

What are the bitwise operations needed to encode x 6 bits, y 5 bits, z 5 bits, 16 bits for i

unsigned int x, y, z
int i;
(x << 26) | (y << 21) | (Z << 16)
(i & 0x0000FFFF) // masking keep bits in FFFF 

char assumes it’s already in ASCII char is 8 bits move 8 bits

Finite Language

Example: Suppose we have the language, L = {cat, car, cow}. Write a program that determines whether or not w ∈ L given that each character of w is scanned exactly once without the ability to store previously seen characters.

We describe below the algorithm for the program. Notice how it only inspects each character in the input once and makes a decision based on the character and the current state of the program.

  • We can represent the algorithm using a state diagram.

Regular Languages

Union, concatenation, Kleene Star

confused as in what kleene star is??? L* basically concatenates every combination, every string must be concatenate with what is in L. Union

Any regular language kleene star is also regular.

Regular Expressions

Egrep tools that determines if the string is in a language. We need to add loops to our pictorial representation to represent regular languages.

Deterministic Finite Automata

AKA DFA Determine the correct ouput, if’s else don’t care when writing Assembler.

Samples in Class

A state for even number of a’s and odd number of a’s. Two states for a. Four states for b:

ae          ao
be          be


ae          ao
bo          bo

DFA recognition algorith

Invent Delta star: describe whole transition in state machine

Any regular language can be defined by a DFA or regular expression Regular expression is a little bit human, mathematic.

Delta is a function, that asks which state to go through. When we go through every character of the word, we then check if s is an Accept. Usually more complicated than that but it’s been masked.

First thing to do to Assembler code is break things down into tokens.

Extensions to DFAs

Also tell you how to get the binary representation in the states. Tells you if it’s in language and also the value. Associate action to the transition.

Example in class

Only check Accept after reading the whole string. Before that, we can’t know if we read in a hex or a number…