hints.doc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .sp 1.5i
  2. .nr H1 7
  3. .NH
  4. Hints to change the standard
  5. .nh
  6. .sp
  7. .LP
  8. We encoutered some difficulties when the compiler was developed. In this
  9. chapter some hints are presented to change the standard, which would make
  10. the implementation of the compiler less difficult. The semantics of Pascal
  11. would not be altered by these adaptions.
  12. .sp 2
  13. .LP
  14. \- Some minor changes in the grammar of Pascal from the user's point of view,
  15. but which make the writing of an LL(1) parser considerably easier, could be:
  16. .in +3m
  17. .nf
  18. field-list : [ ( fixed-part [ variant-part ] | variant-part ) ] .
  19. fixed-part : record-section \fB;\fR { record-section \fB;\fR } .
  20. variant-part : \fBcase\fR variant-selector \fBof\fR variant \fB;\fR { variant \fB;\fR } .
  21. case-statement : \fBcase\fR case-index \fBof\fR case-list-element \fB;\fR { case-list-element \fB;\fR } \fBend\fR .
  22. .fi
  23. .in -3m
  24. .LP
  25. \- To ease the semantic checking on sets, the principle of qualified sets could
  26. be used, every set-constructor must be preceeded by its type-identifier:
  27. .nf
  28. .ti +3m
  29. set-constructor : type-identifier \fB[\fR [ member-designator { \fB,\fR member-designator } ] \fB]\fR .
  30. Example:
  31. t1 = set of 1..5;
  32. t2 = set of integer;
  33. The type of [3, 5] would be ambiguous, but the type of t1[3, 5] not.
  34. .fi
  35. .LP
  36. \- Another problem arises from the fact that a function name can appear in
  37. three distinct 'use' contexts: function call, assignment of function
  38. result and as function parameter.
  39. .br
  40. Example:
  41. .in +5m
  42. .nf
  43. \fBprogram\fR function_name;
  44. \fBfunction\fR p(x : integer; function y : integer) : integer;
  45. \fBbegin\fR .. \fBend\fR;
  46. \fBfunction\fR f : integer;
  47. \fBbegin\fR
  48. f := p(f, f); (*)
  49. \fBend\fR;
  50. \fBbegin\fR .. \fBend\fR.
  51. .fi
  52. .in -5m
  53. A possible solution in case of a call (also a procedure call) would be to
  54. make the (possibly empty) actual-parameter-list mandatory. The assignment
  55. of the function result could be changed in a \fIreturn\fR statement.
  56. Though this would change the semantics of the program slightly.
  57. .br
  58. The above statement (*) would look like this: return p(f(), f);
  59. .LP
  60. \- Another extension to the standard could be the implementation of an
  61. \fIotherwise\fR clause in a case-statement. This would behave exactly like
  62. the \fIdefault\fR clause in a switch-statement in C.
  63. .bp