Changeset 6f47834 for doc/theses/jiada_liang_MMath
- Timestamp:
- Jul 24, 2024, 6:55:30 PM (5 months ago)
- Branches:
- master
- Children:
- 1ad112a5
- Parents:
- 35c792f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r35c792f r6f47834 387 387 388 388 389 \section{Enumeration I/O} 390 391 As seen in multiple examples, enumerations can be printed and the default property printed is the enumerator's label, which is similar in other programming languages. 392 However, very few programming languages provide a mechanism to read in enumerator values. 393 Even the @boolean@ type in many languages does not have a mechanism for input using the enumerators @true@ or @false@. 394 \VRef[Figure]{f:EnumerationI/O} show \CFA enumeration input based on the enumerator labels. 395 When the enumerator labels are packed together in the input stream, the input algorithm scans for the longest matching string. 396 For basic types in \CFA, the constants use to initialize a variable in a program are available to initialize a variable using input, where strings constants can be quoted or unquoted. 397 398 \begin{figure} 399 \begin{cquote} 400 \setlength{\tabcolsep}{15pt} 401 \begin{tabular}{@{}ll@{}} 402 \begin{cfa} 403 int main() { 404 enum(int ) E { BBB = 3, AAA, AA, AB, B }; 405 E e; 406 407 for () { 408 try { 409 @sin | e@; 410 } catch( missing_data * ) { 411 sout | "missing data"; 412 continue; // try again 413 } 414 if ( eof( sin ) ) break; 415 sout | e | "= " | value( e ); 416 } 417 } 418 \end{cfa} 419 & 420 \begin{cfa} 421 $\rm input$ 422 BBBABAAAAB 423 BBB AAA AA AB B 424 425 $\rm output$ 426 BBB = 3 427 AB = 6 428 AAA = 4 429 AB = 6 430 BBB = 3 431 AAA = 4 432 AA = 5 433 AB = 6 434 B = 7 435 436 \end{cfa} 437 \end{tabular} 438 \end{cquote} 439 \caption{Enumeration I/O} 440 \label{f:EnumerationI/O} 441 \end{figure} 442 443 444 389 445 \section{Planet Example} 390 446
Note: See TracChangeset
for help on using the changeset viewer.