 Once again, welcome to the Linux programming and scripting class today we are going to continue with the between a typical ticket from where we left off. Let me first summarize for you what we talked about in the last lecture we talked about what is tickle the tool control language essentially it is developed by Osterhout in UC Berkeley again it was originally developed as just a scripting language mainly for just solving some of the difficulties with the existing scripting languages so again like that goes back to why we need the tickle in the subspace the reason is essentially like I mean this is one way to actually use it in applications you know use the one applications as well as extending the various applications so what we mean by that is we saw that in the last lecture that there are two things basically one is on one side of programming is all the heavyweights essentially with very regular data structure and a lot of complex programming and it can take like years to develop and actually bring it online whereas on the other side we wanted a very easy to use highly interactive quick development capabilities for scripting the former one essentially like that we have very complex we can write very complex programs with very highly developed data structures or languages like C, C++ but on the other end we wanted like like just quick scripting that's where the tickle falls into but one thing to understand is actually the tickle by nature is it can actually it's platform independent that's how the tickle was developed so multiple applications can be easily connected through by tickle as well as you can extend an application for new user controlled ideas or user generated ideas using and then we also saw like I mean how can we use tickles so essentially falls under this bucket as to how do we extend and how do we use the various applications tickle so today tickle is very popular just use widely in many many many applications you name any commercial tool today it has a tickle interface and you can use to go to interact with the tool as well as extend its capabilities one thing that we will talk about in this tickle code class is also the synopsis tool set which you will be using extensively and synopsis tool set or also the entire tool set is built on tickle and you can use tickle scripts to communicate to the the tool so this is tools like design compiler or IC compiler things like that we can easily use tickle as an extensible language today it's not just limited to that synopsis tools but other commercial tools also use tickle as their backbone so today we will be talking about the more of the language constructs of tickle so before we go into that I wanted to just give you a brief background on how all the commands are constructed in tickle so there are two parts of learning tickle one is the syntax and substitution moves we saw this one the substitutions are simple but may be confusing at first so we will deal with this and then the second one is all this built-in commands the this can be learned individually as needed and then the control structures are actually command and that's not language syntax so essentially like in tickle even the control structures we will see all this commands so we don't treat anything differently than any other command what that means is say like I mean if you write a command or any some kind of specialized application they also fall fall under the similar treatment as any other command basically within else which are built-in commands so again we call this as not control structure but just built-in commands so we will see like I mean how tickle program looks like or what is the structure of a tickle program and then we will go into more details one thing to note is tickle has no fixed grammar so essentially it is all like there is no like a lexical convention as to how you have programmed so again going back to basics tickle script is just a sequence of commands the commands are separated by new lines semicolons and then essentially a tickle command itself like I mean so now we look at the script is comprised of commands and the command terminations are new lines or semicolons now the tickle command itself each command and have one or more words separated by just white space so the white space has meaning in tickle and then always it is taken as the first word as the command name and all others are arguments and the command always results in a string so those are the things that you need to understand and you need to keep in mind and whenever we talk about any commands just think about these two basic concepts number one tickle script is nothing but sequence of commands and then the commands are separated by either new line or semicolons so these are the only command terminations so if you do not terminate it with a new line it is it still continues as a command so we will see like some examples as to how this plays out in the in the real world because there are these these concepts are also like confusing with respect to like say language like pearl where only the semicolon was the main the main terminator of commands and then tickle command again it is one or more words separated by white space again that is another key difference and very important in other languages you do not need to separate by white space and even the various characters have special means and that is used as a parsing mechanism but in tickle it is it is very simple basically like the white space is treated as word separator and then the command actually has just a number of words and the first word is always the command name and then the remaining ones are all arguments and it also returns a string value so here is one example this command is set a and 22 this is the same as a equals 22 in perl notice that there is no space here you do not need to have any space between you can actually say like dollar rate yeah that that's more makes sense so dollar in world is a variable and then the assignment is assigned to 22 with the terminator as semicolon whereas here there is no dollar here and 22 and there is no termination semicolon and then another very short program puts hello world so here notice that actually like puts is the command name it has only one argument right now which is inside this quote hello world so it just combines all of them and then just outputs that so I think so far so good so let's move on so in terms of how a command is parsed basically there is a division of responsibility inside the tickle parser the tickle parser has two components one is the tickle parser itself and then the other one is a command procedure so they go from the concepts that I talked about earlier so understand that this line is the your tickle command essentially it's just a string of characters that are coming one by one the tickle parser all it does is it chops the commands in the words so this is one long command it basically like takes it and then it basically chops it into first word second word third word port word and now so mainly it so it it also makes some substitution this this part of it we will come to it it does not interpret any values of words so it does not assign anything and it is a single class operation so every command basically the command you know that it is separated by either a new line or a semicolon so it gets all these things that that forms this command and then when it goes through the tickle parser first it just breaks it into multiple words based on just the white space character and the same blank so based on the white space character it just splits it into all these words and then it just sends these things to the command procedure which essentially interprets these words as commands whether it is there and then once the the first one actually like has the command and the remaining ones are arguments it takes in and then it processes and then it produces a string result and then that result is what we store now let's look at all these other things basically like I mean how this entire process works so once again just to recap the there is a division of responsibility inside the tickle parser the parser the true parser basically once it gets the command which is separated by the new line or a semicolon it parses and it actually separates the whole command into multiple words this chopping is based on just that blank space basically that we say and it also makes some such it substitutions which we will see what it is it does not interpret value of the words and it is a single class operation then once it chops up the words it sends it to the command procedure which interprets the words it can invoke the parser recursively meaning you have something that's another command it it can actually like then go back to the tickle parser and expand that and then gets it and finally it produces a string result which is shown here as another string so now let's talk about some of the things first of all there are arguments which are after this one all the remaining ones are the arguments right so the parser assigns no mean to this argument so here you can say like okay in the in C program x equal to 4 y equal to x plus 10 then y is actually 14 because this y is evaluated and then basically like the value state whereas in tickle if you say set x4 and set y x plus 10 the x plus 10 this just retain and basically just get that same and the different commands assign different meanings to their arguments the type checking must be done by the command themselves again we will we will discuss this in more detail but the commands themselves has an onus to see whether they are of the same type and if they are of compatible types and execute it does not go back to the language to provide any kind of guidance as to what this so here we have a set of commands first one set a 112 then we have another command called expr which actually evaluates an expression and we can see actually that there is a fixed point number and the floating point number so now how does this gets interpreted so now the third one is basically the valve eval has a string as an argument and in this example the button dot be it has many many arguments also so button dot be has text as an argument a low is an argument fg is an argument and it is an argument and now another command called string which has an argument of length and then another kind of a string but we do not know what it is but it is just another word so the string has two arguments so now this one has two arguments this is actually three arguments basically and then you have this has only one argument this one has one two three four arguments and this one has this two arguments and they are all of different different different types so this is a string of one type here there are string arguments and all these are also like string argument here there is another string this is a floating point and the fixed point this is a fixed point so again how to distinguish and how to make sure that they are all consistent is left to the particular command that is that is that is getting those arguments so we will see like some of these examples as to how commands will interpret certain arguments now we come to this variable substitution there are two main topics in tickle that you want to understand and once you understood those two concepts I think will be much easier the number one is the variable substitution number two will be the command substitution and this is something that we will talk about in a later slide but today right now we will talk about the variable substitution so the variable substitution the syntax is $ followed by the variable name actually the $ is what gives the tickle to see that okay this is a variable and I will substitute this in one and the variable name can be letters digits and underscores it is it says basically like I mean it is a white lie the main reason is like sometimes you do not put the digits as the first one but you can we will see how it is so and then the other thing is basically like this $ can occur anywhere in the world in the world so now let us look at some of those commands and what happens basically so here let us say we are setting B to 66 now even we say like set A to B the result is just B notice that this is another just a value it is not the same variable in order for getting this B as 66 what do we need to put the key variable substitution syntax which is the $ so now in this command set A $ B now we get AS 66 now what happens when we say like set A $ B plus $ B plus $ B notice that even though like I mean the our intention is like 66 plus 66 or 66 you know and evaluate that we do not have any commands for one reason so it is just going to assign exactly the same variable which is it substitutes every $ B occurrence of every $ B by 66 so the A will be a string which is 66 plus 66 this is not the same as like 196 okay so please note that or actually 198 it does not put it that way only like has the 66 so now what happens when we say like set A is $ B dot 3 so this dot actually it is also applied so here you get 66.3 now what happens when we say like set A $ B 4 is this the same as 664 actually in this case it just says that there is no variable because now the 4 becomes part of the variable name because you can see that actually the variable name is little bit and on the schools so it treats $ B 4 as a single variable and it finds that actually that is never defined so it just complains about no such way now the second aspect of it that I talked about which is the command substitution so for the variable substitution the key character is the $ now for the command substitution the key characters are this square bracket so any script which is embedded within a square bracket it substitutes that or interprets that as a command and then executes that so essentially it is evaluating the script and then substitute the results and it may occur anywhere within a world so let us look at some example here so here set B is 8 so B is set to evaluate so that is the result here and then we say like set A as expression $ B plus 2 so now when we say like the square brackets and then we give another function name which is or a command name which is expr bill so that expr is now needs to be executed because it is kept under square brackets so now it executes this command so when it executes the command it knows that B is 8 so it substitutes 8 here and then it actually adds this also so there is a variable substitution and now a command substitution as well so now it evaluates 8 plus 2 as a command so the answer is 10 and then that it decides to be so here this is 10 now what happens when we say like set A B minus 3 is expression B minus 3 notice that there is no $ in front of B so B is taken as just another just name and this whole thing is a string so it basically like it puts B minus 3 as a string and then it also uses that space is as a string and then when it comes to this square brackets again it substitutes the command essentially so that is dollar B is 8 minus 3 is 5 and if it has B minus 3 is 5 as the string that is stored in A okay now the words break at white space and semicolons except there are few rules on this number one is the double quotes the double quotes prevent breaks because the entire double quote is treated as just one string and then it is taken as one string so for example in this one in this example set A dollar X is I mean X is dollar X and Y is dollar Y this entire thing is assigned to me as you notice in the previous example only the dollar X is substituted dollar Y substituted but this entire string is just assigned to A so the words don't break here essentially it's just one continuous now the second case where it will not break is the curly braces essentially the curly braces themselves is considered as one unit wherever you are using curly braces it's used it's considered as just one word so anything between the the curly braces is one word I want you to understand this concept because we will revisit this over and over again next one so that's another one the third one is the backslashes which quote special characters so here set a word backslash empty with backslash and backslash dollar and backslash and space this entire thing is treated as just one word and then the backslash also can escape new line so so when we say like I mean when we end like one two three four and then is backslash and then we go to five six seven eight this is just considered as one word this is one two three four five six seven eight with no break here or because of the backslash backslash is just escaping the new line so it is a continuation character now one more thing is the substitutions don't change the word structure so me here as an example we set this a as two words and then when we say like said b as dollar a it's not going to change the word structure itself so this is as a treated as one word it's still be assigned to be so there is no nothing there now let's look at some of the tickle substitution rules so and and parsing one thing is the tickle substitution rules are fairly simple and absolute so here are some of the examples so here we do set a 22 column set b 33 this is okay because we have a column so that we know that actually this is one command now we have a command the comment comment is always like receded by the hash symbol and here hash this is the command this is also okay because this happens in a new line and with the first character as the hash now when we say like set a 22 hash same thing this is a wrong one wrong usage because there is no break and basically now you can say that actually a is having like two or more words and all these are arguments but the set a has can set can take only like two arguments basically so this is really not a valid syntax and it comes with an error to correct this one we need to include a semicolon in between where we are now breaking this into two commands and then the second command this happens to be just a comment comment okay so the bottom line is essentially the parser looks at the commands only once essentially does not treat okay now that there is a comment in starting so maybe this kind of command and basically treated as a comment it does not do that and so as a result what happens is we cannot write expressions in just single command we have to use multiple commands sometimes we will talk about one such example slightly later on but I will I would like to give you and motivate you on the example and one thing to note is actually like that that particular kind of version has never been written as a single command or we cannot find the way to write that single command sometimes things get hairy basically like when we put this curly braces with square brackets so the curly brace essentially is a way to that we saw earlier that is to combine words into one you know it prevents the breaks and then look at the the square bracket within basically that is to evaluate that expression so it is a command substitution so now we will go into the command syntax so the tickle essentially like I mean what we learned was the commands are words separated by white space so as it shown here and the first word is a function and all the others are arguments only functions apply meaning to both of them and it is always a single pass tokenizing and substitution and then the substitution can take two forms one is a variable substitution the other one is a command substitution the dollar passes variable come in substitution or variable interpolation and then the square brackets for the command substitution or the command interpolation to prevent the word breaks we can use three main things or you can also extend it to the fourth one the first one is using the codes that prevents the word breaks and then we can use the curly braces that also prevents all the interpolations and then the backslash escapes all the special characters so including any word breaks so this is another way that we can avoid the word break and then the another key thing that we are always talking about is what tickle has no grammar whatsoever so now let us look at some more substitutions so here we can use eval for another level of expansion so and then you can also use command format for complex arguments so exact rm star dot o basically this executes this particular command so again this itself is a command that takes one two arguments and then the first argument being another command that gets executed and here we say basically language start off o no such file because there is no meaning to the star dot o and then if you say low star dot o that gives the two files which are in the directory just a dot o and b dot o now if you say basically exec rm and then execute this command also using the command substitution square brackets yeah it comes up with that and then but it says the no such file or direction because it's treated as just one one full word so it tries to find the file name called a 0 dot o space b dot o and it comes up with no such file so in order to delete these two files in this directory we need to use these eval function so when we say eval then we say exec rm blob star dot o this works correctly and essentially we can now remove these files so eval is used as another level of expansion and there are other ways of writing this also I mean this is like just using like just one line you can also split this whole thing into multiple lines and then you can also like execute the same same things anyway this is one challenge I am going to give you how to get this without using the eval but using multiple lines so try that out we can discuss in the next class now I want to talk about the typical expressions basically it is more see like int and double you can think of this as integer and floating point so we will see like how this works the command variable substitutions all occur within the expression itself and it is used in expr if and other commands so what do we mean by the command and the variable substitutions and how are these expressions done so here is some sample commands that be five so the result is five now we have this command called expr $b times four minus three so the answer is 17 because it's a five this gets substituted with five so it's a variable substitution so that is 20 minus 3 is 17 now we can also say like I mean some logical operation which is probably the general two and since it is not it returns the false value which is actually zero in tickle zero is always false and anything other than zero is always true just keep that in mind now here we also say like I mean some cost function basically two times follow b multiplied by a here you can see that actually it is the floating point number it automatically converts that in floating point number because one of them happens to be the floating point number and usually it is it calculates as the any any data type until the type changes in the type changes it gives that the new type meaning and then the president is essentially like I mean integer has the lowest presence and then the floating point has higher presence in the expr statement so if you put a floating point up front everything is computed as a floating point number if you put the floating point towards the end then until that time it's computed as an integer and then towards the end it is turned into floating point we will see some examples as to how this will affect now the other one is expr $b times fact 4 now here you notice that actually like I mean between the five buckets so this is command substituted basically it computes this fact 4 and then it replaces that with fact 4 and then times the $b so here this also is substituted so it is five times four factorial which becomes 120 so the bottom line is tickle will promote integers to reals then needed all the values translated to one of the same types and then here also like you can notice that actually the expr command knows about the types and the tickle does not tickle is still it's just a collection of words so imagine right so it's just a collection of words and still it is very popular and today lot of programs actually run with this so now let's look at some more examples to understand expr in more detail so the first one is fairly simple now you guys can answer five plus six by two so six by two is evaluated which is three and then basically added to five we get the eight now the next one is five point zero plus six by two again since this is a real number everything is converted into real and then begin an answer of 8.0 which is a real number now it gets slightly interesting so now the next one is five divided by two plus six so it evaluates five divided by two which is actually 2.5 but since this is an integer it leaves these two out so it is just two and then when it adds to six it's eight now this expression again so if you look at it basically it's again five five divided by two which is 2.5 plus six point zero but since when it computes this it's still a integer data type so it does not use this now plus six it adds and then that becomes eight point zero now the interesting thing is instead of putting six point zero i put five point zero divided by two plus six now you look at this actually this is already a real number so the answer also should be real which is now 2.5 now plus six point zero will give you 8.5 so look at these two expressions they are exactly identical but those two have two different answers so this is another caveat that you have to always adhere to when writing tickle programs you know the data type actually changes as it goes so if you have like the variable substitution all over and at some point it turns into like floating point you get a different answer than it was just a real number it was just a integer okay so now let's talk about the tickle arrays in general since we are using strings and words and etc etc the tickle arrays are always associated with the index can be anything that you want it may not be just a integer number it can be anything that you want for example here set x thread so the array representation is x followed by index here the index is called thread and we set that to 44 now we say set x2 is this expression which is dollar dollar x thread so here the command is the variable is substituted to 44 and then the command substitution happens because of the square brackets so this expression is evaluated and you get 50 as the answer and that is a thank you x2 so now if you want to print out the the name so here the the arrays are basically like this name and value so to print out the name we just say array names and the array name is x then it prints these two index well this means thread and two so using this principle we can actually take two dimensional arrays we don't need to have construct the two-dimensional array but we can construct a single-dimensional array and then take it as a two-dimensional array how do we do it here is an example so here we say set a 1 comma 1 as 10 so it appears as if like I mean a is a two-dimensional array with one two three four and then one two three four and then we are making this one one as 10 and then one two but in reality this is just one name so one comma one is a name that has value of 10 and one comma two is another name that has a value of 11 so if you print out the array names a then it prints out together which is 1.1 I mean one comma one and one comma two so now we see that actually like commas can be included in names so now let's look into the one of the things that we saw earlier in more detail this is the expression a dollar a multiplied by pass two star dollar b two multiplied by property so here actually this is evaluated all these things are basically like a and b are substituted so whatever this value that they get substituted and then the expr is called after that so it is substituted and then expr is called and then expr goes to cars and says that hey I don't know this value so recursively that goes back it gets evaluated then it goes back to expression and then you get this answer so the difference here is in this one the dollar a and b are substituted by the scanner before the expr is called whereas in this expression where we are saying expr notice that this curly braces and dollar b star fact 4 essentially here the dog b substituted expr itself the reason is because of this and it needs to have a single word expression so it basically substitutes this so you get again five into these get these are like substituted so this is evaluated and find 120 so the expressions can get substituted more than months so here one example set b is backslash dollar a and then set a is four and then expr dollar b times two now you can see that actually the b gets first substituted with this a and then it looks at the a and actually the is also needs to be substituted so it is actually four times two and some people operators can also work on strings for example is bill bill expr dollar a less than and is going to be zero and then the less than greater than less than or equal to greater than equal equal and then not equal to we can all work on strings only thing is you have to caution yourself when the strings can also look like numbers in general the tickle is always like generating strings so when it is generating a number it can be a strength and you can also use the string compare function to compare any strings now let us talk about the list the lists are nothing but zero or more elements separated by which the thing in a component is the zero essentially it need not be just one and just zero and here red green blue this is a list essentially because it has a white space in the curly braces and the backslashes are for grouping this we saw earlier so here a b cd e f and the cd e is included in the curly braces so this is treated as just one unit so there are actually four words which is a b cd e and then f then we can also like use escape characters for moving so here one escape and then space and then word this is as one so this is one two and two only three words then we have some list related comments which are all these things the concat l index l length l search for each l insert l range l sort l append list and l replace all these things are list-raised commands and one thing to notice all the indices will start with a zero the end means the last element so here use this function called l index l index of this array with two that the second one is actually goes from zero one two and three so the two is this big cd e expression which is which will be and then when we do the l sort of red green and blue it does an alphabetic sort so to put this as one put this as two and then put this as two the lists actually are very powerful syntax in tickle we will learn more about list actually and there are some specific commands that are also I will also go through for a tool like the synopsis tools so a sample command will be set stack is one so that means that the stack gets long now when we say like push stack red the red is pushed ahead of one so one is need to end and then red is pushed and then if you say push stack of fish with the curly braces that gets presidents essentially as the curly braces and then it puts the curly braces a fish as the first element then then followed by one and if you pop the stack then it comes up as just a fish because it's only like the first element is popped and then the remaining ones are kept inside so now the stack has red one but a fish is popped out and then the push and pop are very short and use list commands to do their work essentially now some more interesting facts about lists the true list meaning won't change when it is a rescan now let's look at this example where the first dollar animal blue and dollar animal this is not a list because there are variables here which may not be substituted now fish blue fish red fish blue fish this is a list now red escape fish blue escape fish this is not a list but if you say just list red this one this gives you basically like red and then it puts this as a one collection and now this can be a list since that is a one so one thing in the commands and lists are closely related a command is actually a list and use the value to evaluate the list of list as a command so in summary today we are learning more and more about tickle two things I want you to take away here from this lecture are this variable substitution and the command substitution the variable substitution is using dollar as the variable as the marker for the variable wherever you find like dollar variable name it gets substituted the real value the commands themselves are it identifies the command with the square brackets essentially so then it it substitutes these actual scripts whenever it finds a score bracket and then evaluates that result and then one other key thing that we saw was how does tickle recognize the words essentially we know that actually like words are distinguished by where they break essentially so they break with white spaces or some columns but there are some exceptions to the rule one is the double quotes brings curly braces prevent breaks and substitutions as well as backslashes form and quote the special character and thus eliminate the word separation so words break so this is another key thing that we saw and then in the commands actually the first word is always the function and the other are arguments and only the function apply meaning to the arguments and everything is done in single pass tokenizing and substitution so something to understand in expr is except command basically it stands from left to right it uses the same arithmetic evaluation techniques only thing notice essentially where whenever it encounters any argument which is a floating point from that point onwards everything is completely in floating point so this can pass down serious prediction right program and I want you to be aware of this when you write your own ticket programs and then we also learned about lists and how to use the list so we will revisit again in the next lecture so I think that is pretty much it thank you very much thank you for listening