Compiler/lexical analyzer: Difference between revisions

use shorter example in the whitespace section
(removing the clarify template - I think everything has been cleared up now.)
(use shorter example in the whitespace section)
Line 144:
** e.g. <code>& &</code> is invalid, and not interpreted as the <tt>&&</tt> operator.
 
TheyFor example, the following two program fragments are equivalent, and should produce the same token stream, except for the line and column positions.:
The following programs are equivalent:
 
* <lang c>if ( p /* meaning n is prime */ ) {
<lang c>
print ( n , " " ) ;
count = 1 ;
count = count + 1 ; /* number of primes found so far */
n = 1 ;
}</lang c>
limit = 100 ;
* <lang c>if(p){print(n," ");count=count+1;</lang>
while ( n < limit ) {
k = 3 ;
p = 1 ;
n = n + 2 ;
while ( ( k * k <= n ) && ( p ) ) {
p = n / k * k != n ;
k = k + 2 ;
}
if ( p ) {
print ( n , " " ) ;
count = count + 1 ;
}
}
print ( count , "\n" ) ;
</lang>
 
<lang c>
count=1;n=1;limit=100;while(n<limit){k=3;p=1;n=n+2;while((k*k<=n)&&(p)){p=n/k*k!=n;k=k+2;}if(p){print(n," ");count=count+1;}}print(count,"\n");
</lang>
 
They should produce the same token stream, except for the line and column positions.
 
;Complete list of token names
Anonymous user