aboutsummaryrefslogtreecommitdiff
path: root/ch1/1-24_syntax-checker.c
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2013-04-23 13:33:25 -0500
committerzlg <zlg@zlg.space>2013-04-23 13:33:25 -0500
commit82d318879c897b3d665767d74806cd33fe6791c0 (patch)
treea3d2f41ef4e1d11136a3088784c59c604c20e47d /ch1/1-24_syntax-checker.c
parentSolve Exercise 3-6: itoa (3 arg version) (diff)
downloadknr-82d318879c897b3d665767d74806cd33fe6791c0.tar.gz
knr-82d318879c897b3d665767d74806cd33fe6791c0.tar.bz2
knr-82d318879c897b3d665767d74806cd33fe6791c0.tar.xz
knr-82d318879c897b3d665767d74806cd33fe6791c0.zip
Add exercise descriptions and answers for ch1
* Corrected behavior in solutions for 1-9 and 1-23
Diffstat (limited to 'ch1/1-24_syntax-checker.c')
-rw-r--r--ch1/1-24_syntax-checker.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/ch1/1-24_syntax-checker.c b/ch1/1-24_syntax-checker.c
index 019b9bc..444c562 100644
--- a/ch1/1-24_syntax-checker.c
+++ b/ch1/1-24_syntax-checker.c
@@ -1,22 +1,27 @@
#include <stdio.h>
/* The C Programming Language: 2nd Edition
- * Exercise 1-24:
- * "Write a program to check a C program for rudimentary syntax errors like
- * unbalanced parentheses, brackets, and braces. Don't forget about quotes, both
- * single and double, escape sequences, and comments. (This program is hard if
- * you do it in full generality.)"
*
- * Proksima from Freenode's ##c helped me understand full generality where
- * Ixquick, Wikipedia, and StackOverflow all failed: a program that has full
- * generality handles all use cases. In this case, my program should report no
- * errors from a well formed C source file, and return correct errors for every
- * non-valid C source file.
+ * Exercise 1-24: Write a program to check a C program for rudimentary syntax
+ * errors like unbalanced parentheses, brackets, and braces. Don't forget about
+ * quotes, both single and double, escape sequences, and comments. (This
+ * program is hard if you do it in full generality.)
+ *
+ * Answer: Proksima from Freenode's ##c helped me understand full generality
+ * where Ixquick, Wikipedia, and StackOverflow all failed: a program that has
+ * full generality handles all use cases. In this case, my program should
+ * report no errors from a well formed C source file, and return correct errors
+ * for every non-valid C source file.
*
* I can tackle this one the same way I tackled the previous exercise: with a
- * FSM. The trick is in catching the mismatched levels.
+ * FSM. The trick is in catching the mismatched levels. This happens when,
+ * after the source has been combed, there are values that aren't equal to
+ * zero. Anything that's non-zero means there are too many or too few of a
+ * specific syntax construct.
*
- * Post-solution note: switch() would've made this MUCH shorter...
+ * Post-solution note: switch() would've made this MUCH shorter... but it's not
+ * covered until chapter 3. I think part of the purpose of this exercise is to
+ * teach the value of the switch structure later on. :)
*/
char c;