s-expression

Parsing S Expression

陌路散爱 提交于 2019-12-08 07:57:53
问题 Given the following definitions that make up an S Expression from Prof. Yorgey's course: data Atom = N Integer | I Ident deriving Show and data SExpr = A Atom | Comb [SExpr] deriving Show What should the full data type be (in Haskell) for the following? (bar (foo) 3 5 874) 回答1: I believe it would be something like Comb [ A (I "bar") , Comb [ A (I "foo") ] , A (N 3) , A (N 5) , A (N 874) ] Whenever you encounter an open parenthesis you would start a new Comb expression, so (foo) is Comb [A (I

How to safely read untrusted Clojure code (not just some serialized data)?

眉间皱痕 提交于 2019-12-05 21:44:27
问题 (def evil-code (str "(" (slurp "/mnt/src/git/clj/clojure/src/clj/clojure/core.clj") ")" )) (def r (read-string evil-code )) Works, but unsafe (def r (clojure.edn/read-string evil-code)) RuntimeException Map literal must contain an even number of forms clojure.lang.Util.runtimeException (Util.java:219) Does not work... How to read Clojure code (presering all '#'s as themselves is desirable) into a tree safely? Imagine a Clojure antivirus that want to scan the code for threats and wants to work

Is there something similar to Nokogiri for parsing Ruby code?

牧云@^-^@ 提交于 2019-12-05 18:37:13
问题 Nokogiri is awesome. I can do things like #css('.bla') which will return the first matching element. Right now we need to do some parsing of Ruby source code - finding all methods within a class etc. We're using the ruby_parser gem, but all it does is comb your source code and spit out S-expressions. Is there anything like Nokogiri for these S-expressions which can do things like "return S-expression for first method found named 'foo'"? 回答1: The only thing I can think of, is Adam Sanderson's

Is there a C# utility for matching patterns in (syntactic parse) trees?

梦想与她 提交于 2019-12-05 15:36:47
问题 I'm working on a Natural Language Processing (NLP) project in which I use a syntactic parser to create a syntactic parse tree out of a given sentence. Example Input: I ran into Joe and Jill and then we went shopping Example Output: [TOP [S [S [NP [PRP I]] [VP [VBD ran] [PP [IN into] [NP [NNP Joe] [CC and] [NNP Jill]]]]] [CC and] [S [ADVP [RB then]] [NP [PRP we]] [VP [VBD went] [NP [NN shopping]]]]]] I'm looking for a C# utility that will let me do complex queries like: Get the first VBD

Parsing Lisp S-Expressions with known schema in C#

…衆ロ難τιáo~ 提交于 2019-12-05 05:44:49
问题 I'm working with a service that provides data as a Lisp-like S-Expression string. This data is arriving thick and fast, and I want to churn through it as quickly as possible, ideally directly on the byte stream (it's only single-byte characters) without any backtracking. These strings can be quite lengthy and I don't want the GC churn of allocating a string for the whole message. My current implementation uses CoCo/R with a grammar, but it has a few problems. Due to the backtracking, it

S-Expressions parsing

微笑、不失礼 提交于 2019-12-05 00:51:42
问题 I ran into this question earlier today: Example Input: I ran into Joe and Jill and then we went shopping Example Output: [TOP [S [S [NP [PRP I]] [VP [VBD ran] [PP [IN into] [NP [NNP Joe] [CC and] [NNP Jill]]]]] [CC and] [S [ADVP [RB then]] [NP [PRP we]] [VP [VBD went] [NP [NN shopping]]]]]] I was about to suggest simply parsing the expected output (as it looks like an s-expression) into an object (in our case a tree) and then using simple LINQ methods to process it. However, to my surprise, I

Parsing and building S-Expressions using Sets and binary search tree

别说谁变了你拦得住时间么 提交于 2019-12-04 21:29:12
This is pseudo homework (it's extra credit). I've got a BST which is an index of words that point to the lines (stored somewhere else) that contain the words. I need to implement a way to search using s-expressions so I can combine and (&) and or (|). At the command prompt a user could type something like: QUERY ((((fire)&(forest))|((ocean)&(boat)))&(water)) Essentially that should return all lines that contain the words fire, forest and water as well as all lines that contain ocean, boat and water. What I really need help with is the logic for parsing and inserting nodes into the tree to

jq or xsltproc alternative for s-expressions?

瘦欲@ 提交于 2019-12-04 16:10:15
I have a project which contains a bunch of small programs tied together using bash scripts, as per the Unix philosophy. Their exchange format originally looked like this: meta1a:meta1b:meta1c AST1 meta2a:meta2b:meta2c AST2 Where the : -separated fields are metadata and the AST s are s-expressions which the scripts pass along as-is. This worked fine, as I could use cut -d ' ' to split the metadata from the ASTs, and cut -d ':' to dig into the metadata. However, I then needed to add a metadata field containing spaces, which breaks this format. Since no field uses tabs, I switched to the

How to safely read untrusted Clojure code (not just some serialized data)?

若如初见. 提交于 2019-12-04 04:56:25
(def evil-code (str "(" (slurp "/mnt/src/git/clj/clojure/src/clj/clojure/core.clj") ")" )) (def r (read-string evil-code )) Works, but unsafe (def r (clojure.edn/read-string evil-code)) RuntimeException Map literal must contain an even number of forms clojure.lang.Util.runtimeException (Util.java:219) Does not work... How to read Clojure code (presering all '#'s as themselves is desirable) into a tree safely? Imagine a Clojure antivirus that want to scan the code for threats and wants to work with data structure, not with plain text. First of all you should never read clojure code directly

Emacs: bulletproof up-list?

此生再无相见时 提交于 2019-12-04 04:26:42
问题 I'm getting up-list: Scan error: "Unbalanced parentheses" from this position: (foo "bar|") Snippet from up-list doc: This command assumes point is not in a string or comment. So this is the expected behavior. But I don't care. I just want to go upwards from a list. Could someone suggest an up-list clone that does the proper thing? I'm looking for something better than this naive code: (defun up-list-naive () (interactive) (while (not (ignore-errors (up-list) t)) (forward-char))) 回答1: EDIT: