Changeset 5aeb1a9


Ignore:
Timestamp:
Jul 24, 2024, 7:11:56 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
38e20a80
Parents:
a03ed29 (diff), 878b1385 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
3 edited

Legend:

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

    ra03ed29 r5aeb1a9  
    395395
    396396
     397\section{Enumeration I/O}
     398
     399As 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.
     400However, very few programming languages provide a mechanism to read in enumerator values.
     401Even 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.
     403When the enumerator labels are packed together in the input stream, the input algorithm scans for the longest matching string.
     404For 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}
     411int 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$
     430BBBABAAAAB
     431BBB AAA AA AB B
     432
     433$\rm output$
     434BBB = 3
     435AB = 6
     436AAA = 4
     437AB = 6
     438BBB = 3
     439AAA = 4
     440AA = 5
     441AB = 6
     442B = 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
    397453\section{Planet Example}
    398454
  • 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"
     1BBB = 3
     2AB = 6
     3AAA = 4
     4AB = 6
     5BBB = 3
     6AAA = 4
     7AB = 6
     8AA = 5
     9B = 7
     10BBB = 3
     11AAA = 4
     12AA = 5
     13AB = 6
     14B = 7
     15BBB = 3
     16AAA = 4
     17AA = 5
     18AB = 6
     19B = 7
     20AAA = 4
     21B = 7
     22CB = 8
     23AC = 9
     24CB = 8
     25AC = 9
     26BBB = 3
     27AAA = 4
     28AA = 5
    2929missing data
    30 "AAA"
    31 "B"
    32 "CB"
    33 "AC"
    34 "CB"
    35 "AC"
    36 "BBB"
    37 "AAA"
    38 "AA"
     30AAA = 4
     31B = 7
     32CB = 8
     33AC = 9
     34CB = 8
     35AC = 9
     36BBB = 3
     37AAA = 4
     38AA = 5
    3939missing data
  • tests/enum_tests/input.cfa

    ra03ed29 r5aeb1a9  
    33
    44int main() {
    5         enum(int) E { BBB, AAA, AA, AB, B, CB, AC };
     5        enum(int ) E { BBB = 3, AAA, AA, AB, B, CB, AC };
    66        E e;
    77
     
    1414                } // try
    1515          if ( eof( sin ) ) break;
    16                 sout | "\"" | e | "\"";
     16                sout | e | "= " | value( e );
    1717        } // for
    1818}
Note: See TracChangeset for help on using the changeset viewer.