Java Reference
In-Depth Information
AJavaorC
single-line comment that begins with // and ends with
Eol can be defined as
++
//(Not(Eol)) Eol
Comment =
This regular expression says that a comment begins with two slashes and
ends at the first end-of-line. Within the comment, any sequence of char-
acters is allowed that does not contain an end-of-line. (This guarantees
that the first end-of-line we see ends the comment.)
A fixed-decimal literal (for example, 12
.
345) can be defined as
Lit = D + . D +
One or more digits must be on both sides of the decimal point, so .12
and35.are excluded.
An optionally signed integer literal can be defined as
) D +
IntLiteral =
('
+
'
|−|λ
An integer literal is one or more digits preceded by a plus, minus, or no
sign at all (
). So that the plus sign is not confused with the positive
closure operator, it is quoted.
λ
A more complicated example is a comment delimited by ## markers,
which allows single #'s within the comment body:
) Not(#)) ##
Comment 2
=
## ((#
Any # that appears within this comment's body must be followed by a
non-# so that a premature end-of-comment marker, ##, is not found.
All finite sets are regular. However, some (but not all) infinite sets are regular.
Forexample,considerthesetofbalancedbracketsoftheform[[[...]]].
This set is defined formally as
, and it can be proven that this set
is not regular (Exercise 14). The problem is that any regular expression that
tries to define it either does not get all balanced nestings or includes extra,
unwanted strings.
On the other hand, it is straightforward to write a CFG that defines bal-
anced brackets precisely. Moreover, all regular sets can be defined by CFGs.
Thus, the bracket example shows that CFGs are a more powerful descrip-
tive mechanism than regular expressions. Regular expressions are, however,
quite adequate for specifying token-level syntax. Moreover, for every regu-
lar expression we can create an e
{
[ m ] m | m
1
}
cient device, called a finite automaton ,that
recognizes exactly those strings that match the regular expression's pattern.
 
Search WWH ::




Custom Search