Article View: fa.caml
Article #60[Caml-list] ask for help : how to increase coding efficiency of fun as below
From: xy s
Date: Tue, 15 May 2012 01:00
Date: Tue, 15 May 2012 01:00
57 lines
5881 bytes
5881 bytes
We have defined types:
�
type position = {line : int; col : int };;
type 'a ast = {data : 'a; kids : 'a ast list; posf : position; post: position};;
�
�
And then we transform string to ast:
�
let construct_common_ast s=
��� let len = String.length s in
��� let rec aux i j=
����� if i>j then []
����� else (
������� let k = find_first s "(,)" i in
������� let str = trim (String.sub s i (k-i)) in
������� if k>j || s.[k]=')' then (
��������� if str="" then []
��������� else {data=str; kids=[]; posf=(calc_pos s i); post=(calc_pos s j)}::[]
������� )
������� else if s.[k]='(' then (
��������� let l = next_matched s '(' ')' (k+1) in
��������� let m = find_first_not s " \t\n\r" (l+1) in
��������� if m<=j && s.[m]<>',' then
������������� fail_ast (calc_pos s k) (calc_pos s l) "construct_common_ast: invalid input string"
��������� else
������������� {data=str; kids=aux (k+1) (l-1); posf=(calc_pos s i); post=(calc_pos s l)} :: aux (m+1) j
������� )
������� else {data=str; kids=[]; posf=(calc_pos s i); post=(calc_pos s k)} :: aux (k+1) j
����� )
��� in
��� let trees=aux 0 (len-1) in
List.hd trees;;
�
For construct_common_ast :
# construct_common_ast;;
- : string -> string ast = <fun>
# construct_common_ast "node (function, params(), returns())";;
- : string ast =
{data = "node";
�kids =
� [{data = "function"; kids = []; posf = {line = 1; col = 8};
��� post = {line = 1; col = 16}};
�� {data = "params"; kids = []; posf = {line = 1; col = 17};
��� post = {line = 1; col = 25}};
�� {data = "returns"; kids = []; posf = {line = 1; col = 27};
�� �post = {line = 1; col = 36}}];
�posf = {line = 1; col = 2}; post = {line = 1; col = 37}}.
�
But, it is intolerable to deal with long string. how to increase coding efficiency of this function?
�
Thank you anyway.
Best wishes!
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Technical Details
Message-ID:
<fa.EwCdt2lg1qujtNJeohXpvYCNYzY@ifi.uio.no>Path:
arc1-ca.pugleaf.net!pr3ni26855pbb.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: ff861,88fb114157770769,start
X-Google-NewGroupId: yes
X-Google-Attributes: gidc0fe4b917e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Received: by 10.68.125.201 with SMTP id ms9mr62050pbb.3.1337043629214;
Mon, 14 May 2012 18:00:29 -0700 (PDT)
Path: arc1-ca.pugleaf.net!pr3ni26855pbb.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: xy s <sxy62849013@yahoo.com.cn>
Newsgroups: fa.caml
Subject: [Caml-list] ask for help : how to increase coding efficiency of fun as below
Date: Tue, 15 May 2012 01:00:28 UTC
Organization: Internet mailing list
Lines: 65
Message-ID: <fa.EwCdt2lg1qujtNJeohXpvYCNYzY@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1337043628 12296 129.240.7.9 (15 May 2012 01:00:28 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Tue, 15 May 2012 01:00:28 +0000 (UTC)
To: caml-list@inria.fr
X-IronPort-AV: E=Sophos;i="4.75,590,1330902000";
d="scan'208";a="158377809"
X-Authentication-Warning: walapai.inria.fr: sympa set sender to caml-list-owner@inria.fr using -f
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AjoKAFKqsU9qCpf3Ymdsb2JhbAA3DYIbK7FIFwgMBxUogkMZAQI3ARSJOgEDCplwjw6Cc4UFAiMnAolXAQYKAQGRDgSIYo0ihW4tjRQ
X-IronPort-AV: E=Sophos;i="4.75,590,1330902000";
d="scan'208";a="143808391"
X-Yahoo-Newman-Property: ymail-3
X-Yahoo-Newman-Id: 781201.92524.bm@omp1011.mail.sg3.yahoo.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.cn; s=s1024; t=1337043605; bh=0alZJSHeLqzo8KLLyXbDemvTdi/LVGvw3LNKP1bdTVg=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=5xMWSpCrZZ/WiesiusQN40pr8pEcD1iYb+Xe/w0gJu+UqHOkKNwN70ljMIvvbmDPk03KFeJZ2fkWGC8l5ItVyQ+istjMTFLiLZ3ey1KPPazm2G75MW7pUJHpSKpxqeRGMRjgAvUiK+xOoLjQ+OhDIgIa26hne1h/KM+vRKihqAI=
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=s1024; d=yahoo.com.cn;
h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type;
b=Xkxf+sJcMOLrVxR3V1l7ny0LS/xbRwJaMe8Q58Orfx+CXyQ8L/H/4OaoRAWXXD/dK1uzar2qVKhK6x7Jt7+L9c2lBqQI0Od8o7wXIvZ/+9YemlGv0AckTSuCBqvJ4GLkM7ZRG5i0Pb+3IdqFaE61jtAenEmLpZ5LCPIPIS6vI7I=;
X-YMail-OSG: P77o704VM1kS07N4ON4Z1hs3gbeg1BShQlQxPGzxC3Zf1On
7MiS3OQ01AzcvatDNpHMRFZUK1auSysL5hAY7wyymvDqs015zKsJlMQN8nO.
33JaOT6kAUL5Pz7NwhP0IzgubIAqtD4kCoNpTDEiZ_OJFxOfEDWLfeikxxuv
0YQYlRSxSB5x.KDBOyOhjDVLOwNChbXFNYZ1ejn0VZQbKMDlOCRKEQjZu6i_
QCG1.L5B08Q.3JNMrJ8mMeU8yscTQgP6_svwlkrPqqkwTrL65N_zcykNiIGV
xHMBEbfOQ.sv.f3Hm5c2EtdcfE.5.nATuC4BiCdJd.r_HLz4xqgTVq6_jt1q
TAbuUj6WUz.sSZpzkqMoT7CikMv1Ox8QKf1LRK9lJfhFnEi5Q0uIMvM8isVH
5cB4SQBTvm74brA858siDG6dBmDSTwcG3OKfp_Bk-
X-Mailer: YahooMailClassic/15.0.6 YahooMailWebService/0.8.118.349524
X-Sequence: 4098
List-Id: <caml-list.inria.fr>
List-Archive: <https://sympa-roc.inria.fr/wws/arc/caml-list>
List-Help: <mailto:sympa@inria.fr?subject=help>
List-Owner: <mailto:caml-list-request@inria.fr>
List-Post: <mailto:caml-list@inria.fr>
List-Subscribe: <mailto:sympa@inria.fr?subject=subscribe%20caml-list>
List-Unsubscribe: <mailto:sympa@inria.fr?subject=unsubscribe%20caml-list>
X-FA-Processed: Removed HTML alternative
Original-Date: Tue, 15 May 2012 09:00:05 +0800 (CST)
Original-Message-Id: <1337043605.43298.YahooMailClassic@web15601.mail.cnb.yahoo.com>
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit