*************************************************************
** Parse Tree: Upto the the levels of simple
statements ***
*************************************************************
Program
|
|
FUNCTION_DEFINITION_HEADER:<compound-stmt>
| [0] function
main ( )
|
| |
| | BEGINNING of FUNCTION
DEFINITION:<compound-stmt>
| | [1] {
| |
| | |
| | |
WHILE_HEADER:<compound-stmt>
| | | [2]
while ( 1 )
| | |
| | |
|
| | |
| BEGINNING of WHILE_BLOCK:<compound-stmt>
| | |
| [3] {
| | |
|
| | |
| |
| | |
| | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [4] display "" ;
| | |
| |
| | |
| |
| | |
| | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [5] display
"************************************************" ;
| | |
| |
| | |
| |
| | |
| | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [6] display "Want to find all primes
less than n! " ;
| | |
| |
| | |
| |
| | |
| | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [7] display "What is your value of n
this time? " ;
| | |
| |
| | |
| |
| | |
| | READ_STATEMENT:<simple-stmt>
| | |
| | [8] read n ;
| | |
| |
| | |
| |
| | | |
|
DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [9] display "" ;
| | |
| |
| | |
| |
| | |
| | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | [10] display "The following are all the
primes less than " , n ;
| | |
| |
| | |
| |
| | |
| |
FUNCTION_CALL_ASSIGNMENT_STATEMENT:<simple-stmt>
| | |
| | [11] allPrimesLessThan = allPrimesLessThan (
n ) ;
| | |
| |
| | |
|
| | |
| END of
WHILE_BLOCK:<compound-stmt>
| | |
| [12] }
| | |
|
| |
| | END of FUNCTION
DEFINITION:<compound-stmt>
| | [13] }
| |
|
|
FUNCTION_DEFINITION_HEADER:<compound-stmt>
| [14] function
allPrimesLessThan ( y )
|
| |
| | BEGINNING of FUNCTION
DEFINITION:<compound-stmt>
| | [15] {
| |
| | |
| | |
ASSIGNMENT_STATEMENT:<simple-stmt>
| | | [16]
count = 0 ;
| | |
| | |
| | |
ASSIGNMENT_STATEMENT:<simple-stmt>
| | | [17]
num = 2 ;
| | |
| | |
| | |
WHILE_HEADER:<compound-stmt>
| | | [18]
while ( num < y )
| | |
| | |
|
| | |
| BEGINNING of
WHILE_BLOCK:<compound-stmt>
| | |
| [19] {
| | |
|
| | |
| |
| | |
| |
FUNCTION_CALL_ASSIGNMENT_STATEMENT:<simple-stmt>
| | |
| | [20] status = isPrime ( num ) ;
| | |
| |
| | |
| |
| | |
| | IF_HEADER:<compound-stmt>
| | |
| | [21] if ( status )
| | |
| |
| | |
| | |
| | |
| | |
BEGINNING of IF_BLOCK:<compound-stmt>
| | |
| | | [22]
{
| | |
| | |
| | |
| | | |
| | |
| | | | ASSIGNMENT_STATEMENT:<simple-stmt>
| | |
| | | | [23] count = count + 1 ;
| | |
| | | |
| | |
| | | |
| | |
| | | | DISPLAY_STATEMENT:<simple-stmt>
| | |
| | |
| [24] display num , " is a
prime." ;
| | |
| | | |
| | |
| | |
| | |
| | | END
of IF_BLOCK:<compound-stmt>
| | |
| | | [25]
}
| | |
| | |
| | |
| |
| | |
| | ASSIGNMENT_STATEMENT:<simple-stmt>
| | |
| | [26] num = num + 1 ;
| | |
| |
| | |
|
| | |
| END of
WHILE_BLOCK:<compound-stmt>
| | |
| [27] }
| | |
|
| | |
| | |
RETURN_STATEMENT:<simple-stmt>
| | | [28]
return count ;
| | |
| |
| | END of FUNCTION
DEFINITION:<compound-stmt>
| | [29] }
| |
|
|
FUNCTION_DEFINITION_HEADER:<compound-stmt>
| [30] function
isPrime ( x )
|
| |
| | BEGINNING of FUNCTION
DEFINITION:<compound-stmt>
| | [31] {
| |
| | |
| | |
IF_HEADER:<compound-stmt>
| | | [32]
if ( x < 2 )
| | |
| | |
|
| | |
|
RETURN_STATEMENT:<simple-stmt>
| | |
| [33] return 0 ;
| | |
|
| | |
| | |
ASSIGNMENT_STATEMENT:<simple-stmt>
| | | [34]
candidate = 2 ;
| | |
| | |
| | |
WHILE_HEADER:<compound-stmt>
| | | [35]
while ( candidate < x )
| | |
| | |
|
| | |
| BEGINNING of
WHILE_BLOCK:<compound-stmt>
| | |
| [36] {
| | |
|
| | |
| |
| | |
| | IF_HEADER:<compound-stmt>
| | |
| | [37] if ( ( x % candidate ) == 0 )
| | |
| |
| | |
| | |
| | |
| | |
RETURN_STATEMENT:<simple-stmt>
| | |
| | | [38]
return 0 ;
| | |
| | |
| | |
| |
| | | |
|
ASSIGNMENT_STATEMENT:<simple-stmt>
| | |
| | [39] candidate = candidate + 1 ;
| | |
| |
| | |
|
| | |
| END of
WHILE_BLOCK:<compound-stmt>
| | |
| [40] }
| | |
|
| | |
| | |
RETURN_STATEMENT:<simple-stmt>
| | | [41]
return 1 ;
| | |
| |
| | END of FUNCTION
DEFINITION:<compound-stmt>
| | [42] }
| |
*************************************************************
***
End of Parse Tree
***
*************************************************************