※ 引述《vito0302 (選擇!!)》之銘言:
: 請問有人有建議的c語言opensource專案可供學習嗎?
http://sourceforge.net/projects/ici/
ICI is a general purpose interpretive programming language
that has dynamictyping and flexible data types with the flow
control constructs and operators of C.
http://www.zeta.org.au/~atrn/ici/Default.html
http://www.zeta.org.au/~atrn/ici/usercontrib.html
http://www.zeta.org.au/~atrn/ici/examples/hello-world.ici
#!/usr/local/bin/ici
printf("Hello, World!\n");
http://www.zeta.org.au/~atrn/ici/examples/grep.ici
#!/usr/local/bin/ici
/*
* grep.ici - simple grep-like program in ICI
*/
static
grep(in, pattern)
{
auto regex;
auto line;
regex = regexp(pattern);
while (line = getline(in)) /* getline() returns NULL at eof */
if (line ~ regex) /* `~' is the "match" operator */
printf("%s\n", line);
}
if (argc < 2)
{
printf(stderr, "usage: %s pattern [file...]\n", argv[0]);
exit(1);
}
if (argc == 2)
grep(stdin, argv[1]);
else
{
auto f, fn;
forall (fn in interval(argv, 2))
{
if (fn == "-")
grep(stdin, argv[1]);
else
{
grep(f = fopen(fn), argv[1]);
close(f);
}
}
}
ICI 是 public domain, 內含 PCRE library.
未使用 yacc or lex. (bison/flex)
Source code 很乾淨.
用途跟 ruby, python, lua 等直譯式語言相同.
my_array = array(1, 2, 3, "word", "world");
printf("%d %s \n", my_array[0], my_array[3]);
=> 1 word
有 array(), struct(), set() 可用.
// struct() 功能: mapping.
$ ici -
st = struct(1, "one", 2, "two", 3, "three");
printf("%s %s\n", st[3], st[2]);
=> three two
$ ici -
ss = set(2, 3, 5, 7, 11, "two", "three");
if (ss[2]) printf("Get 2\n");
if (ss[9]) printf("Get 9\n");
if (ss["two"]) printf("Get two\n");
if (ss["five"]) printf("Get five\n");
=> Get 2
Get two
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.22.98