Monday, June 18, 2007

Machine Problem #1

Due Date: Wednesday, June 27, 2007, before or on 3:00 PM
Submission Requirements:
  • computerized (word-processor-application-generated)
  • printed in short bond paper
  • text uses:
    • font: Garamond
    • size: 12 pt.
  • source code uses:
    • font: Courier
    • size: 10 pt.
  • including your test suite (input/output)
PROBLEM:
Write a program that will act like a scanner using the C representation below. Test your program with the following inputs:
  1. mid = (hi + lo) / 2;
  2. degc = (degf - 32) * (5.0 / 9);
  3. your sample 5 inputs.

REPRESENTING TOKENS IN C

typedef enum {
   IDENT, INT_CONST, BINOP, LEFTPAREN, . . .
} TokenKind;

typedef union {
   char *name;
   int int_const;
   . . .
} TokenValue;

typedef struct {
   TokenKind kind;
   TokenValue value;
} Token;

No comments: