with ada.text_io; use ada.text_io; -- Demonstrates how look_ahead processes input -- If the input contains the following three lines (without the "-- "): -- ab -- cde -- f -- Output will be: -- FALSE, a -- FALSE, a -- get: c = a -- FALSE, b -- get: c = b -- TRUE, ^Q -- FALSE, c -- FALSE, f procedure lademo is c: character; at_eol: Boolean; package boolean_io is new enumeration_io(boolean); use boolean_io; begin ------------------------------------------------------------------ -- Look at the FIRST character in the input -- This not move the input marker: it proceeds the first character look_ahead(c, at_eol); put(at_eol); put_line(", " & c); ------------------------------------------------------------------ -- Look again at the first character in the input -- The input marker has not moved: -- it still proceeds the first character look_ahead(c, at_eol); put(at_eol); put_line(", " & c); ------------------------------------------------------------------ -- Now we will actually input the first character -- This moves the input marker: it will follow the first character get(c); put_line("get: c = " & c); ------------------------------------------------------------------ -- Now look at the SECOND character in the input look_ahead(c, at_eol); put(at_eol); put_line(", " & c); ------------------------------------------------------------------ -- Now we will actually input the second character -- This moves the input marker: it will follow the second character get(c); put_line("get: c = " & c); ------------------------------------------------------------------ -- Now look_ahead indicates that the input marker is at end of line -- Remember that c is a "random" character when at_eol is true look_ahead(c, at_eol); put(at_eol); put_line(", " & c); -- Move to the next line of input skip_line; ------------------------------------------------------------------ -- Look at the FIRST character on the second line look_ahead(c, at_eol); put(at_eol); put_line(", " & c); -- Move to the next line of input skip_line; ------------------------------------------------------------------ -- Look at the FIRST character on the third line look_ahead(c, at_eol); put(at_eol); put_line(", " & c); end lademo;