Changeset 6f47834 for doc


Ignore:
Timestamp:
Jul 24, 2024, 6:55:30 PM (23 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
1ad112a5
Parents:
35c792f
Message:

add section on enumeration I/O

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    r35c792f r6f47834  
    387387
    388388
     389\section{Enumeration I/O}
     390
     391As 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.
     392However, very few programming languages provide a mechanism to read in enumerator values.
     393Even 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.
     395When the enumerator labels are packed together in the input stream, the input algorithm scans for the longest matching string.
     396For 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}
     403int 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$
     422BBBABAAAAB
     423BBB AAA AA AB B
     424
     425$\rm output$
     426BBB = 3
     427AB = 6
     428AAA = 4
     429AB = 6
     430BBB = 3
     431AAA = 4
     432AA = 5
     433AB = 6
     434B = 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
    389445\section{Planet Example}
    390446
Note: See TracChangeset for help on using the changeset viewer.