home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!sr0o+
- From: sr0o+@andrew.cmu.edu (Steven Ritter)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: incrementation differences/THINK C 4.0 vs. 5.0
- Message-ID: <webbHVm00WBM842pMu@andrew.cmu.edu>
- Date: 28 Aug 92 10:48:01 GMT
- Article-I.D.: andrew.webbHVm00WBM842pMu
- References: <1992Aug27.182157.16567@qualcomm.com> <38188@unix.SRI.COM> <1992Aug28.130710.18938@qualcomm.com>
- <1992Aug28.143614.22079@phri.nyu.edu>
- Organization: Doctoral student, Psychology, Carnegie Mellon, Pittsburgh, PA
- Lines: 67
- In-Reply-To: <1992Aug28.143614.22079@phri.nyu.edu>
-
- roy@alanine.phri.nyu.edu (Roy Smith) writes:
-
- >sdorner@qualcom.qualcomm.com (Steve Dorner) writes:
- >>It does *not* know where the missing ";" should go. It knows where
- >>something is missing. An '=' would be a perfectly good choice, too.
- >
- > I've been thinking about this for a day or so. In the fragment
- >"a=b=c d=e;" the blank could be replaced with just about anything and make
- >a syntactically correct statement:
- >
- > Any alphanumeric would turn "c d" into a variable name.
- >
- > Any binary arithmentic operator (+, -, *, /)would be fine.
- >
- > Any relational operator (==, !=, <, >, <=, >=) would be fine.
- >
- > Any boolean operator (||, &&) would be fine.
- >
- > Any binary logical operator (&, |, etc) would be fine.
- >
- > Any assignment operator (=, =+, =-, =*, =/) would be fine.
- >
- > Deleting the space completely would give you the variable "cd".
- >
- > A comma would be fine, giving you two sequential assignments.
- >
- > All things considered, the a-priori probability that you need to
- >replace the space by a semicolon is pretty slim.
-
- This is an AI problem, and not a very difficult one. In principle, the
- compiler can know as much as you know. Suppose you were modifying
- someone else's code and came across the line:
- a=b=c d=e;
- What would you do?
-
- Most of the above suggestions are illegal. You can't add a binary
- arithmetic operator (you'd get c+d=e). Same with a boolean, relational
- or logical operator or any of the arithmatic assignment operators (=+,
- etc.).
-
- You could add an alpha character (or delete the space) to turn
- it into a variable name. Unless there is a variable in scope (and of the
- right type) of the form c*d, this is highly unlikely to be the right answer.
-
- Your remaining choices are semi-colon, comma and =. In this case,
- semi-colon and comma are semantically identical, so that's not much of a
- problem. Deciding between = and the others is slightly tricky. You can
- resolve this, in part, by seeing which variables have been initialized.
- If only one of the five variables has been initialized, the answer is
- almost certainly = (otherwise, you'd be assigning something to an
- uninitialized variable). Similarly, if both c and e (for example) have
- just been initialized, you're almost certainly missing a semi-colon.
-
- The "if (a=b) case is much trickier, but I think we could do a pretty
- good job on this as well. There are some idioms [like if
- (fp=fopen(...))] that are clearly intended. For something like "if
- (a=b)" I'd check whether 'a' was unassigned before the 'if' and is used
- only in the body of that conditional (at least, up to a later
- assignment). If so, the assignment is probably intended.
-
- The point of all this is that, in the vase majority of cases, a compiler
- with a little intelligence could guess right most of the time. Whether
- the occasional errors would be worth it (after all, it's just finding
- typos) is a separate question. Natural language grammar checkers guess
- right most of the time as well but I find them more annoying than useful.
-
- Steve
-