Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / PHP
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
30 Aug 2011CPOL2 min read 20.7K   2   4
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer netrox (sc)
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralInteresting story. Pin
Dr.Walt Fair, PE31-Aug-11 8:27
professionalDr.Walt Fair, PE31-Aug-11 8:27 
GeneralRe: Thanx Pin
Alexander Kouznetsov31-Aug-11 19:36
Alexander Kouznetsov31-Aug-11 19:36 
GeneralReason for my vote of 5 good job Pin
Manimal9930-Aug-11 7:09
Manimal9930-Aug-11 7:09 
GeneralRe: Thanx Pin
Alexander Kouznetsov31-Aug-11 19:36
Alexander Kouznetsov31-Aug-11 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.