1 / 14

ITEC 320

ITEC 320. Lecture 7 Examples / Look ahead. Review. Strings What types are there? What are the differences? What should you use where?. Outline. Usage of ADA Variables Conditionals Loops Arrays Look ahead More input w/ Ada. Program 1. Character counter

reegan
Download Presentation

ITEC 320

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 320 Lecture 7 Examples / Look ahead

  2. Review • Strings • What types are there? • What are the differences? • What should you use where?

  3. Outline • Usage of ADA • Variables • Conditionals • Loops • Arrays • Look ahead • More input w/ Ada

  4. Program 1 • Character counter • Input strings less than 80 characters until eof and count number of spaces. Then count number of As, Bs, ...Zs (case insensitive).

  5. Program 2 • Given a string, compute recursively (no loops) the number of times lowercase "hi" appears in the string.

  6. Program 3 • Caesar cipher of shift 3 to the right Character’val(65); Character’pos(‘A’);

  7. Input • What are the problems with ADA input? • What would need to be added to solve this?

  8. Example EOL: Boolean; c: Character; -- Caution: This example ignores EOL begin lookAhead(c, EOL); put(c); -- Output is 'H' lookAhead(c, EOL); put(c); -- Output is 'H' get(c); lookAhead(c, EOL); put(c); -- Output is 'e’ end example; Assumes input Hello

  9. Motivation • Allows you to figure out how to read next bit of input lookAhead(c, EOL); -- Use get to input if Ada.Characters.Handling.Is_Digit(c) then Ada.Integer.Text_io.get(n); -- Get an integer else Ada.Text_io.get(c); -- Get a character end if;

  10. Motivation • Allows multiple portions of code to access the same input • Loop conditionals loop LookAhead(c, EOL); exit when is_Something(c); -- do something with c get(c); end loop; For example, when reading 123+456 This can be used to help a compiler How else could this be accomplished?

  11. Issue • What happens when you hit the end of line? • Value returned depends on which way the wind blows EOL: Boolean; c: Character; begin loop lookAhead(c, EOL); if EOL then – End of line Ada.text_IO.Skip_line; else if is_digit(c) then -- do a numeric get else -- do a character get end if; end if; end loop;

  12. White space • What is white space? • Code to skip white space?

  13. Others • Java • java.io.PushbackInputStream(InputStream) - constructs a stream that can be used to push back one byte • java.io.PushbackInputStream(InputStream, int size) - constructs a stream that can be used to push back size bytes • void unread(int b) pushes back the byte b which will be input again by the next read. Only one byte can be pushed back at a time. • C++ • unget and putback • C • ungetc

  14. Summary • Problems in ADA • Lookahead / IO review

More Related