Re: [問題] 在自製語言中,如何表示函數和物件

看板Programming作者 (影斯作業系統)時間7年前 (2017/04/25 01:36), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串3/3 (看更多)
ici 4.x 完全符合你的規格。 parse.c: 不用 yacc/bison: http://ici.cvs.sourceforge.net/viewvc/ici/ici/parse.c\ ?revision=1.51&content-type=text%2Fplain object.c http://ici.cvs.sourceforge.net/viewvc/ici/ici/object.c\ ?revision=1.43&content-type=text%2Fplain https://sourceforge.net/projects/ici/ https://en.wikipedia.org/wiki/ICI_(programming_language) http://ici.sourceforge.net/faq.html http://atrn.org/ici/ What is ICI? ICI is a C-like, high level language originally developed by Tim Long and placed into the public domain. ICI marries C's expression syntax, control structures and overall feel , with a dynamic, garbage collected, object-based, data model. Although ICI superficially resembles C, and is easy to use for C programmers, its data model is very different, higher level with types such as (real) strings, regular expressions, dynamic arrays, sets and dictionaries (struct). ICI's aggregate types are immediately useful without any extra programming typically required in C. ICI's automatic module loading, memory management and error handling frees the programmer from much of the drudgery associated with developing in C and lets you concentrate on what the program is doing rather than how it is doing it. With programs that are not overly performance critical or are I/O bound ICI makes a useful alternative to compiled languages. Even for performance critical applications the use of native-code modules in the correct areas is typically all that is required to allow development in a higher level language. 作者: 我 看板: 我的公開個版(SayYA 資訊站,已倒站?) 標題: [ici] ICI 簡介 時間: Sun Jul 14 07:01:53 2002 ICI 簡介. ICI source code is in public domain. Homepage: http://www.zeta.org.au/~atrn/ici/ Files: http://www.zeta.org.au/~atrn/ici/distfiles/ici-3.0.1.tar.bz2 http://www.zeta.org.au/~atrn/ici/distfiles/ici-modules-0.2.0.tar.bz2 ICI Main FTP Site: (ici2) ftp://ftp.research.canon.com.au/pub/misc/ici/ ICI Mail List: Send mail to "ici-request@research.canon.com.au" With the text "subscribe" in the body of the message. http://www.escribe.com/software/ici/index.html Freebsd ports: (ici3, 3.0.1) su - cd /usr/ports/lang/ici make install CVS: (ici4) cvs -d:pserver:anonymous@cvs.ici.sourceforge.net:/cvsroot/ici login cvs -d:pserver:anonymous@cvs.ici.sourceforge.net:/cvsroot/ici co ici cvs -d:pserver:anonymous@cvs.ici.sourceforge.net:/cvsroot/ici co ici-modules Related work: CINT http://root.cern.ch/root/Cint.html Python http://www.python.org EiC http://www.kd-dev.com/~eic (Artistic License) elastiC http://www.elasticworld.org ici-3.0.1 的安裝 makefile 似乎有點問題. cp *core*.ici /usr/local/lib/ici/ ln -s /usr/local/lib/ici /usr/local/lib/ici3 ln -s /usr/local/include/ici /usr/local/include/ici3 cvs 中的版本要手動將 Makefile.linux 中的 ici3 改成 ici4, 移除 wrap, skt. ICI 使用起來較順手. (如果熟練 C 的話.) 而且內含 PCRE (Perl-compatible regular expressions) library. 與 perl 主要的語法不同是 perl: /regexp/ ici: #regexp# 標題: [ici] perl01.ici 時間: Fri Oct 31 21:30:39 2003 // [ici] perl01.ici /* perlreftut (p3 of 16) 如何表述一個值為串列的雜湊,是 Perl 4 中常出現的一個問題。 當然,Perl 4 有雜湊,但值需為純量﹔不能是串列。 為什麼你會需要一個串列的雜湊? 讓我們看看一個例子: 你有一個城市和國家 名稱的檔案,像這樣: Chicago, USA Frankfurt, Germany Berlin, Germany Washington, USA Helsinki, Finland New York, USA 而你希望產生一個如下的輸出,每個國家印一次,然後是這個國家中照字母順序 排列的城市清單: Finland: Helsinki. Germany: Berlin, Frankfurt. USA: Chicago, New York, Washington. 這是早先我所提出的問題的答案,關於如何重新編排一個國家和城市名稱的檔案 。 1 while (<>) { 2 chomp; 3 my ($city, $country) = split /, /; 4 push @{$table{$country}}, $city; 5 } 6 7 foreach $country (sort keys %table) { 8 print "$country: "; 9 my @cities = @{$table{$country}}; 10 print join ', ', sort @cities; 11 print ".\n"; 12 } */ // join() from ici 3.x icipath.ici extern join(head, sep) { auto vargs = [array]; auto comp; if (typeof(head) == "array") { vargs = interval(head, 1); head = head[0]; } forall (comp in vargs) head = sprintf("%s%s%s", head, sep, comp); return head; } table = struct(); while(s = getline(stdin)) { // tmp = s ~~~ #(.*), (.*)#; // Using PCRE library. tmp = gettokens(s, ","); city = tmp[0]; country = tmp[1]; if (table[country]) { push(table[country], city); } else { table[country] = array(city); } } // perl01.ici, 56: argument 1 of sort() incorrectly supplied as a struct // forall(value, key in sort(table)) { forall(value, key in table) { printf("%s: ", key); cities = sort(value); // printf("%s", str.join(cities, ", ")); // ici 4.x with str module. printf("%s", join(cities, ", ")); printf(".\n"); } /* ici perl01.ici // ici 4.x with str module. Chicago, USA Frankfurt, Germany Berlin, Germany Washington, USA Helsinki, Finland New York, USA (Ctrl-D) Segmentation fault */ /* ici perl01.ici Chicago, USA Frankfurt, Germany Berlin, Germany Washington, USA Helsinki, Finland New York, USA (Ctrl-D) Germany: Berlin, Frankfurt. USA: Chicago, New York, Washington. Finland: Helsinki. */ ※ 引述《Neisseria (Neisseria)》之銘言: : 小弟先前沒事寫一個計算機 : 目前寫了 lexer, parser, interpreter : 有自製的 AST (abstract syntax tree) : 為了練功,這些功能沒依賴 yacc 或其他外部套件 : 有以下功能: : - 可處理整數和浮點數 : - 有變數的概念,可 chained assignemnt : - 簡易代數運算,像 (123 + 45)**(5 % 3) : - 常見數學公式,像指對數、三角函數等 : (直接 call host language 的相關功能) : 卡在函數 (function) 和物件 (class) 不知道如何表示 : 希望板上各位大大提示一些方向 : 目前先以 interpreter 為目標 : 因 compiler 還牽涉到轉機械碼的過程 : 目前對小弟來說太硬了 : 先在這裡謝過各位大大 -- https://youtu.be/MMWBPklrRB4
小雞逼逼(崩潰版) https://youtu.be/KlZL1hqGxDg
《江南夜色》 https://youtu.be/WIW16vMdrZU
《告白氣球》 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.17.145 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1493055404.A.3AA.html

04/25 06:22, , 1F
感謝大大提供資訊,可以好好讀一下
04/25 06:22, 1F

04/25 06:23, , 2F
ICI 的程式碼來學習程式語言
04/25 06:23, 2F
文章代碼(AID): #1O_ZUiEg (Programming)
文章代碼(AID): #1O_ZUiEg (Programming)