Ychydig i chi i'n hoffa, sy'n gweithio i siaradol? Ychydig i chi i'n hoffa, rydyn ni'n gofynu'r ymateb yma ar y cymdeithas a'r cymwylliant pethau. Mae gwirio'r llad yn dweud James Tickham a rydyn ni'n hoffa ar y cymdeithas ar 2002 ac mae'n rhan i'r pryd yn hoffa a yn ymwyllteb. Rydyn ni'n cymdeithio ar y ddechrau ac rydyn ni'n gofynu'r cymdeithas, ar y ffordd y ffynedd. There is only one left for today. I'll bring another 10 tomorrow, so if you come and find me, if you don't get hold of this one at the end of the talk, come and find me tomorrow and I hopefully will have some more. Yes, PHP, so how many people know roughly this cycle of how it works already? Okay, about half, okay, cool. So, for the benefit of everyone, PHP code is fed into this thing called Alexa. Don't worry about what it means yet, I'll explain that in due course. This Alexa generates these things called tokens, you may have heard of these.  The AST is then compiled by this compiler thing to generate these things called opcodes. You've probably heard of those. And the opcodes are stored in this thing called the opcash, which hopefully you've heard of that, and is executed in this thing called a virtual machine. That's basically how PHP works. The virtual machine thing is not like vagrant or anything like that. It's like a virtual CPU that executes these opcodes and runs them, makes it do things, right? The AST part of that is new in PHP 7. Well, I say new because PHP 7 is not that new anymore. But yeah, it was introduced in PHP 7 and it was quite a dramatic change to how the engine works underneath. So let's have a look at how this actually works. So we start off with Alexa, right? The Alexa in PHP is a generated program written in C. I say it's generated because to write one of these things by hand is a bit silly. It's time consuming and it's complicated. So we have a generator to do it for us. R2C or R2C, however you prefer to say those things, is the Lexa generator tool that PHP uses. There are others available, other programming languages, you will use different ones. So we have this file, zendlanguagescanner.l. This is the syntax definition, if you like, of PHP. And this describes how the tokens are formed and how they're split out and so on. And this is what it might look like. A very simple example, right? The format is quite common. It's similar to this thing called Flex, which stands for fast lexical analyser. Incidentally, that is used by HHVM, which is the alternative PHP runtime that Facebook built and now only runs hack as far as I know. But these are a few very simple examples, right? In the angle brackets here, we have ST in scripting. So these are the current states where these tokens will be matched. Alexa is a state machine, so as you go through, you can change the state of where you are. So you're in scripting or maybe you're in double quotes or in a here doc or now doc and things like that. So you can change the context or state, right? Of what tokens you're looking for. Because when you're in a string, you may be looking for the dollar to input a variable name and things like that to concatenate a string, for example. The next bit is a very simple string literals. We've probably seen these things before, like a function or die or exit. And then what happens inside the curly braces is what happens when this token is matched. So when the Alexa encounters these tokens, this thing will happen. In all of these cases, they just return the tokens directly. T exit is instantly exactly the same in exit and die, it doesn't matter. It returns the same token, so it has the same meaning. And function returns the function token. So then it puts these out into this thing called the output stream of the Alexa, the token stream, right? So, as I mentioned, it's a state machine, so the state allows you to match different tokens depending on where you are and so on. So this is an example, bit by bit, let's go through it. This first one will match, if we're in double quotes, back quote, or we probably know it as back ticks perhaps, or here doc. And we're looking for the string dollar curly brace, so that we're inside a string basically, right? And when we encounter that, we will do this thing called a yy push state, right? That's basically changed the state to this, which is looking for variable name, right? So now we're looking for a variable name, so we're changing the state again. And we return the token that we've matched to the token stream. So now we're in this state looking for variable name, we're looking for a variable, a label basically, and followed by a curly brace. And there's lots of sort of square brackets and curly brackets and so on. If you get them wrong, you'll probably break. So, you know, don't touch that. And then we do this thing called copying a semantic value. Basically that means that's the name of the variable, right? But that's useful information we want to know when we're looking at that token. We want to know what the name of the variable is that we matched. It's kind of important for the engine to know, right? Pop state, we kind of go back into the last state we're in, and then we push state, so we go back into scripting. The pop state seems kind of perhaps a bit redundant, but I don't know, maybe there's a reason for that, I don't know. And then of course we return the token for the token stream. Yay, we've lexed stuff, all right? So now all we have is we've broken up our long string of PHP code into lots of little tokens, perhaps with some meaningful information like the variable names and so on. So, given that syntax definition, we pass this into re2c, this program, and it generates a C file. It's not all that readable. There's bits of it that are readable, but then there's huge chunks of numbers and letters that are really meaningless. But you can go ahead, you can check out the PHP source code and you can run re2c on this with a load of flags which are minus, minus, no generation date, minus, minus, case inverted, minus, C, B, D, F, minus, O, A, dot, C, zen, language, scanner, dot, L, and so on. Remember that? You probably do, but you're probably the only person that remembers that in this room. And that is the lecture implementation, and that's what actually happens, right? So the next stage is the parser. The parser kind of works in a similar way, it's a state machine as well, fine. And we have another definition, zen, language, parser, dot, Y, another meaningless file extension. This contains the parser definition, and this gets a little bit more complicated. When we're lexing stuff, all we're doing is breaking up a string into lots of little tokens, right? As I said, a parser actually tries to make sense of these tokens in order.  But they're actually ordered, so that they mean something to you, and you understand what I'm talking about, hopefully. If I'm getting the words in the right order, that is. If I start talking random nonsense, I'm still using real words, but in the order they are, it doesn't make sense, and you won't be able to understand. So, actually, when you're writing a programming language with a lexer and parser, it works in quite a similar way to, you know, you could deconstruct a spoken language or written language, if you like. So, the parser tries to make sense of these words, if you like, in order, and says, right, that works, that's good. So, we're trying to understand the main parts of what's going on here. Right. First of all, these are just labels. We have two definitions. If statement, if statement without else. Now, throughout this, you'll encounter two other definitions, which are quite large. Expr, which is expression, and statement. And these are really big definitions, so I can't fit them on a slide, so I've omitted them, but, you know, we know what an expression is in a statement, so we can kind of put that in mentally. So, we'll look at the if statement first. Basically, this says if statement can be an if statement without else on its own. This thing is like precedence. We don't have to worry too much about that. It's kind of important, but we'll skip over it. It's fine. Or it can be an if statement without else followed by an else followed by a statement. OK. But we also need to know what an if statement without else is, so we can fill in those blanks. And that is the if token followed by the literal open parenthesis, followed by an expression. An expression is something that returns something, followed by a closed bracket, followed by a statement. And a statement doesn't necessarily return something. The definition for expression statement is huge, OK? So, we'll ignore it. But you can look at this file in PHP code and see, wow, that's big, if you like. Or it can be an if statement without else can also be an if statement without else, followed by else if, followed by an open parenthesis, an expression, closed parenthesis, and a statement. So, the statement, just for completeness, so you can hopefully visualise this a bit better, includes curly braces around the side. So, obviously you write if brackets, an expression that returns something boolean, or truthy, or falsy, maybe. And then sometimes you have curly, it's optional, right, if you want to do one line. Most people, I think, use curly braces consistently for their ifs and else's and so on. But that's included in the statement, so we don't actually see that in this definition. So, let's have a look at some code. We know some PHP code, right? Who doesn't know PHP code? Okay. Cool. You're at the right place, then. All right, so we'll try and use those rules. So, the first one matches the first one to a few lines of code. If statement without else, and it's got an if token, open brackets, expression statement. As I said, the statement includes the curly braces. And then it's got else if, so that's why we match that. So, the next part is matched by exactly the same rule. It matches the alternative grammar, if you like, that was defined. So, it matches the if statement without else and an else if as well, and a little open parenthesis, expression, closed parenthesis statement. Okay. And finally, the last one, if statement, matches because it's an if statement without else, followed by an else token, followed by a statement. Okay. With me so far? Some nods, good. All right. Cool. So, if we have a look at PHP 7.0, whatever, it doesn't matter, it's irrelevant. We can see it's doing some stuff, right? It has curly brace parts. So, that's, again, what happens when we match the grammar that's been defined. But there's something important that I've highlighted in big red boxes here. Right? In PHP 7, the parser outputs the abstract syntax tree. If we go look at PHP 5, the grammar is actually slightly different, so I've kind of matched it the best I can. But instead of doing this AST stuff, we're doing this zend do if-cond, which is basically an if statement, right? And the grammar is different. And you can see we're actually generating op codes here directly. You know, we're doing op code is zend jump zidden, things like that, right? You know, I have to worry too much about what they are, but fine. So, the AST is new, right? So, going back to the first diagram, it's this bit here, sort of in between these two steps is where the AST exists, if you like. So, the result of the parser in PHP 7 is the AST. The AST is then fed into the compiler, which converts it to op codes, and the op codes are executed, and magic happens. Anyone lost? It's okay to put your hand up. It's fine. Okay, so I'm going to try and simplify this, okay? First of all, what is an AST? Because I haven't really explained what it is, just that it is. An AST is just a data structure. It's a representation of your code, and that's pretty much it. Right? It uses a tree structure, hence the name tree, funnily enough. And it's not necessarily specific to PHP, which is kind of interesting. It's a data structure that says, well, this is how your code is laid out, and so on. It can be modified in theory. And obviously, if you modify the behaviour of that, it would... Sorry, if you modify the tree, it would modify the behaviour of the code, because basically you're changing the code programmatically, if you like. It can also contain some metadata as well, things like what line number, what file it is, and things like that. And this data structure that represents your file of code, or whatever, can also be unparsed. That is to say you regenerate a program from that, your source code. The layout may change because we may ignore certain elements of the layout, like whether you've got a space and so on. It may or may not be relevant to whatever programming languages there are. I say that because an AST is a representation used in many other programming languages as well, not just PHP. So let's have a look at what it might look like. So we know what this does, hopefully. If we represent this as a tree, brilliantly drawn ASCII tree, we have an echo statement, and we have a child value of that of a string, which is a scalar value, and the value is Hello World. And that's it. That's what it might look like. So then just to demonstrate it getting a bit more tree-like, let's do something slightly different. This does roughly the same thing, I think. There's a bit more going on here, though, if we turn this into an abstract syntax tree. We have an echo statement. We have a concatenation operator as the child instead of the string directly. The concatenation is what's called a binary operator. It takes a left and a right argument, if you like. I think of it maybe as a function, perhaps. So the left value is the scalar string Hello, and the right operand is the scalar string World. Okay. So let's do a bit of maths on this. Don't worry, it's not difficult maths, hopefully. We're going to assign some variables and then do this sum A plus brackets B times 2. Fine. This is what the AST for this looks like, and you can already see it's getting quite big and complicated, but it's okay. At the top, if you can just about see it, we have the assign statement variable A with the integer value of 1. We have B with an integer value of 3. Sorry, value of 5 and value of 3. I can't read it's really tiny on there, so it's probably really tiny at the back as well. But then we have the echo statement. That's the next thing to happen. And then we have the add operation. Again, that's a binary operation. It has two things to it. At the left side, we have the variable A. The right side, we have another binary operation. To multiply, because that takes, again, two things. You multiply two things together. The left is the variable B, and the right is just an integer with a value of 2. All right? Okay. So we can represent stuff as trees. But why? Well, there was quite an important, it was quite an important introduction to the PHP engine. Lots of other languages already do this. So maybe there's a bit of, well, PHP can be a grown up language and we can have one too. But it also increases the maintainability and co-quality inside PHP itself. And it decouples the compiler from the parser. So we have this sort of intermediate thing. And that also simplified some of the productions from the parser as well, which is nice. So the grammar actually got simpler. At the cost of some really weird edge cases that we don't really care about. And if you've already migrated to PHP 7 and you encountered some of these weird things, then you shouldn't be doing weird things in the first place perhaps. I don't know. Yes. And it's faster, asterisk. All right? I have to quantify this. Because there is a particular part of that process that is faster. So using the AST means that we can be faster in the compilation step, right? Despite this extra step, it kind of offsets it. But the runtime difference is kind of negligible. Most of the benefits that we see in PHP 7 are actually from other optimizations, like rewriting how Z-Vals work and referencing and things like that. Not this part of it. So the runtime performance is not really changed much from this particular change. But in the compilation step, that actually means that it's about 10% to 15% faster, which is kind of nice. But it does require more memory because there's obviously this big old data structure. That makes sense. But once it's compiled into opcodes anyway, it doesn't matter because you've already compiled the opcodes then and they're in the opcash and they're in the opcoder. But the reason why it's more efficient is because this tree structure is very friendly for compilers. Computers understand it nicely and you can go around this tree and figure things out and I'll demonstrate that shortly. So it's very efficient. In theory, you could also do static collapsing of nodes and things like that. If we look at this code, we already know what the answer is because the value will always be the same. Exactly, you could just change that into an echo the value, right? And then that AST becomes nothing. But we won't, we'll leave it as a big AST, right? So we can draw this a different way, like a tree, but upside down. So the exact same information is here on this slide. But when we show this as a tree and draw it out like this nice tree, we can do something. We can follow a line around the graph. Execute each node that we touch down in order. And if we start at the top and go all the way around and run all of these, if you like, this is something called a pre-order traversal. And if you write them down in the order that they happen, you'll get something that looks like this. And in sort of pseudo code terms, that looks the same as the code we've written, right? The PHP code, roughly. So the important thing is the operation or the statement is prefixed, right? So the assign comes before the variable and the scalar value. And it's called Polish notation when we write it down like this. And it allows us to very easily see the order of precedence. We know that we have to multiply something first before we can add the value. So we have to go all the way down, multiply B by 2 and then we can add A to the result of the multiply operation. When writing a programming language, I've mentioned this thing called order of precedence. When writing a programming language, order of precedence is really important because it defines how things behave when the order of operations is potentially ambiguous. Demonstrated by this simple maths sum, if you do it two different ways, you get different results. So order of precedence is very important in the same way in programming languages. Is it seven? Do we do the multiplication first? Or is it nine where we add first and then multiply the result? We know in mathematics rule that we multiply first, right? But you can change that potentially in a compiler and make it do something different, which would be unexpected perhaps. So when we write this out and we do the multiplication, then we can see the order of things that have to happen. But it's actually kind of backwards because you have to go all the way down, take the three and the two and multiply them together and so on. So reading left to right, we have to say, well, okay, we want to add something. We got the first thing, which is a one, but then we got another operator, which is the multiply. So we have to go and do something else first. Right? So the operator is multiply. We have a left and a right and they are something that we can do something with immediately. That's great. So we know that the values are two and three. And so we return six from the multiply and then we have the value six as the add. And then we know to add one and six and the answer is actually seven. So we can turn it around. Maybe that's a bit easy to understand. We have this thing called, funnily enough, reverse Polish notation. It's kind of similar, but maybe not as obvious as what's going on here. It does exactly the same thing. It's just a different way of writing it out. To pass this, we build a stack. So we can do this thing called a stack interpreter, if you like. So we've got a stack and we're going to step through each item one by one. If it's not operational, it's an operator then we're going to execute on whatever's in the stack. Otherwise, we're going to add it onto the stack. So, one by one. This is a number. It's not an operation, so we'll add it to the stack. The second one's also a number, so we'll add it to the stack. It's a number, we'll add it to the stack. Fourth one is an operator. So we have to do something now. We know that the multiply operator takes two operands. So we have to take two things off the stack, two and the three. And then we put the result back onto the stack. So now we have six in the stack, at the top of the stack. So the next one is the add operator. We know we need two things for an add because we add two things together. So we take the two things, one and the six off and then we put the result back on, which is indeed seven. And then we've reached the end of the input. The final result of that particular operation is the single item left in the stack. We know it's seven, right? If you have more than one thing left on the stack or no items in the stack, something's broken, okay? All right. So now we have armed ourselves with some interesting and dangerous knowledge. We can now write a compiler. I'm going to constrain it for the sake of keeping it within this talk. And we're going to use an AST in it as well, of course. So we can do this in three easy steps. Don't use this in production, though, because it's terrible. If you like GitHub things, you can have a look at the source code on github.com. Basic maths compiler. And all the code that you'll see on this slide is there in its entirety, but not slightly redacted to fit on tiny little slides on this huge screen. So first of all, when we want to write a programming language, you have to define what's in it. Our language is just going to be basic sums, okay? Just maths. Hence the name basic maths compiler. All right. So we're only going to use positive integers. So nothing negative. That simplifies things somewhat. We're going to allow white space. But we're going to ignore it. And we're going to have four operators. There's only four things you can do. Add some trapped multiplied void. And we're only going to support one line of input. And another thing to simplify this even further is that we're not going to allow any way to override the order of precedence. So no brackets or anything like that to say or execute this bit first. Ignore that, because that gets a bit complicated. So first up, we write the lexa. A very simple lexa can be written just with regular expressions. Who loves regular expressions? Who hates them? It's the other hands, right? So whether you love them or hate them, regular expressions can be used here. So we're going to define them and notice that all of them, if you don't know regular expressions in tax very well, the circumflex at the start means you always match the start of the string, okay? And then we've got the plus or minus. Multiply, divide, some of them have to be escaped with a backslash to make sure that they pass properly and so on. Backslash D plus is a number. Any digit, if you like. Backslash S is any white space. So any amount of white space, fine. But by using that circumflex there, we ensure that we're always matching the next token, not something further on down in our string. Because we want to do this in order, right? We don't want to say, oh, there's a number over there. Because, oh, the other way around. There's a number over there, yeah? Because that's going to screw up our lexa. So we always want to match the start of the string and then we move along the string bit by bit. All right? So we're going to step through the string, like I said, bit by bit. And what this bit of code here does, just to explain it, we analyse from the offset onwards each time and we try to do this in order. We move the offset onwards each time. And we try all of those regular expressions each time. We move the offset on if we match something. I've used this fancy word, lexime, basically that's the thing that got matched. That's a fancy word for that. Okay. And the match is just, we literally loop through the regular expressions and see if any of them match. That's it. If they do, great. That's all over the place. Let's make another object. All right. So that's it, that's a lexa done. That was it. So now we need to parse the tokens. Okay? Before we can do this though, we need to know the order of precedence. As I explained, it's something very important for programme language. We're going to use standard operator precedence here. It's kind of in inverse order. Basically the highest value is the most important precedence, if you like. So multiply, then divide, then add, then subtract. So the list of tokens we get from our parser, or the array of tokens, or stack of tokens, is in the correct vernacular. We're going to loop over that. Okay? And we're going to create two other stacks as we go through this. We're going to have our token stack, which is the output stack. So we've made sense of this. And a temporary operator stack, which is going to be, we're going to chuck stuff in, probably operators, the name may suggest, and then take them out and so on. If the token that we find is an operator, that is, it's add, subtract, multiply, divide, then we're going to do a load of other code. So this is inside that if block. Basically, if it's an operator, we're going to put it on the operator stack and put it on the operator stack and move on. And going backwards a bit, if we find something in the operator stack that has a higher precedence of the operator that we're looking at, then we're then going to pop it out of the operator stack and put it onto the output stack. All right? And then at the end, we clean up any leftover operators in the operator stack and put them onto the output stack. So then everything ends up on this output stack. All right? So all we're doing here is just reordering, shuffling the tokens around into something that is more meaningful to our compiler. So let's try and visualize this with an amazingly drawn load of boxes. So we're going to go through one by one. Okay, this one is a value, so we're going to put it onto the output stack. Oh, this one's an operator, so push it onto the operator stack. Okay? There's nothing of a higher precedence there, so that's fine, we can just add it on. And then we add two to the output stack. That's very simple. The multiply operator comes next. Oh, it's an operator. We check the stack. If the last thing has a higher precedence, which it doesn't, then we would have popped it off, but it doesn't. Okay? So we just add the multiply onto the operator stack. Finally, the last one is just a value and then we need to do our cleanup. We need to take all the operators and put them onto the output stack. This is familiar. This is the reverse Polish notation we looked at. So what we've done is we've taken this big stream of tokens, or potentially big stream of tokens, and we've shuffled them all around into this notation that we can use in our compiler. So now we need to create the AST. But because we have this stack of tokens in the right order, we can actually take those tokens and very simply make them into a tree. So we progress through the stack again. So we do another loop. IP is the instruction pointer, which is useful if you start getting a bit more complicated and going back through the stack and then forward through the stack and so on, which we don't have to in this compiler. It's fine. We can ignore that, but it gets a bit more complicated perhaps. So it defines where we are in the stack. So then we just create the AST, right? If it's a value, we just say, it's a value, and we give it the lexeme. We pass the lexeme to it and cast it to an integer because it's a number, right? The lexeme is the bits that's matched, so that's going to be the numbers, right? If it's an operator, we need to figure out what kind of operator it is. There's a bit of code that I've omitted there, but we figure out what it is, store it in dollar node type, and then we create this AST node. So we're representing our AST three of PHP objects here. And because these are all binary operators, they both need the left and the right, okay? So we pass those. So we take them off the stack using that stack compiler thing, right? And we make the AST node there. So there we have it. It would look something like this, right? We have our ad, we have the integer value one perhaps, and then a multiply, and we have the two integer values, right? So then we need to go through this. We have this parsed now, so we need to execute it. And again, this is quite an easy part. We're going to create this tiny virtual machine. It's kind of inception there because PHP is running in a virtual machine and we're creating a virtual machine in the virtual machine.  Anyway, lulls. We descend through the abstract syntax tree and execute things as we come to them. That's basically it. But we can't execute it until we go all the way down the tree and figure out what we're trying to execute, right? So we have this recursive calling of this compile node function. So this is like our entry point for our compiler. So at the top, if we know it's a binary operator, so all of the binary operators in this particular source code extend from this abstract binary operator, to the interface that would work as well. And then we call another function called compile binary op. We'll come to that in a moment. If it's a scalar value, i.e., our integer, then we're just going to return the value directly. That's it. That's all we need to do there. And we don't have any other node types. We're ignoring white space. So that's it. So the compile binary op. Let's have a look. This is where kind of the meat of it exists. Now, we don't know whether left and right are values that we can use straight away. So actually what we have to do is pass left and right into the compile node function. So that's where the recursion comes from. Once we've done that, eventually, there might be another add or multiply, whichever, it was multiply, wasn't it? So one of the sides is going to be multiply. So then, actually, it would go back into compile binary op and then call compile node on the left and right, and that time we'd get integers. So left and right, eventually, hopefully, we'll turn into integers. And then we figure out the type of the node, so whether it's multiply, sorry, add, subtract, multiply, divide. We've got to switch here as you can see, and we just run it. We just do add, subtract, multiply, divide. And that's it. All right, so what does this mean for me? On the surface, this doesn't seem very relevant to our day-to-day jobs, perhaps, unless you're Derek. But what it does mean is that we get a nice bonus, along with the other optimisations in PHP 7 and so on, that we have faster and more efficient code. AST is one of those reasons, faster asterisk, yeah? But it does mean that we have some nice scope for optimisations in the future as well. And I believe some of those are sort of being discussed or some of them being implemented as well, which is nice, because we can reason about how the code goes together a bit nicer. So we've got this separation from the compiler and the parser, so it's kind of fun. Knowing how the engine works can help somewhat. I would suggest, though, that just because you know how the engine works, don't necessarily write micro silly optimisations that say, well, I know this is going to generate a more efficient data structure in the AST or whatever. No, PHP is actually a brilliant language for people to write terrible code. And PHP just deals with it, right? And that's evidenced as well by the vast improvements in PHP 7. Maybe Vim talked about those earlier. I didn't see his talk, but something I mentioned earlier as well, the AST isn't actually specific to PHP, but for most programming languages, apart from the weird ones that we'll ignore, most programming languages work in exactly the same way I've just described. We let stuff, parse it, compile it. And that's pretty much how you make a programming language, except some of them, right? We'll ignore those, though. So this can actually help you understand how your code is put together and helps you understand, actually, that syntax is just that. Essentially, all programming languages do roughly the same thing in a very slightly different way with some weird quirks. Fine. So can we use this? Well, no, unfortunately not at the moment. The AST is not directly available for you to say, oh, what does the AST look like for my code? But there are ways we can do this. Why would we want to do this? Well, it gets us big insights to our code. What's going on? We can examine the structure of the code that's going on, and we can do some magic things as well. I like magic things. There is this extension from Nikita Popov called PHP AST. And that exposes the AST into userland. So you could then say, well, have a look at this source code and give me the AST for it.  The downside to this, depending on your opinions on this, is it's an extension. So you have to then go and install an extension. If you're on perhaps a shared host, that might be a bit more difficult. Maybe you probably don't want to do that in production anyway. But this is like how we'd use that. So we install the extension, whether it's by Peckle or compiling it by hand, like a nutter. You give it some code. In this case, I'm just giving it a string of code. You use the AST backslash pass code function. And then we've got this AST dump, which is basically just a helper to make it a bit more readable. Because as you saw, even with that simple math sum, the AST got pretty big and maybe even impossible to read at the back. So PHP AST is what we can use to expose PHP's very own internal abstract syntax tree to you. There is also another extension, which I advise you don't use, because it's madness. But it's called ASTKit. Does anyone use RunKit? Does anyone use RunKit in production? Okay, cool, good. RunKit, if you don't know what it is, it allows you to like unknow classes and do things you shouldn't probably be doing and things like that. So ASTKit is written by Sarah Goldman. And it allows you to modify the AST and then execute it. So in effect what you get is this concept you may have heard of called monkey patching, which is where you take some code, change it before you run it, right? Which is quite cool. The downsides are, it's an extension and this is probably not something you want to be doing in production. And it was written as just a bit of an experiment, right? So maybe don't use it in production. So some usage of this extension. Fairly straightforward. We give it some code and it exposes these extra methods like getchild, getchild, graft and stuff. Basically what that means is changing the true in the if into false. Because it's a tree, you're getting the children of the tree and things like that. You're changing things over and so on. And then you can execute it. So the first time you execute it, it will say this is a triumph and then the second time you execute it once it's been changed it will say the cake is a lie. So these examples are just taken from the read me's. I didn't write this. But it demonstrates what these extensions are used for. But that's not all. There is this thing called PHP parser. It's written by Nikita Popov who is the author of the PHP AST extension and does a lot of work on PHP core. So he knows how it works, which is a good start. And it's more or less the same as the PHP AST extension but it's written in PHP. So you can install it with composer. You can say just composer require Nicky C PHP parser. So the upsides are it's not an extension. It's very easy for anyone to use. The downside is, and there's a really big downside to it, it's really, really, really slow because it's written in PHP. So this is how you use it anyway. There are use cases for it. I'm just getting there. Don't disregard this straight away because it's slow. So this is how you use it very much in the same way that if you have an extension, you give it some code. In this case I'm just doing some file get contents on whatever and calling pars and you'll get this big old AST depending on how much code you have, of course. All right. So it's very simple to get the AST and then we can do stuff with it, right? So we have this library that I'm going to shamelessly plug now. I don't care. It's called Better Reflection. For short, it's the reflection API that you may or may not be familiar with in PHP but it uses the AST instead. It's pretty flexible, it's pretty powerful and it allows you to do monkey patching. So this is roughly how it works. I'm not going to go into too much detail because this isn't at all about Better Reflection. I want to make it relevant, though. We have this reflector which is like the public API. That's how you do reflecting and the source locator is basically instructions for Better Reflection to find your code. The reason why we do this is because we can now reflect on code that doesn't exist to PHP yet.  That's the point. So this uses PHP parser, that's like the main part of it if you like and you've got all the methods most of the methods that you're used to when you're using normal reflection but a few extra ones like get AST and get body AST and things like that. So you can start looking at the content of your methods and your classes and functions and things like that. The API is roughly similar instead of saying new reflection class we have this new Better Reflection we get a class reflector and stuff like that. But we're returning this reflection, right? So we're using some same defaults, we're using whatever auto loader is registered in your SPL auto load add thing, which is usually going to be composer, right? So anything that can compose, composer can load, we can load too but we don't actually have to load it to look at it. We just grab the source code, feed it into PHP parser and then we have the reflections so this is that source locator and class reflector stuff. The defaults are that we can reflect on PHP's internal source because there's a load of stuff there and that's an awful mess so we'll ignore that. Evald code if you're evil enough to be using eval and then your auto load one which does some magic under the hood which is kind of fun actually it overwrites your file streamwrapper and then it will say did your class exist so it will trigger your auto loader to say oh open this file but instead we've overwritten the file streamwrapper and then we stop it from actually being loaded we just grab the file name and then we restore the file streamwrapper and then we have the file name so then we can open it with PHP parser so that class never actually has to be loaded for us to look at it we just grab the source code of it directly and it works in 99% of cases if you're loading your source code from something like a database which is really weird but it wouldn't work or if you're loading it from a memory stream or something like that which is also a bit weird most people load them from files that's where we store source code so it works for most of the time so given a class structure like this fairly straightforward we get the AST that looks like this so we get all of the nodes we get all the structure of the code and I've simplified it down because that would be huge so we get the class node with an array of statements so the statements are the body of the class and we have the property node and the property node has types and attributes and things like that we have the method node has a type, some parameters statements within the method actually we didn't have any statements within the method so that would just be an empty array any relevant attributes like start line, end line, things like that so what can I use better reflection for so we have this AST, great so we can do some monkey patching as I kind of explained you've got a class, for example my class and it returns 5, very simple so we can use better reflection to reflect on that because it doesn't necessarily load your code into memory so we can grab the AST of that because hopefully as you know certainly if you use Runkit you know that once you have loaded a class in PHP you can't change it that's one of the benefits of Runkit so we can do this instead we can say grabbing the source code finding the AST of it make sure you do it before the class is loaded of course then we use this class loader and we're going to cache it in a file so we don't have to keep doing this over and over again do this after all the other autoloaders because this class loader actually registers his own autoloader to go in the way of composer if you like and say well if you try and instantiate the class that you're looking for and I know about this and I've changed it then I will make my own evil monkey patched version instead so then we can use the reflection we can say get method foo which is familiar probably if you use reflection to get a method of over reflection but we also have this new function that doesn't exist in core reflection called set body from closure and we can pass it a closure in this case a function that returns for you can also set the body from a string if you don't like writing functions or you can pass it a load of AST nodes that are in the format of Nikita's PHP parser AST nodes and it does have like this whole way of building AST nodes which is kind of nice but basically what we're doing is we're making that method return foo instead of 5 it's a kind of fairly straightforward change so the autoloader that we registered that class loader will kick in and say oh you're trying to instantiate my class and it will allow us to load the modified version of that code so now it will return foo not 5 hahaha so for the PHP engine AST is a nice efficient data structure that we can use to represent code it means that compilation step is faster obviously when you factor in the OPCash it doesn't make any difference in runtime really maybe like the first time you run that but it provides that nice separation But it provides that nice separation from the Pazza and the Compiler. But what's more useful to us normal developers who don't delve into PHP's core too much... Not that you're not normal, Derek. these concepts can be used in userLand and they are very useful. So we've got the PHP Pazza library, which means we can do this straight away and do it slowly of course. We have better reflection which is based on PHP Pazza. Ond os ydych chi fod ar y cwmwysgwch o amlwg nifer i los i'r cyn o'r llwyddiad ein gweithigau ar gyfer ei achyfodd a'r llwyddiad sefydliad o'n amlwg, ond diddorol o hollwch yn ein hyn大家都 iddi'r pleidwyr stathog yr analysus. Mae'r analysus yn y rhan o'r tawch am ymdweud, oherwydd gechwyn fyddi, swipe upon it, about a tool called Exocat, which uses the AST as well to do static analysis. If you're not sure what static analysis is, it's basically looking at your code and seeing where it's going wrong, not debugging, that's a different thing. It's kind of looking at things like types and saying, well, does this function accept the right types that it's using and things like that? Are you passing the right types to a function? Obviously, if you're using strict type declarations, that will now throw lots of errors, but certainly in PHP 5 code and before, this kind of thing is going to be immensely useful. So maybe we can use it to look at the dock blocks and say, well, you're using this function and passing it an integer, but the dock blocks say a string. So what's going on? It's wrong, right? And just who uses PHP Storm? Okay, many of you. It does static analysis as you're writing code. So when it says the little squiggly underlines and it will say, oh, this doesn't look right, that's what it's doing, it's looking at your code, it's not running it, it's statically analysing it, right? There's also another tool called FAN, P-H-A-N, not F-A-N, which uses the PHP AST extension and that does a load of static analysis as well. It was originally written by Rasmus and then some other people have taken it over and now maintaining it, and it's a very useful tool. And these kind of tools, you can stick into your CI environment and then make sure nothing breaks, or nothing obvious breaks perhaps is a better way of putting it. So it allows you to catch your bugs faster. So actually, it's cool and it's very useful.


Ranger Bill, warrior of the woodland, struggling against extreme odds, traveling dangerous trails, showing rare courage in the face of disaster, in the air, on horseback, or in a screaming squad car. His mind alert, a ready smile, unswerving, loyal to his mission. In all this, an exchange for the satisfaction and pride of a job well done. Uh-oh, here comes that boy again. Alice, if he's here looking for me, and I'm sure he is, get rid of him, will you? I'll do what I can, Mr. Bronx. Hi. Is Mr. Bronx around, please? Oh, I'm afraid he's busy right now. May I take a message? Oh, he knows why I'm here. Will he be busy long? Well, that's hard to tell. He's a very busy man, you know. Oh, I sure guess so. Being the editor of a big newspaper like the naughty pine sun, sure must keep him busy almost all the time. Boy, imagine being the editor of a big newspaper like this one. Are you interested in the newspaper field? I sure am. That's why I keep coming here. I figure sooner or later, Mr. Bronkel, give me a chance to work for the paper. Well, aren't you a little young to be thinking about this?  Yeah, but I don't expect to be put on as a cub reporter. Besides, mom and me really need the money. Oh? Well, I don't want you to feel sorry for me or anything, but ever since my dad died last year, mom and I have been having it pretty rough. The journalism teacher at school, well, he said he thought I had real ability in this kind of work, and I thought, well, I might just as well try to get started here. Maybe after I get out of school, I could work here full-time. You have it all figured out, don't you? Well, not all of it. I don't know how much schooling I'd need before I could be a good newspaper man. Well, I'd say more than you have and experience, too. Well, that's the whole trouble.  It sure gets a guy down after a while. Oh, I know. But there is one other way to get in. What's that? It seems to me that any editor would be impressed with a young fellow who could dig up a good story on his own. Huh? What do you mean? Well, just this. If you could go out and on your own, dig up a good story for the newspaper, and then come back here and sell it to us, I think Mr. Bronx might change his mind about hiring you. Oh, do you really think so? Well, I do all I could to help you. Well, that is if your story was good enough. Huh?  Well, what are you saying? Well, if you think you could get me a job here, I'll do it. Boy, I sure thank you for the encouragement. No, that's all right. Now, what did you say? Freddie. Freddie Burns. And I'm Alice Flag. Well, I sure thank you, Ms. Flag. Oh, that's all right, Freddie. Now let's see what you can do as a reporter. Well, there's old Ben across the street. I haven't seen him in town for a long time. Me neither, young feller. Poor feller. Talk about never giving up. I know what you mean, Stumpy. How many years has old Ben been panning for gold on on Rocky Creek? As long as I can remember. And there are some that say that was pretty long. And what's the hope to get from it? That's a hard question to answer. Been panning for many years and never found even one nugget. And sometimes put to shame by his persistence. What do you mean, Bill? Well, there's a man who spends every ounce of energy and every minute of time working for a dream. And as a matter of fact, a selfish kind of dream. Here I am supposed to be doing all to the glory of God, heart, soul, and mind. I don't seem to spend half the time or energy that old Ben does looking for his gold. See what you mean? It's a good lesson, all right? Hi, Ranger Bill, Stumpy. Hello, Freddie. Hi there, Whippersnapper. What you doing with that there, pad and pencil? I'm a reporter. Is that so? Sure. Well, almost one.  That sounds pretty good, Freddie. Is editor Browne interested? Well, it's not him, really. His secretary, Miss Flag, said she'd help me if I could get one good story. So now you're running around looking for something to report, huh? That's right. Got any ideas? Well, you might run a contest to see who could guess how old Stumpy is. Yeah, what's so funny about that? A man as old as he feels, which makes me about 24. Well, seriously, Freddie, do you have any ideas? Not one. I almost ran out of the office and bought this pad and pencil and paper at the first drug store I came to. But then, all of a sudden, I couldn't think of a thing. It all seemed so simple at first, but what can I write about? Don't ask us, young fella. That's why we're rangers and not newspaper writers. Hey, what about a story on a day in the life of the rangers? I appreciate your offer, Freddie, but around here, everyone pretty well knows what we do. I doubt whether there'd be much interest in it. Yeah, I guess so. Even I know all the things you guys do. The excitement with the rangers isn't doing what you do rather than just hearing about it. Oh, if I can only find one good idea. Well, let's think about it, sonny. Where does a man look for a story that no one else thinks of? If I knew the answer to that, I'd be home typing it up right now. Hey, that reminds me. What does your mother think of all this, Freddie? Well, she doesn't know anything about it yet. She doesn't think I ought to mess up my schoolwork, but I know I can do both. This ought to prove it to her and also help us out with the things we need. Sure, I know you won't let your schoolwork slip. I don't dare. One thing that might make a difference with my job is what kind of work I'm doing at school. That's right, Freddie. Boy, everything is working out for me, but I can't even think of one story or idea. What about him over there? Huh? Old man. You see that man coming out of the hardware store? Now there might be a story for you. Old man? Oh, everybody just laughs at him. Isn't he the man who's been panning for gold up on Rocky Creek for a long time? That's right. Why do you think he keeps on panning? I mean, he's never found any gold, has he? Not a nugget.  Oh, he probably is just a nut. You know, some people are about things. He don't seem off-balance to me. He's set about this panning for gold business. I think Bill's got a good idea. Why don't you find out about him? Well, why not? I don't have any other ideas. What do you think I ought to do? Just go over there and ask him why he keeps on panning? I wouldn't be quite that blunt, Freddie. Enough people have made fun of him that he's probably pretty sore on that spot. I'd suggest you get to know him a little first. Oh, I'll try. Boy, there sure is a lot to this newspaper report that you don't think of when you first want to do it. Howdy, old Ben. What brings you to town? Oh, just needed to pick up a few supplies. No gold yet, huh? I'll find it. Well, what can I do for you? I just want to see whether I can still make a better cup of coffee than you serve. Call it right up. Hello, Mr. Everybody just calls me old Ben, son. Well, my name is Freddie Burns. Happy to meet you. Sit down. Thanks. Well, huh, I've seen you watching me most of the morning following me everywhere I went. You saw me, huh? I thought you was awfully friendly just now. What's on your mind? Oh, well, nothing much. Well, you sure go away. You put trouble for nothing much. Come on, boy, out with it.  Oh, no, no, it isn't that, not at all. I was beginning to wonder if you had a voice left. I, well, you've been panning for gold for as long as I can remember, and... Judging by the looks of you, I've been panning longer than you or your folks can remember. So? Well, you don't hear of anybody panning for gold anymore. I mean, we read about it in history books and all, but... You're interested in panning? Well, I would like to see how it's done. I mean, I know how it's done, but, well, I'd like to see it. Coffee, Ben? That'll be ten cents. I know how much it costs. I've watched it rise from four cents a cup on up. Same coffee, though. The price still stands at ten cents. I'm looking for it. I've got it here somewhere. Here's the dime. Oh, thanks, boy. That's mighty kind of you. Seems like there's always somebody who's mighty kind around these points. Best coffee around.  I always lead him to think that I brew better coffee out by my camp. How far is your camp from town, Bill? Oh, about five miles a figure. Not more than that. Why? Well, I was thinking, if you don't mind, maybe after school and the afternoons I could come out and I'll see how you work. Mind? Why hadn't you had any company since the markers stopped and that was years ago? Markers? He, like me, spends a lot of time going after something he really believes in.  They used to drop fools' gold in the river in tricks like that. But old Ben knows what he's after and he's not about to be tricked either. If you'll draw me a map of how to get to your camp, I'll come out first thing next week. Pleasure. Real pleasure. Maybe you'll get interested enough to give me a hand. There's gold out there, boy. I know. I've been panning for a long time and haven't got to it yet. But I know it's there. Maybe one more of us out there that believes in it will change my luck. Hello, Freddie. Hi, Miss Flag. How are you? Fine, Miss Flag, fine. You still want to be a newspaper reporter? Well, there's a lot more to it than I thought. I knew you'd find that out soon enough. So the idea's over, huh? Oh, no, not at all. In fact, well, I'm on the trail of a pretty good story right now. It's gonna take some time, though. Well, I am surprised. But what I said still stands. If you dig up a good story, I'll see that it and you come to the very definite attention of editor Bronk. Well, I have to run along now. Bye, Freddie. So long, Miss Flag, and thanks. Not famous yet, Stumpy, if ever. How did you make out with old Ben? Well, I'm going out to his camp next week and see how he does things.  Well, I hope so. You know, I really like him. He doesn't seem crazy at all. Isn't that what we told you? And he really believes that there's gold out there in Rocky Creek. I mean, even after all these years of finding nothing. He'd better believe it. I'd hate to think he was out there just killing time the way he works. Why would a man do that, Bill? Why, after all these years, would he keep panning? There could be a lot of reasons, Freddie. It'd be impossible just to come up with one. It would fit old Ben. Besides, I thought that's why you were getting to know him. Just so you could find out why. For that there story, you weren't right. Yeah, only I thought maybe I could have an idea of what to look for or ask. Oh, well, I guess I'll have to keep playing it by ear. I guess you will, Freddie. And I, for one, will be very interested in reading the final result in the naughty pine sun. I'm coming to shore, boy. This shore is interesting. I could tell you were catching the spark, boy. I seen the look in your eye the last few days when you was out here. Well, it seems easy enough. Just sift in the sand and stuff that washes down through those boxes and screens. Nothing to it. Good clean work. The smell of the woods in your nostrils all the time. And it rains you and all of nature get wet. Like the good book says, the just and the unjust. You'll make this kind of life sound like fun, Ben. It is fun, Freddie. Is that why you keep doing it? What do you mean? Well, it isn't hard work and it is lots of fun, but you never find any gold in your boxes. Do you just keep it up because it's fun? I thought we'd come to this sooner or later. Well, you have to admit it, Ben. There isn't any gold. I don't have to admit no such thing. Boy, I'm going to show you something. I've never showed to nobody before. Once you see it, you'll understand why old Ben has spent his whole life right here looking for gold. What is it? Some were here in my pack. Just wait till you get a look. Here it is. Look at this. It's an old book, a real old book. It's an old diary. Here, look at the date, 1851. That's over 100 years ago, boy, even before I was born. I know, but what's that got to do with... Well, Ben will show you, boy. Just hold on. Now, lots of the pages have been ripped out or fallen out and some of it's pretty hard to read, but take a look at what it says right there. Uh-huh. The gold in little rocky stream from the Big River. Well, that's only half a sentence. Read a little more, boy. If we never return to claim it, may its discoverer be blessed by his great wealth. Great wealth. You hear that, boy? Great wealth right here in Rocky Creek. But over 100 years ago... You're thinking that this creek has been pan-drive gold, huh? Well, I checked before I started here years ago. There's no record of anyone ever even washing a dinner plate in this creek. But the person who wrote this diary knew about the gold? A man of God, boy. I've read every page that's left in this old diary. He was a preacher on his way west with a wagon train. Aimed to convert some of those old girls... gold-thirsty men in the rush of 49. He had no use for it, so he left it and went on. Oh, boy, what a story! So you see? All bends not as far off his head as folks think. I have it here in writing by a minister of the gospel that there's gold in Rocky Creek. But you've never found it? That don't mean it ain't here, does it? Gold ain't like animals.  He said it was here and I say it's here, too. Do you want to help me find it, boy? Well... Ben, what would you do if you finally found it? Anything I wanted to. I'd be rich. Yeah, but look how old you are. I don't know quite how to say this, but you haven't got a whole lot of time left to... Well, enjoy being rich even if you do find the gold. What are you trying to say to me, boy? Well, I don't see why you'd start looking for the gold when you were young and could enjoy it. I could understand that, but I still don't see why you keep looking for it when you... I don't know no such thing. That gold is mine. I found out it was here, didn't I? I spent my whole life trying to get at it, didn't I? Who better ought to have it than me? That minister, he let it go because he thought that there were more important things than being rich. Not for me, there ain't. All these years, people have been laughing at me. When I find that gold out by the whole town and kick them out. But, Ben, don't you see that? I'm going to see if there's anything in those boxes. If you want to stay, you're welcome. If you want to go, good riddance. Hey, just a minute. I'll help you out. Here, now grab my arm. Come on, come on, hold on. I guess you can't stand. I'll let the drag get us short. It's a good thing I was here. You might have drowned. Oh, never mind. Just get some help for me. I think my leg is busted. Hold your leg till we get you back to town, Ben. Looks like you had a bad fall. It's a good thing someone was here when it happened. I got a space cleared out in the back of the jeep. We can put Ben in there any time. Good. Here I'll carry you, Ben. I'll get there by my own steam. All you have to do is just help a little. Oh, Walrus, now you just settle down and let somebody do something for you. We've been out here alone too long. The only thing anybody does for old Ben is make trouble. Making tricks and cracking jokes.  Anybody that's nice to me either died long ago or wants some of my gold. We're all free alive. Bill, Freddie and me. And there ain't none of us won't even see that dream gold of yours. You can have every nugget you find. Although I sure can't see you in an old 49er like you would do with it. Even there was such a thing. That's my business. It sure is. Now let's get you back to the jeep. Here, I'll give you a hand. He doesn't know how fortunate he is that you were here, Freddie. He sure started acting funny. What do you mean? Well, I asked him the same thing that Stumpy did just now. What he would do with the gold if he did find it. And that's when he got all upset and finally slipped as he was waiting out into the stream. It's probably an idea that never occurred to him. At least not for a good many years. You know, you might have started shattering his whole dream with that question. He sure is a nice guy otherwise. Oh, I found out why he's searching Rocky Creek for the gold. Yeah, he has an old diary, over a hundred years old, that talks about gold in the creek. Well, I guess the man who wrote the diary, a minister on his way out west, just left the... Hey! Hey! What's the matter, Freddie? I got it. I figured it out. Bill, can you stay here and help me with an idea? I think I know where the gold that old Ben has been looking for is. Can't help thinking, Freddie, that you might take over where old Ben leaves off. Not a pine may never be without a character out here looking for gold. Only you've improved the method from panning to just digging. No, sir, Bill. If we don't find it right away, I'm not going to bother to... There it is. You better wait to make sure. I'm as sure as I can be, Bill. We found it. We found old Ben's gold. When I tried to put together the idea that the diary was probably true and that yet you hadn't found any gold, it came to me that in the river might mean under the river. That's when Bill and I dug it up. Uh-huh. That's right. The old chest must contain all the valuable effects, coins, and jewelry of a number of families. But I suppose the secret of where all the treasure came from must remain in history. I can hardly believe it. The gold. It really was there. That's right, Ben, and it's all yours. Mine? You dug it up, boy. Well, I never have figured out where to dig if you hadn't spent all those years figuring out where those old wagon-trained people had crossed the rocky. I've probably stood right on the treasure for hours at a time. And now it's found. And so what? Huh? Huh? Did I hear you right, Ben? That's right. I wish there never was any. But, well, Ben, I thought that you... When I first started out years ago in search of the gold, I was sure that I'd find it in no time at all. Stake my claim and live the rest of my life in ease. But as the years went on and I covered this stream from one end to the other, no gold, well, I got to be a town character. Old Ben chasing after gold that ain't there. I was determined to show him. I finally figured the exact place in the river that the river must have found the gold. But I didn't find any. These last years I couldn't give up. I was sure that there wasn't no gold, but I couldn't just walk into town after so many years and say that I quit. I thought I'd probably die out there. And then it didn't matter what folks thought. At least I wouldn't hear it. And now the gold has been found. And I don't know a thing to do with it, except pay up this hospital bill. Well, there's more than that in the chest, Ben. I know, I know. Stumpy, you and me, we must be about the same age. I may be a little older. Well, maybe. Why? Look at us. You've spent your life helping folks, doing something worthwhile. And me, I've been wading around in little streams. I got an idea. Your idea seemed to be paying off today, Freddie. Well, I know how you can make your whole life count, Ben. Well, why not give the money away? Help people with it. There's a lot of people who could use the kind of help you could give them. You know, it kind of makes sense to me why you should find that gold and not me. Huh? Sure. What I would have done with it was wasted on myself. Now my life is about done. And I never needed all those things I would have had. But you, you would give all that treasure away. You'd help folks with it. It's right that you should be the one to find it. Well, Freddie, I was beginning to think we'd seen the last of you around here. No, ma'am. I dug up that story you sent me on, and I really mean dug it up. Oh. And what a story.  Oh, where'd you get this story, Freddie? In a comic book? That's why he brought us along, Miss Flag. You've got a story, all right. And it's one that your paper would probably be most interested in. A true story? True as true can be, ma'am. Unless I miss my guess, Freddie here will soon be Freddie Burns from the Sun. I mean... Hey, I never thought of that. Freddie Burns from the Sun. I guess I don't need to tell you, boys and girls, that Freddie got the job. Maybe from today's adventure you can see what the Bible means when it talks about looking on the inside of a man. We can do a lot of things for a lot of reasons, but the only reasons that are worthwhile are the reasons that are pleasing to God. Well, see you next week for more adventure with... This program was produced in the studios of the Moody Bible Institute in Chicago.


Yes, yes, sir one moment, please for mr. Dick toadie of the Washington broadcast news all right Good morning dick haven't talked to you since our lunch at the White House That's right sir, and that was a great deal of good experience, and this will be to and I thank you very much for talking to us I'm pleased to do it this president You said you will launch a hard campaign to get Congress to pass your tax reform package when you and Congress return to Washington What will you do first? Well, we're working on the schedule of Appearances and so forth. I will be taking the this issue to the people I think they're the ones who have to show us exactly what they think and according to all the evidence We have so far the people are pretty much united that tax reform is exactly what we need I think they have been misinformed to a certain extent by some pressure groups that want one item or the other Taken out of the tax reform program, but we feel we have a Good reform there, and it'll be the first one literally that we've ever had in the income tax How do you plan to persuade Congress to accept both budget cuts and tax reforms particularly now that you're getting some negative reaction Not only from Democrats, but also from Republicans in both House and Senate Well, let me point out one thing Actually on tax reform there is no argument about whether we should have it or not in the Congress The approach is completely bipartisan The only areas of disagreement have to do with some features of the program whether it should do one thing or the other Now the same thing is true of the budget It is true that they have gotten together and before they went home They passed a a budget resolution in in the Congress. It's a non-binding resolution It is a compromise. I still think that the budget we originally submitted was the best for dealing with the deficit problem and reducing government spending But we now have this one and again if there is disagreement It would be over particular items where to cut for example and and how much I'm going to be watching it very carefully because each one of the features has to be augmented by legislation and appropriation bills and I'm prepared to veto at any time if they start to add in things that would increase the The deficit and I know that there are a number of spending bills that are still before the Congress President Harry Truman once kept Congress in session when the members wanted to go home Do you have any plans for keeping him in session perhaps through Christmas and New Year's in order to force tax reform with spending cuts? no and I think I'd have to tell you that if I did have any ideas of that kind I don't think I would mention them now, but no we haven't considered that We've just thought that we're going to do everything we can to aid the Congress in dealing with these and Getting the plate cleared this year Mr. President here in Washington the uproar over apartheid in South Africa is reaching something of a crescendo and There's talk of economic sanctions against South Africa if Congress passes such sanctions What will be your reaction veto or no veto?  I think in this particular case in South Africa. They would hurt the very people. We want to help They would have an effect on the economy that would result in more unemployment setbacks in the games that have been made by Labor and by the blacks in South Africa and so I Can tell you I'm I'm standing back and looking with a kind of jaundice diet at what may come to me But then the final decision as to whether to veto or not will depend on exactly what does get my desk What do you plan to do about foreign footwear imported into this country leave it alone or cut it back? Well, I've it. That's a decision that I have to give an answer to in the next several days I'll answer that in a broad brush stroke. Also, I Am opposed to protectionism protectionism is a two-way street and You may help some particular industry with protectionism or some group of employees And you find that you've done it at the expense of other industries other employees and I Recall very well in the great depression back in the early 30s When this country did turn to protectionism With the mistaken belief that it might help somehow in the depression it was then the smooth holy tariff bill and all it did was Expand the depression more worldwide than it was and make it worse and prolong it so I have to tell you basically I Don't think that protectionism is the way to go We're trying to talk to our trading allies about a meeting to get trade more open more fair between all countries open markets in all countries Mr. President when you meet with Soviet leader Gubeshoff are there proposals that you'll make to him to ease US Soviet tension? Well, I'm looking forward to the talks with him and I hope That it won't be just a session of trying to make some agreements on Particular specific issues, but that we can get right down to Discussing problems between us and an agenda for the future so that we can eliminate the hostilities and the suspicions if that's possible There's no question, but the Soviet Union has made it plain that They are embarked on an expansionist program They believe in the one-world communist state the world revolution, but at the same time you have to wonder if This is not based on their fear and Suspicion that the rest of us in the world mean them harm now I Think that we can present evidence to show that we have no such intention and If we could discuss things from the standpoint that we're the only two nations in the world I believe that could start World War three We're also the only two nations in the world that could bring about world peace and I would think that That would be our task in history to deal with that problem and I'm going to do my best to Present the evidence that would show and prove that this country has no Intention of taking hostile action against them and Also, however that we believe we have good reason to believe to think that they do have hostile intent Their expansionism worldwide their invasion of Afghanistan and so forth, but I wish we could get that out on the table and hopefully Reduce the suspicions between us Thank You, Mr. President I best do your wife talk to you again, sir. Thank you Bob Mohan from WSB radio Thanks, go ahead ladies gentlemen Good morning, Mr. President. This is Bob Mohan with WSB radio in Atlanta, Georgia. Yes. Good morning, Bob Good to talk to you so very much. Mr. President for this opportunity to talk with you this morning since time is at a premium I have a three-part question regarding South Africa, sir in view of the increased unrest in South Africa, Mr President, do you anticipate any change in our policies in South Africa? No, not really because I have to look at what has been accomplished so far We have by our relationship with South Africa, which is always over the years been a friendly one We have made it plain in spite of that that apartheid is very repugnant to us and that they should go down the path of reform and bringing about a more perfect democracy in their country and Our present relationship has we believe resulted in some very substantial changes the the very fact that the now the the blacks of ability at Being in labor unions or even having their own labor unions The fact they can buy property in the here-to-forth white areas that they can own businesses in some 40 White-dominated business districts They have eliminated the segregation that we once had in our own country the type of thing where host hotels and restaurants Places of entertainment and so forth were segregated that has all been eliminated They recognize now interracial marriages Well, we believe that for us to take an action now such as some are suggesting Turning our backs and walking away would leave us with no persuasive power whatsoever We think that if we continue We can help the present administration there, which is a reformist Administration as evidence for the things that I have have just mentioned Mr. President what is your reaction to Reverend jury Falwell statement that Bishop tutu is a phony? Who does not represent the interest of South African black? Well, I was very pleased to see his clarifying statement Yesterday I believe it was and what he had to say about that and his apology to Bishop tutu It seems from what I could read That his original statements were based on more not his own judgment, but on quotations From those people that he had met with in South Africa both blacks and whites, you know, we must recognize that the black Majority in South Africa is a combination of minorities. There are at least 10 tribal divisions there And so he heard that some considered Bishop tutu a leader others rejected him as a leader This was what he was trying to say, but I was very pleased when he Went public and said that his use of the word phony was really an unfortunate choice of words And he certainly had never meant in any way To describe the character of the beliefs of philosophy of Bishop Bishop tutu He was trying he used mistakenly the word to describe The thing that he had found that he was not recognized as Quote a black leader of all the blacks The president you fear a pro-communist government may take power in South Africa if the president's government fails This is a fear that many people who call my talk show express. How do you feel about that? I have to say that for us to believe the Soviet Union is not in its usual style stirring up the pot and Waiting in the wings for whatever advantage they can take we'd be very innocent naive if we if we believed If we didn't believe that that they're there ready to do that Okay, the next question. I have a regards tax reform. Mr. President several members of the Georgia Congressional Delegate delegation are saying the tax reform will be the first order of business when Congress reconvene After all the gnashing of teeth debate and compromise can the American people expect any reform in the tax system this year I Have to be optimistic and believe they can because we're going to push very far hard for it You see if we don't do it this year, then we've got a way to hold Other year another year before this can be implemented I think there are such advantages to the program the tax reform program that we've presented the simplification The fairness the advantage to the family. I was greatly encouraged when a committee of the house Dominated by the opposing party came forth the other day with a statement that this tax plan as we've presented Offers the most advantages to the American family of any of the tax proposals that have been made So we're going to try very hard. I know that the with the Congress it isn't so much An outright opposition as it is their concern that they've got too much on the plate To get to this in time This president I have one more question. I've been allowed You have been very kind to allow me to ask you some questions Since my listening audience comprises about 36 states I would like to afford you an opportunity to ask them something that they can discuss with me during my show on Monday night Is there something you would like to ask them? Oh my I Wish I'd had some warning about that I could probably think of another of several things You'll probably think of a thousand things afterwards. I know that sort of slipping it in the back door I didn't check with two methods on that But I thought perhaps you would have something that you might like to ask them because they'll be talking to me on Monday night Well, there are a couple of things that I where I think there's a possibility of great misinformation one We've just been talking about the tax reform. I know that the people have been told where we're eliminating a number of so-called tax deductions and so forth In return for the much lower rates that if the people have any questions as to exactly How this would come out for them regarding what the fairness would be with their taxes be increased or Reduced they in fact will be reduced the only people who have to fear this are those people who've been avoiding their fair share of taxation By taking advantage of certain tax shelters and loopholes and so forth But if they would ask so that they would know and understand very much for this opportunity All right Thank you. Thank you Thomas Rick a lotto from WRHC radio station, Miami one moment Go ahead, please don't look good morning. Tomas. It's great to hear your voice again How do you feel I feel just fine? I really do as a matter of fact as Soon as you and I are finished here. I'm going over and saddle up a horse and take a ride Well, mr. President, we're very glad I ask you about the Kennedy-Khrushchev agreement and you said that as far as you are concerned That agreement has been abrogated many times by the Russians and Cuba my question sir Are you prepared to denounce that agreement publicly and officially are we talking about the agreement of Did I understand of the the Kennedy-Khrushchev agreement with after the missile crisis in Cuba? Well Actually, that was an agreement an informal agreement. It had no legal standing and It is true that the Soviet Union have observed the most important part Which was the not Replacing the nuclear missiles in Cuba or having any there they have observed that Almost from the beginning. However, there are other facets of that kind of informal agreement that have been violated the use of Castro's forces throughout the world such as in Angola and all his interference in Central America and Latin America and attempts to get overthrows of legitimate democratic governments and all so I Don't see where there's any need to Take any action with regard to that particular agreement, but simply to deal with each issue as it comes up and What they are doing and what they're not doing what they're doing with regard to stirring up revolution in Central America Is wrong for all the Americas and I think all of us should oppose it Yes, and I think we are in dealing with it where he is Attacking such as in right now in Nicaragua. We did it before that in El Salvador when we first came into this administration The whole question was whether Salvador was going to Go communist well now we have a democracy there there have been several elections and Supervised elections in which we know that they were free of any corruption Democracy is on the march and in other areas and the right now the sore spot is Nicaragua And we're going to continue our help and support of the freedom fighters We have And more than one occasion we have heard some Proposals from the present Cuban government about wanting a better relationship and wanting to discuss with us How that could come about we've responded and then we found that really they they had no concrete proposal They were offering nothing I Do not believe that armed overthrow is the answer But I believe that we should continue some of the restraints and restrictions that we have with regard to our relations with Cuba But at the same time Make it evident that any time that they want to prove by Dean not just word That they are willing and want to come back to the community of American nations And as they once were we'd be very happy to help and to help open the door for that but at the present time they are openly a satellite of the Soviet Union and taking their orders from the Soviet Union and we see no No opening For us to to be of help Mr. President, do you think that when you finish your second term among your legacy to history will be a Central America and a Caribbean free of Communism and tyranny I Don't know whether we can accomplish that entirely qualify that word but I think that the progress that is being made in Latin America with regard to the democracy is far More outstanding than many of us have realized Over these past couple of years right now about 90% of the people in Latin America Live in democracies or in countries that are rapidly moving toward democracy that has never been true before and We're going to continue helping in every way we can To keep that trend going, but I think great progress has been made One final question. Would you be discussing the situation on the activities of Cuba, Nicaragua with Mr. Gorbachev in Vienna? I I would think that that that subject could very well come up because as as I view this these talks with Mr. Gorbachev and our our effort to try and Lesson the hostility and see if we can't eliminate some of the suspicion and Exist between the two countries there. I've think very very much that we would point out to him the the contrast between our own conduct and What he is doing with regard to the Americas or what his country is doing with regard to the Americas by way of of Cuba principally and Get that out on the table as one of the facets of the relationship that we think stands in the way of of Any better relationship with the Soviet Union Thank you very much, Mr. President. Well, thank you and a pleasure