U E D R , A S I H C RSS

Programming Language Class/2006/Report3

Report 3

Specification

~cpp
C supports two kinds of parameter passing mode, pass-by-value and pass-byreference,
but not pass-by-name. A technique for implementing pass-by-name is to
treat the actual parameters as thunks. Whenever a formal parameter is referenced in a
subprogram, the corresponding thunk compiled for that parameter is executed. Even
though it is difficult to avoid run-time overhead in the execution of thunks, sometimes it
provides a very powerful feature for some applications like a generic summation routine.
Suppose that whenever a programmer wants to pass a parameter by name in C, it is
required to prefix the keyword name just in front of both the actual and formal
parameters as below:
Sum (name i + j, 1, n, name V[i]);
Of course, if a C program with the call statement above is to be compiled by a
conventional compiler, syntax errors should occur since it violates the syntactical rules
of C.
You are required to implement C preprocessor that supports the pass-by-name
parameter-passing method. The preprocessor should transform C programs with name
parameters into pure C programs so that the transformed programs manage to handle
parameters prefixed with name as if they were called by name without causing any
syntax errors.
μˆ™μ œμ˜ μ΄ν•΄λΌ μœ„ν•΄μ„œ μš°μ„  thunks λΌλŠ” λ‹¨μ–΄μ˜ 의λΈλΌ μ•Œμ•„μ•Όν•©λ‹ˆλ‹€.
thunks λŠ” 두가지 의λΈλ‘œ ν•΄μ„λ©λ‹ˆλ‹€. 첫번째, ν•¨μˆ˜ν˜• μ–Έμ–΄μ—μ„œ λ§ν•˜λŠ” μ§€μ—°ν˜• 계산 λ‘λ²ˆμ§Έ, ν˜Έν™˜μ„±μ˜ 이유둜 μ„œλ‘œλ‹€λ₯Έ λ°μ΄ν„°ν˜• κ°„μ˜ 맀핑을 ν–‰ν•˜λŠ” ν–‰μœ„
이번 μˆ™μ œμ—μ„œ κ΅¬ν˜„ν•˜λ €λŠ” 것은 첫번째의 의λΈλ‘œ μ§€μ—°ν˜• 계산(delayed computation)을 의λΈν•©λ‹ˆλ‹€. call-by-name, call-by-needλΌ ν†΅ν•΄ ν•¨μˆ˜μ—κ²Œ λ„˜μ–΄μ˜€λŠ” 일련의 λ§€κ°œλ³€μˆ˜λΌ thunkλΌλŠ” μ΄λ¦„μœΌλ‘œ λΆ€λ¦…λ‹ˆλ‹€. κ°„λ‹¨νžˆ 말해 thunkλΌλŠ” 것은 μ‹€ν–‰μ‹œμ— κ³„μ‚°λ˜μ–΄ λ³€μˆ˜μ˜ 값이 μ–»μ–΄μ§„λ‹€λŠ” 의λΈμž…λ‹ˆλ‹€. (μ΄λŠ” 기쑴의 ν•¨μˆ˜μ—μ„œ νŒŒλΌλ©”ν„° νŒ¨μ‹±μ—μ„œ Call μ‹œμ— λ³€μˆ˜μ— λ°”μΈλ”©λ˜λŠ” κ²ƒκ³ΌλŠ” λ‹€λ¦…λ‹ˆλ‹€.) 이런 κΈ°λŠ₯이 졜초둜 κ΅¬ν˜„λœ Algol60μž…λ‹ˆλ‹€.

Requirement
~cpp
x = sigma(i=1, n) {V}

1) Your program should handle Jensen’s device; show that your program works
properly by testing it for various summation below.
2) You are also recommended to check if Swap (x, y) does work properly or not
by passing parameters by name.
3) You have to show off the robustness of your program by checking various
error conditions.
Jensen's Machine 은 JΓΈrn JensenλΌλŠ” μ‚¬λžŒμ΄ Algol 60을 μ œμ•ˆν•˜λŠ” λ³΄κ³ μ„œμ—μ„œ μ œμ‹œν•œ ν”„λ‘œκ·Έλž˜λ° ν…Œν¬λ‹‰μ„ λ§ν•©λ‹ˆλ‹€.
~cpp
  begin integer i;
     real procedure sum(i, lo, hi, term);
          value lo, hi; integer i, lo, hi; real term;
          comment term is passed by-name;
     begin real temp; temp := 0;
           for i := lo step 1 until hi do
              temp := temp + term;
           sum := temp
     end;
     print( sum(i, 1, 100, 1/i))
  end
μ œμ‹œλœ λ¬Έμ œλŠ” 상기와 κ°™μœΌλ©°, μ΄λŠ” 100번째의 μ‘°ν™”μˆ˜λΌ κ΅¬ν•˜λŠ” λ¬Έμ œλΌ ν•΄κ²°ν•˜λŠ” λ°©λ²•μž…λ‹ˆλ‹€. 차후에 κ·Έ 이름도 유λͺ…ν•œ Knuth λ‹˜κ»˜μ„œ Man Boy Test둜 λ°œμ „μ‹œμΌ°μŠ΅λ‹ˆλ‹€.
μ†ŒμŠ€κ°€ 잘 이해가 μ•ˆλ˜μ‹ λ‹€λ©΄... -_-; 계속 λ³΄μ‹œλΌκ³  λ°–μ—”;;;
cf) Jensen's Device, Man Boy Test λŠ” Compiler Theory 의 ν•œ ν•­λͺ©λ“€μž…λ‹ˆλ‹€.

Hand-In
~cpp
You should follow the guideline suggested later. To be specific, your report is
supposed to include an external documentation as well as an internal documentation.
The external documentation should explain your program in detail so that we can
understand what kind of data structures have been used, the characteristics and general
as well as unique features of your program, etc. An internal documentation means the
comment attached in your source.
You are supposed to upload your source program and executable file. You are also
required to submit a listing of your program and a set of test data of your own choice,
and its output, when you show up for demo. Be sure to design carefully your test data
to exercise your program completely.

brief note

음 잠깐 ν•˜λ©΄μ„œ μƒκ°ν•œκ±΄λ°.... 이 μˆ™μ œ μ •λ§λ‘œ ꡬ리닀. -_- λ‚΄κ°€ μ΄λ ‡κ²Œ 재λΈμ—†λŠ” μˆ™μ œλΌ ν•˜κ²Œλœκ±΄ νŒŒμΌκ΅¬μ‘°λ•Œ binary 가지고 μž₯λ‚œμΉœ 이후 처음인λ“ν•˜λ‹€. λ¬Έμžμ—΄ μž₯λ‚œν• κΊΌλ©΄ νŽ„λ‘œν•˜κ²Œ ν•΄μ£Όλ˜μ§€... C λ¬Έμžμ—΄ ν•¨μˆ˜ 가지고 λ†€λ €λ‹ˆ... μ •λ§λ‘œ κ΅¬λ¦¬λ‹€λΌλŠ” 생각뿐~ - eternalbleu
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:24:02
Processing time 0.0132 sec