Tokens
A token is the smallest element of a
program that is meaningful to the compiler. In Java, there are five
categories of tokens: identifiers, keywords, literals, operators,
and separators.
Identifiers
Identifiers are tokens that represent names. These
names can be assigned to variables, methods, and classes to uniquely
identify them.
- Variables - are names that represent
memory locations in a computer. For example I could create
a variable called "Celsius Temp" to hold data about the
current temperature in Celsius or "FarenTemp" to hold data
on the current temperature in Fahrenheit. When a programmer
wishes to perform some operation using a variable, he or she is
actually performing an operation on data that exists at that
memory location. For example, these lines could be inserted into a
typical program to convert a Fahrenheit temperature of 21
degrees to Celsius.
- Celsius
Temp = 21;
FarenTemp
= (9/5 * Celsius
Temp) + 32;
- In the first statement, the number value of
21 is stored in the memory location Celsius Temp.
- In the second statement the data in the
Celsius Temp location is multiplied by 9/5 and then 32 is
added. This total is then stored in the memory location called
FarenTemp.
- Functions - are tasks within a program. A
function also must have a name. You could for example create a
method called "ConvertToFarenheit". This name would be
assigned to the task responsible for converting Celsius
temperatures to Fahrenheit.
- Classes - are a grouping of related
data structures or methods. For example you could create a class
called "Temperature". Within this class would be methods
that are used to do temperature related operations such as
"ConvertToFarenheit" or
"GetCurrentTemperature".
Different programming languages have different
rules about the use of Identifiers. In C/C++, all identifiers are
case sensitive (i.e.. temp and Temp are not the same).
Identifiers must begin with a letter. You can include numbers in an
identifier but not as the first character. In addition, identifiers
cannot have any spaces in them (i.e.. Celsius Temp is
invalid).
Keywords
Keywords are predefined identifiers reserved by
languages for a specific purpose and are used only in a limited,
specified manner. You cannot use keywords for any other
purpose. Listed below are Keywords reserved by the C++
language.
Literals
Literals are character constants that have a
special meaning in a language. Listed below are several literals used
in C++.
- \n newline
\b backspace
\f formfeed
\0 null
\r carriage return
\t horizontal tab
Operators
Operators specify an evaluation or computation to
be performed on data. Indicated below are several operators and their
meaning as used in C++.
- -
Subtraction
+
Addition
*
Multiplication
/
division
% Modulus
--
Decrement
++ Increment
> Greater
Than
< Less
Than
>= Greater Than or Equal
To
<= Less Than or Equal
To
== Equal To
!= Not Equal
To
&& And
|| Or
! Not
Separators
Separators are used to inform the compiler of how
things are grouped in the code. Listed below are examples of
separators supported by C++.
{
} ;
Comments and
Whitespaces
All comments written within the source code of a
program are ignored. To notify the compiler that the text is in fact
a comment, several symbols are used. These symbols are indicated
below.
- /*
comment */ All characters between /*
and */ are ignored.
//
comment All characters
after the // up to the end of the line are ignored.
Last Updated Jan.8/99