vak: (Default)
[personal profile] vak
В мае 1994 года в ньюсгруппе comp.sources.misc появилось сообщение, озаглавленное: "v42i088: cfoogol - A compiler for a tiny ALGOL-like language, Part01/01". В нём предлагались исходные тексты компилятора с простого алголоподобного языка Foogol. Вот пример программы на Фугол, вычисляющей простые числа:
begin
integer n, div, sub, test, testcopy, found, max;
n := 0; test := 2; max := 10; /* number of primes wanted */
while n # max do begin
div := test-1; found := 0;
while div-1 do begin
testcopy := test; sub := 0;
while testcopy do begin
sub := sub+1; if sub = div then sub := 0;
testcopy := testcopy-1
end;
if sub = 0 then found := 1;
div := div-1
end;
if found = 0 then begin
n := n+1;
printn(test); prints(" is prime number "); printn(n); print
end;
test := test+1
end
end
Осовремененные исходники на Гитхабе: github.com/sergev/cfoogol

Если кому интересно разобраться, как пишутся компиляторы - рекомендую файл fc.c. Всё можно прочитать и понять за полчаса.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org