Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

SCLOG: one more bicycle that has all signs of programming language

0.00/5 (No votes)
30 Aug 2011 2  
A way to view, store and process logical expressions

When we reached the point to develop user defined actions and filters our interface designer Michael hung. He was thoughtfully staring at the window and smoking one after another, from time to time he started thrashing the punching bag shouting something obscene. Actually, he had non-trivial task: at the last planning meeting it was stated that forcing users create rules in plaintext manner is not user-friendly and non-intuitive.


When the third day came, Michael shouted: "Bingo! We’ll have a tree!" The idea was quite simple: display a logical rule as a tree where brunches represent logical "and" or "or" and leaves represent some logical conditions. The command liked the idea, and he started "creating". For several days he stared at monitor knocking keyboard muttering something obscene. Once he asked me how we were going to store the tree, I was deep in optimizing SQL-queries and said without actual thinking: "In the string, of course."


And finally I was staring at this:

&( s_!=~( city , " Saint- " ) , s_=( platform , " Linux " ) , i_>( screenw , 1024 ) , i_>( screenh , 800 ) , |( i_>( viewed , 7 ) , i_>=( timeonsite , 30 ) ) )

Representing the following tree:

old tree-builder

After having look at this string, I told myself: "It looks like a program directive." So, some experiments and test were done and it was found out to be reasonable just to make an interpreter for this language. We’ve called it "scisp" at a very start because of many brackets, but after some thinking we decide that it deals more with logic than with lists, and the language got it final name "SCLOG."


Now SCLOG has two data types ("string" and "integer"), two logical operations ("and" and "or") , four string comparisons ("equal", "not equal", "contains", "not contains"), six integer comparisons ("equal", "not equal", "less", "greater", "less or equal", "greater or equal"), visual tree-building tool written with jQuery for web and php-interpreter.


The string shown upper, has the following form:

&(!~(city,"Saint-"),=(platform ,"Linux"),>(screenw,1024),>(screenh,800),|(>(viewed,7),>=(timeonsite,30)))

Useless spaces gone and operators got more reasonable representations, and the tree visual representation evaluated to the following completely editable with CSS:

tree-builder


What's next:


  • New data types: boolean, datetime, float and arrays;
  • C# interpreter.



Links:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here