CS2112: Exercises + Answers from $19 Language Design & Implementation \- Identifiers

* Some languages treat upper-case and lower-case names as distinct (e.g. Pascal), some as being the same (e.g. Ada), and some only allow one case. How would you recognise and match names in an Ada compiler?
Some languages ignore characters in names past some limit. e.g. in ANSI C, only the first 6 characters of extern identifiers have to be checked (although more can be) and their case can be ignored. How could you use Lex and Yacc to check ANSI C programs for identifiers that might be confused by a compiler/linker that only provided the minimum facilities? How could you use #define to avoid any problems thus detected?

?

* List all the data structures you can think of that could possibly be used for a namelist - which of them would you prefer to use and why? Can you imagine any circumstances in which you would pick a different one?

?

* What identifiers do Lex and Yacc (i.e. the parser generators themselves, not the parsers they generate) each have to deal with, and so what do they need in the way of dictionaries?
What about other Unix tools that you are familiar with, like Ksh?

?

* Check your favourite compilers to see what happens if you misspell an identifier. Do you get just one error message? If you repeatedly misspell it in the same way, are the error messages repeated?

?

* Write a set of C declarations that uses all the different kinds of declarations, and all the sorts of types, that you can think of, and then give the corresponding dictionary entries.

?

+ How would you change the semantics of C to simplify semantic analysis? What useful features of the language would be lost by this simplification?

?

<top of 2nd column>