.net - Parsing Lisp S-Expressions with known schema in C# -


I am working with a service that provides data as Lipp in the form of S expression string. This data is getting thicker and faster, and I want to churn down the batch stream (this single-byte character only) as quickly as possible, without any backtracking. These strings can be quite long and I do not want to churn the GC to allocate the string for the entire message.

My current implementation uses cocoa / r with a grammar, but there are some problems with it. Due to back-tracking, it specifies the whole stream in the string. If I have to do this for my code users then this is also a little bit. I have a pure C # solution Coca / R Parser / Scanner does not allow for reuse of objects, so I have to revive them for each message.

Conceptually, the data stream can be treated as a sequence of S-expressions:

  (item 1 apple) (item 2 banana) (item 3 chains )  

Parsing this sequence will create three objects, the type of each object, in the above case, in the "item", the first value in the list can be determined by the schema of the incoming section / Grammar is well known.

Before starting coding, I would like to know whether there are existing libraries who already do this. I am sure that I am not the first person to get this problem.


Edit

Here's a little more detail about what I want, as I think the basic question Can be a bit unclear.

Viewing some of the contacts, such as:

  (Listen to hello 12.3) (HJ LAJ 1 -0.42) (FRP LF (Pause 2.3 1.7 0.4))  

I want a list of items equal to this:

  {New HiperSeptrate (12.3, "HelloWald"), New Hingjoinstate ("Laj 1", -0.42) , New Force Radiation Detector State ("LF", New Polar (2.3, 1.7, 0.4))  

I am working on the actual data set. I might potentially need deserialise.

Written recurring descent parser is probably simple and at least as fast. Normal pattern will look like this (in Java, C # must be very similar):

  Object readdate (pushback reader) {int sh = in.red; Read the return data (in, f); } Object ReadData (In Pushback Reader, Int CH) {if (ch == '(')) {read readList (in, ch); } And if (inc (ca)) {return number (in, ch); } And if (isSymbolStart (ch)) {return to symbolic (in, f); } And {error (ca); }} ReadList (PushbackReader, int lookAhead) {if (ch! = '(') {Error (ch);} List results = New list (); while (true) {int ch = in.read (); if (F == ')') {break; } And if (WhiteSpace (ch)) {skipWhiteSpace (in); } Else {result.append}; read}} return result;} string reading symbol (in PushbackReader, int ch) {StringBuilder result = new stringbilder; results; amped (f); f); true Is) {int ch2 = in.read (); If (as2m2) (result.append (four) ch2);} and if (is wwwspace (ch2) || ch2 == ')') {unread (CH2); break; } And if (ch2 == -1) {break; } And {error (ch2); }} Return result. String (); }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -