Java Reference
In-Depth Information
a,with*b as the parameter. If a has been declared in a typedef to be a type
name, then this character sequence can also be the declaration of an identifier
b that is a pointer variable (the parentheses are not needed, but they are legal).
C contains no special marker that separates declarations from statements,
so the parser will need some help in deciding whether it is seeing a proce-
dure call or a variable declaration. One way to do this is for the scanner
to create, while scanning and parsing, a table of currently visible identifiers
that have been defined in typedef declarations. When an identifier in this
table is scanned, a special typeid token is returned (rather than an ordinary
identifier token). This allows the parser to distinguish the two constructs
easily, since they now begin with di
erent tokens.
Why does this complication exist in C? The typedef statement was not
in the original definition of C in which the lexical and syntactic rules were
established. When the typedef construct was added, the ambiguity was not
immediately recognized (parentheses, after all, are rarely used in variable
declarations). When the problem was finally recognized, it was too late, and
the “trick” described previously had to be devised to resolve the correct usage.
ff
Processing Reserved Words
Virtually all programming languages have symbols (such as if and while)
that match the lexical syntax of ordinary identifiers. These symbols are
called keywords . If the language has a rule that keywords may not be used
as programmer-defined identifiers, then they are reserved words ,thatis,they
are reserved for special use.
Most programming languages choose to make keywords reserved. This
simplifies parsing, which drives the compilation process. It also makes pro-
grams more readable. For example, in Pascal and Ada, subprograms without
parameters are called as name; (no parentheses required). But what if, for
example, begin and end are not reserved and some devious programmer has
declared procedures named begin and end? The result is a program whose
meaning is not well defined, as shown in the following example, which can be
parsed in many ways:
begin
begin;
end;
end;
begin;
end
With careful design, you can avoid outright ambiguities. For example,
in PL
/
I keywords are not reserved; procedures are called using an explicit
 
Search WWH ::




Custom Search