CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 20:14:56 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=39eb73dda7c9e072efbb4436a97cecab8b5d484c0104b4bcc2d931f9041c08e5a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22EPsxU_e9S1VpQsPn-vZotd1Q7gbYs7Bj%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d106d13c51f470-BLR
logic expressions parser - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns lec.parser
- (:require [clojure.string :as cs]))
- (def valid-chars (set "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
- (def operators (set "&|>=+"))
- (def char->operator {\& :and, \| :or, \> :implies, \= :iff, \+ :xor})
- (defn- section
- "Must be used with a string that starts with '(', and will return
- a vector of what is inside of that clause, and whats after.
- (section '(a & (b | c)) > d' ) => ['a & (b | c)', ' > d']"
- [xs]
- (-> (fn [[n acc xs]]
- (case (first xs)
- \( [(inc n) (conj acc (first xs)) (rest xs)]
- \) (if (= n 1) [(dec n) acc (rest xs)]
- [(dec n) (conj acc (first xs)) (rest xs)])
- [n (conj acc (first xs)) (rest xs)]))
- (iterate [1 [] (rest xs)])
- (->> (drop-while (comp not zero? first))
- (first)
- (rest))))
- (defn parse
- "For parsing logic formulas like: !(a & b) > ((c + b) | (a = d))
- (Input mus not have spaces) to something like:
- [[:not ['a' :and 'b']] :implies [['c' :xor 'b'] :or ['a' :iff 'd']]]"
- [xs]
- (cond
- (not (some operators xs)) ; Just a literal
- (if (= \! (first xs))
- [:not (apply str (rest xs))]
- (apply str xs))
- (= (take 2 xs) '(\! \()) ; negation of a nested expression
- (let [[a b] (section (rest xs))]
- (if (empty? (filter (partial not= \)) b))
- [:not (parse a)]
- [[:not (parse a)] (char->operator (first b)) (parse (rest b))]))
- (= \( (first xs)) ; nested expression
- (let [[a b] (section xs)]
- (if (empty? (filter (partial not= \)) b))
- (parse a)
- [(parse a) (char->operator (first b)) (parse (rest b))]))
- :else
- (let [[a b] (split-with (comp not operators) xs)]
- [(parse a) (char->operator (first b)) (parse (rest b))])))
Advertisement
Add Comment
Please, Sign In to add comment
-
π Swapzone +37% glitch β O
JavaScript | 6 sec ago | 0.25 KB
-
π ChangeNOW Exploit
JavaScript | 9 sec ago | 0.24 KB
-
β
β Make huge profits on trading ββ 5
JavaScript | 14 sec ago | 0.25 KB
-
π΅ Make 3000$ in 20 minutes π΅
JavaScript | 23 sec ago | 0.24 KB
-
ββ
Marketplace Glitch β
Working β
NEVER SEEN...
JavaScript | 23 sec ago | 0.25 KB
-
ββ
Exploit 2500$ in 15 Minutesβββ 7
JavaScript | 32 sec ago | 0.25 KB
-
π Swapzone +37% glitch
JavaScript | 32 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)ββ 1
JavaScript | 42 sec ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand