A finite automaton processes an input string according to the following algorithm.
The input string is read from a tape. The tape head is initially positioned over the first symbol of
the input string. The current state starts out as the start state.
The single most important thing to keep in mind when you are creating a finite automaton to
recognize a regular language is the following:
Each state represents a property describing a prefix of the input string.
The idea is that when the automaton is in
Recall that the syntactic structure of a programming language's syntax is typically a context-free
language. Context-free languages are more powerful than regular languages because they can
describe nested constructs such as parentheses.
Regular languages are a useful model for the lexical structure of a programming
We will learn about two formalisms, regular expressions and finite automata, for
specifying regular languages precisely:
1. Regular expression - a generator for a re
Ambiguity in a context-free grammar can generally be eliminated by rewriting the
grammar. Here is a grammar for the same expression language that yields syntax trees
that follow the usual precedence rules for arithmetic:
Lexical analysis is the process of reading the source text of a program and converting it into a
sequence of tokens.
Since the lexical structure of more or less every programming language can be specified by a
regular language, a common way to implement a
Dynamically typed (variables may contain any kind of value)
Interpreted: Ruby source code is directly loaded into the Ruby interpreter and executed.
(Internally, the interpreter translates the source program into a more-easily executed format.)
The syntax of a programming language is the set of rules that describe which sequences of
characters form legal programs, and which do not.
There are two components to programming language syntax:
1. Lexical structure. The lexical structure of a language
Parsing is the following problem: given a grammar and a string of terminal symbols, find a series
of productions that derive the string of nonterminals from the start symbol.
E.g., given the expression
How can we parse this string? Here is one way:
Classes and objects in Ruby are much more dynamic and flexible than Java or C+.
For example, we can add a method to an existing object at runtime:
puts "#cfw_@name goes for walkies"
The method call
produces the output
Metaprogramming is the ability for a program to create new functions/methods when the
Ruby has excellent support for metaprogramming because
Methods can be added to classes and objects at runtime
Procs allow code to be "saved" and executed