Java Reference
In-Depth Information
procedure S
tart
()
switch (
)
case ts . peek()∈{num, lparen}
ans
...
V
alue
()
call
match
( $ )
call
print
( ans )
5
end
function V
alue
() returns int
switch (
)
case ts . peek()∈{num}
call
...
match
( num)
num . ValueOf()
return ( ans )
case ts . peek()∈{lparen}
call
ans
match
( lparen)
ans
E
xpr
()
call
( rparen)
return ( ans )
match
end
function E
xpr
() returns int
switch (
)
case ts . peek()∈{plus}
call
...
match
( plus)
op 1
V
alue
()
6
op 2
V
alue
()
7
+ op 2
case ts . peek()∈{prod}
call
return op 1
8
match
( prod)
ans
V
alues
(1)
9
return ( ans )
end
function V
( thus f ar ) returns int
case ts . peek()∈{num, lparen}
alues
next
V
alue
()
10
ans
V
alues
( thus f ar × next )
11
return ( ans )
case ts . peek()∈{rparen}
return thus f ar
12
end
Figure 7.10: Recursive-descent parser with semantic actions. The
variable ts is the token stream produced by the scanner.
 
Search WWH ::




Custom Search