Java Reference
In-Depth Information
2.1 An Informal Definition of the ac Language
Our language is called ac (for adding calculator ). When compared with most
programming languages, ac is relatively simple, yet it serves nicely as a study
for examining the phases and data structures of a compiler. We first define ac
informally:
Types Most programming languages o
er a significant number of predefined
data types, with the ability to extend existing types or specify new data
types. In ac, there are only two data types: integer and float.Aninteger
type is a sequence of decimal numerals, as found in most programming
languages. A float type allows five fractional digits after the decimal
point.
ff
Keywords Most programming languages have a number of reserved key-
words ,suchasif and while, which would otherwise serve as variable
names. In ac, there are three reserved keywords, each limited for sim-
plicity to a single letter: f (declares a float variable), i (declares an integer
variable), and p (prints the value of a variable).
Va r i ab l e s Some programming languages insist that a variable be declared by
specifying the variable's type prior to using the variable's name. The
ac language o
ers only 23 possible variable names, drawn from the
lowercase Roman alphabet and excluding the three reserved keywords
f, i,andp. Variables must be declared prior to using them.
ff
Most programming languages have rules that dictate circumstances under
which a given type can be converted into another type. In some cases, such type
conversion is handled automatically by the compiler, while other cases require
explicit syntax (such as casts ) to allow the type conversion. In ac,conversion
from integer type to float type is accomplished automatically. Conversion in
the other direction is not allowed under any circumstances.
For the target of translation, we use the widely available program dc
(for desk calculator ), which is a stack-based calculator that uses reverse Polish
notation (RPN). When an ac program is translated into a dc program, the
resulting instructions must be acceptable to the dc programandmust faithfully
represent the operations specified in an ac program. Stack-based languages
commonly serve as targets of translation because they lend themselves to
compact representation. Examples include the translation of Java TM into Java
Virtual Machine (JVM), ActionScript R
into AVM2 for Flash R
media, and
. Thus, compilation of ac to dc can be
viewed as a study of such larger systems.
printable documents into PostScript R
 
 
Search WWH ::




Custom Search