From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.straub-nv.de!open-news-network.org!news.ett.com.ua!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Sun, 1 Aug 2010 21:01:21 +0000 (UTC) Organization: ETT newsserver Message-ID: References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> Reply-To: anon@anon.org NNTP-Posting-Host: dialup-4.225.168.100.dial1.dallas1.level3.net X-Complaints-To: usenet@news.ett.com.ua X-Notice: Filtered by postfilter v. 0.6.1 X-Newsreader: IBM NewsReader/2 2.0 Xref: g2news1.google.com comp.lang.ada:12791 Date: 2010-08-01T21:01:21+00:00 List-Id: In <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com>, Natacha Kerensikova writes: >Hi, > >I'm trying to learn Ada, coming from a C background. The first thing I >planned to code is a S-expression parser, because it's quite easy (at >least in C, less than 1000 lines including comments and memory >handling (dynamic arrays reinvented)) and very useful considering >almost all my existing programs use S-expressions as a serialization >format. > >To describe briefly S-expressions, I consider them to be the simplest >existing data organization beyond raw sequences of bits. They are >basically lists of elements, each element being either a list or an >atom, and atoms being raw sequences of bits. > >While I'm still not deep enough into Ada to know how to represent the >lists, I guess there won't be major issues, I think I can handle it >myself (though pointers and hints would still be welcome). > >My question here is about how to represent the atoms in Ada. In C it >was merely a void pointer and a size, but it seems more difficult in >Ada because of the strong typing. Because it's up to the application >to make sense (i.e. type) out of the raw sequences of bits in atoms, >the S-expression library has to handle them as a sort of untyped >memory chunk. Do you know of a way to handle that? > >Please correct me if I'm wrong, but my guess would be that the S- >expression library would provide a Sexp_Atom type, which refers to the >untyped memory chunks, and the application would have procedures to >convert back and forth between Sexp_Atom and whatever types it >internally uses (i.e. serialization and deserialization procedures). >However the library would provide these procedures for the most common >types (e.g. strings and numeric types). > >Though it looks like a fine Ada API (at least to my eyes), I have >absolutely no idea about how to implement the library. How to define >the application-opaque Sexp_Atom type? How to read Sexp_Atom objects >from a file? How to build them from Ada types? How to write them back >to disk? > >Thanks for your help, >Natacha In creating the LISP interpreter, most use: For outside environment to internal: Word or Numeric Text (Text_IO) --> Tokenizer --> Internal Text tree --> Internal List tree If the I/O is to become a VS to your program use the Direct_IO package to create a Indexed binary file where the words and string phases would be stored in one file while the internal access pointers would be stored in the second. Internal Text tree <--> Direct_IO ( Text_Sexp ) Internal List tree <--> Direct_IO ( List_Sexp ) In this design, short term (online) memory storage the access pointer are still valid. In long term storage you would need to remap the List tree to map the Text tree using indexes. So, for long time storage it is better to use the Text_IO, and rebuild the outside environment version of the structures. Internal Word tree --> unTokenizer --> Word or Numeric Text (Text_IO) Internal List tree -->