Changes in / [a03ed29:5aeb1a9]
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
ra03ed29 r5aeb1a9 395 395 396 396 397 \section{Enumeration I/O} 398 399 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. 400 However, very few programming languages provide a mechanism to read in enumerator values. 401 Even the @boolean@ type in many languages does not have a mechanism for input using the enumerators @true@ or @false@. 402 \VRef[Figure]{f:EnumerationI/O} show \CFA enumeration input based on the enumerator labels. 403 When the enumerator labels are packed together in the input stream, the input algorithm scans for the longest matching string. 404 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. 405 406 \begin{figure} 407 \begin{cquote} 408 \setlength{\tabcolsep}{15pt} 409 \begin{tabular}{@{}ll@{}} 410 \begin{cfa} 411 int main() { 412 enum(int ) E { BBB = 3, AAA, AA, AB, B }; 413 E e; 414 415 for () { 416 try { 417 @sin | e@; 418 } catch( missing_data * ) { 419 sout | "missing data"; 420 continue; // try again 421 } 422 if ( eof( sin ) ) break; 423 sout | e | "= " | value( e ); 424 } 425 } 426 \end{cfa} 427 & 428 \begin{cfa} 429 $\rm input$ 430 BBBABAAAAB 431 BBB AAA AA AB B 432 433 $\rm output$ 434 BBB = 3 435 AB = 6 436 AAA = 4 437 AB = 6 438 BBB = 3 439 AAA = 4 440 AA = 5 441 AB = 6 442 B = 7 443 444 \end{cfa} 445 \end{tabular} 446 \end{cquote} 447 \caption{Enumeration I/O} 448 \label{f:EnumerationI/O} 449 \end{figure} 450 451 452 397 453 \section{Planet Example} 398 454 -
tests/enum_tests/.expect/input.txt
ra03ed29 r5aeb1a9 1 "BBB" 2 "AB" 3 "AAA" 4 "AB" 5 "BBB" 6 "AAA" 7 "AB" 8 "AA" 9 "B" 10 "BBB" 11 "AAA" 12 "AA" 13 "AB" 14 "B" 15 "BBB" 16 "AAA" 17 "AA" 18 "AB" 19 "B" 20 "AAA" 21 "B" 22 "CB" 23 "AC" 24 "CB" 25 "AC" 26 "BBB" 27 "AAA" 28 "AA" 1 BBB = 3 2 AB = 6 3 AAA = 4 4 AB = 6 5 BBB = 3 6 AAA = 4 7 AB = 6 8 AA = 5 9 B = 7 10 BBB = 3 11 AAA = 4 12 AA = 5 13 AB = 6 14 B = 7 15 BBB = 3 16 AAA = 4 17 AA = 5 18 AB = 6 19 B = 7 20 AAA = 4 21 B = 7 22 CB = 8 23 AC = 9 24 CB = 8 25 AC = 9 26 BBB = 3 27 AAA = 4 28 AA = 5 29 29 missing data 30 "AAA" 31 "B" 32 "CB" 33 "AC" 34 "CB" 35 "AC" 36 "BBB" 37 "AAA" 38 "AA" 30 AAA = 4 31 B = 7 32 CB = 8 33 AC = 9 34 CB = 8 35 AC = 9 36 BBB = 3 37 AAA = 4 38 AA = 5 39 39 missing data -
tests/enum_tests/input.cfa
ra03ed29 r5aeb1a9 3 3 4 4 int main() { 5 enum(int ) E { BBB, AAA, AA, AB, B, CB, AC };5 enum(int ) E { BBB = 3, AAA, AA, AB, B, CB, AC }; 6 6 E e; 7 7 … … 14 14 } // try 15 15 if ( eof( sin ) ) break; 16 sout | "\"" | e | "\"";16 sout | e | "= " | value( e ); 17 17 } // for 18 18 }
Note: See TracChangeset
for help on using the changeset viewer.