 Okay. Hello everyone. Thank you for coming. It's really nice to see so many people here. My name is Andrew and what I'm doing, today I realize that I'm doing Perl for 20 years since 1999. I'm also organizing the Perl conference. So it's PerlCon this year in August, so you can take a look. But I'm not going to promote Perl here. What I'm going to do, I'm going to talk about one specific part of Perl6, which is really interesting, especially in this audience for creating some compilers, parsers, translators, whatever interpreters for other languages. So I will demonstrate how Perl6 can do this stuff today. So basically just a couple of words about what Perl6 is. So a few years ago, well three years ago, a lively creative Perl itself announced that there's Perl6.00 release, and it was done here at Fosdom. Since then, basically you have this table version of the language specification, and you also have really nicely working compiler. You have to realize that Perl5 and Perl6 are basically different languages. Of course, they have many things in common, the same spirit of the language, but still it's a separate language, and all that I'm going to talk about is only about Perl6. So it's different language. There's only one compiler at the moment which you can use. It's called Rakudo, and you can download it from rakudo.org, and you can use this compiler to run all the examples that I will demonstrate later. The interesting thing about Perl6 is that this compiler is also written in Perl6. So it's self-hosting language, and that's one of the reasons why it took so long to bootstrap the language. Also, there's the MQP, not quite Perl. It's a subset of Perl6 which was developed to help to build this bootstrap in process. This is just a random, really random. I just took some random code from repository. This is the source code of Perl6, and it's written in Perl6 plus some MQP somewhere, which uses some MQP calls to do some low-level stuff. But this image is not aimed to show you how difficult Perl6 is. It's not a noise language. It's internals of the compiler, so it has to be something difficult. Basically, in Perl6, you can do things like this. So you can use Unicode characters, you can use, for example, superscripts to create the power of variable, instead of using two stars, for example. But that's a side story. So what's interesting in Perl6 for creating other languages is that they have the updated regular expression engine, and the regular expressions are not called regular expressions. Well, they are not regular, that's regular. They are now called reg-exes or reg-exes, whatever you like to read it. The second part is that Perl6 has extended version of regular expressions which are called grammars. That's the end of the slides. So what I'm going to do next, I'm going to show you how quickly you can create a compiler. Well, not necessarily it should be a compiler. By compiler, I mean that it's some program that translates, that reads that understand language, not necessarily compiles it to an executable file in binary code. So here's the empty file, and what I'm going to do, I'm going to create a program that will be able to understand this program. For example, it's just a random language, it's not language, is it big enough, and I'm going to print it. So imagine that this line is the line in language which is the minimalistic language, and I'm going to parse and execute it using Perl6 grammars. So what I'm going to do, I have to create the grammar, so I have to describe the language. It's somehow similar to what the BNF syntax is using. So I create the grammar, I can call it whatever I want, and that's basically the class. So the syntax really resembles how you define classes in other programming languages, but instead of methods, you have rules and tokens. So my first rule, and it should be called top, so the beginning, my first rule is to parse the whole sentence, the whole program. So my program is basically a list of statements. A list of statements, and what I'm typing now, this line five is actually the regular expression, which is embedded inside the Perl6 code. So grammar line three rule, line four are Perl6 code, inside line five is basically already a regular expression, not a regular, a regular. So I'm going to have more than one statement, or actually zero. A syntax is really like a regular expression, so the star quantifier means there can be zero or more repetitions of something on the left. Then I tell that these statements are separated by the semicolon. So that's simple. What I have to do now, so I described this grammar to some extent, and now I can use this grammar to parse the string containing this program in this programming language. That's it. After that, I, for example, can say, say is operated to print in Perl6. So I can use this test.pl, of course, because there are no statements, so I have to define them. So a statement actually is the next rule, which I have to implement. Statement, and what is a statement? A statement is, in my example, it's either a vertical bar for or, either a variable declaration, so I can type variable declaration, or the printing instruction. For example, actually, we can call it just a function call, right? And from this moment, I have to define what is a variable declaration, what is a function call, and again, it's really simple. So I can variable declaration. What is it? It's a string, bar followed by variable name, very upload name followed by equal sign followed by some number, and so on. So I have to also explain to Perl6 what is a variable name. So I create another rule, but this time it will not be a rule, it will be a token. Why a token? Because variable name is something that does not contain spaces inside. So Perl6 understands that, for example, in the line one, I will omit spaces around the equal sign, it will still work. So I don't have to do any extra work to explain that it is allowed there. So Perl6 will understand as soon as I'm using the rule keyword, it will understand the spaces around parts of the expressions are valid things. So what is a variable name? Basically, it's just some letters or whatever, some word characters more than one. The same for the number. Let's do a simple thing. For example, numbers are only digits, so it's integers positive, but for our example is more than enough. And what else? We have the function call thing. So let's create another rule, function call which will expect a function name. In our case, it's only print. So we are only having a single function in this language followed by a variable name. So more or less, that's it. So what I also want you to take a look at, so for example, line 13 rule variable dash declaration. And Perl6 dash is a valid character for it can be used inside the identifier of the, for example, variable or function or method name. Okay. So it looks like, okay, let's try running it. No still no method statements, because it has to be statement and s is like, yeah, it's the star. Okay. So let's take a look at the output of this program. So what it says, it says that it managed to pass the top line containing the program. And basically, it then demonstrates, so it contains a statement bar x is 20. The second statement is print x, and each statement has some details about what it is. In the first case, it's a variable declaration with the variable name and the number that is assigned to this variable. In the second case, it's again the function call. The function name, well, the function name is missing here because we didn't create this special rule or token for the function name, but still we have the variable name x extract hit. So basically, here, we already pass in the program. So PEL 6 understands, well, my program, my test program understands what's the structure of this program. And the next step is just to execute this. So yeah, and also notice that unlike traditional approaches to creating compilers, there's no separation for like lexar and parser. Everything goes in a single grammar. So my variable declaration, my numbers and like equal sign or bar keyword are living here. There's no special lexar which extracts the parts of the language first. So now the second part, the second part is to execute this. So what I want, I want to print 20 in the console. And what I will do, I will add actions, so called actions to my grammar. So this is the placeholder for the action. So again, line 13 starts with some PEL code, inside which we have some regular expression, inside which we have again, a block which contains PEL 6 code. So here where the line 15 is, I will type some PEL code and I will just save this variable in some variable storage. So this is how I can do it. Variable name is number. I will explain this plus, and of course I have to create some storage for this. So I can create the hash bar which will contain my variables, and after the program is passed, I can just type it and see what's there inside. So what's there inside? You see this line, the last line? Yeah, sorry. This line. So for the last like PEL. So this line demonstrates the content of this variable storage after I passed and executed the action. So you see so X contains 20, and now actually I can create another action which will use this value to print it. So I have to go to the function call rule, and here I will just print. So in PEL 6 there are two functions that print. Well, actually there's more. So there's print, but also there's three letters say, which also adds the new line at the end of the output which is really handy in many cases. So what I'm going to do, I'm just going to print this exact value. That's it. So you see just above, there's 20 in the output, so it works. Of course, it is not limited to this program only. I can extend it, I can add for example another variable, which is 42 and I can print it, and you see so 42 is here, and I also see what the structure of this program is. So basically that's a real short demonstration of what you can do with grammars, and you can do really quickly. So it took me five minutes to type this, and it's already a working prototype of what you can expect. Of course, the bigger the language becomes, the more is your desire to split PEL 6 and a regular expression in parts of this grammar. So what can be done, you can extract these parts of the grammar to separate class A, for example, and what you have to do, so we are going to move these to the methods of these class, and the name of the method should be the same. So it's method this time, should be the same as the method at the rule name that is activating these actions. So it's variable declaration, method variable declaration, and it's just the PEL code which, okay, I have these which does what it did before, but you also will expect something in this int variable which is passed to this method, and also I can move the function call function call action to a separate method. So I will just remove it from the grammar, and I will move it to the function call, and then when I am passing the string, I can pass in the named attribute actions, these class containing actions, and if everything is okay, you will get exactly the same behavior, so nothing changed from the user perspective, but from the perspective of the developer, you have a separate class with PEL 6 code, you have a separate grammar described in the language. Also, so I promise to talk about this, so basically this dollar slash variable, you can name it differently, you can just have dollar something, I mean you can type letters there. It will contain the information which contains some information similar to what we have here. This parse tree, the fragment which is passed at this moment like function call variable declaration, is passed further in this method and you can use it. So basically when you type this, you are referring to this variable, you are taking it like an element from the hash and the key for this element is variable name, and on the right side it's the number. This which is selected is a object of a grammar class, the so-called match object. If you type plus before, you will just ask PEL to make a number out of it somehow. So PEL6 knows how to convert this match object to a number, this is exactly what we need. Actually here, it converts the match object to a string. You can extend it like you can type the tilde before this, but you don't have to do it, PEL6 will do that. So that's the short example. I can also show you, so there's github.com slash hash slash lingua is an example of much bigger language. It's used the same technique that I just demonstrated. What it contains, it contains a few files. So there's the grammar. Oh my God. Yeah. You can go to itself if you have internet here, but nevertheless it's just the bigger thing. For example, we go to the test directory of this. I created some tests. For example, there's if statement implemented in this language and again, you can find it in the actions and in the grammar class, how we do it. It's really easy. Just step by step to increase your language, starting with the example I demonstrated earlier. Finally, you will have to deal somehow with, for example, functions. So you have to put the function to, so you have to understand that this is the definition of a function. You have to put the parse tree somewhere, and then you have to evaluate it. So if you will, on that github link, so you see there's the grammar and my top rule states that it's not only statements, it's also can be a comment for example, and also I'm clearly separating different type of statements just to make the rest of the grammar simpler. Yeah. So it means that instead of, so I can have the vertical bar means or, so it's either this or this or this. But inside, remember on the previous screen, I showed you this thing, dollar something. So when you are inside an action or inside the grammar rule, you can refer to one of those alternatives using the single name. So it's much, much easier than you don't have to create like if this is a statement, if it's assignment, if it's something. So yeah. So okay, the final thing, I would really recommend you to read this book. It contains a lot of examples of how you can use grammars and also there's something in this book written by me. You can buy these books downstairs in the pearl booth. So thanks a lot for listening. I hope it was interesting and success with poll six and languages. I will take picture. So yeah. What type of grammar is it? So yeah, I would recommend you to. What type of grammar is it? LL1, this one you mean, right? That's the question to developers more than to me. Actually, I think that in the documentation of poll six, you don't have the explicit answer to this question if I'm correct. So basically, yeah. If it satisfies, yes? Example, white space was automatically allowed to be the code. Yes. It's when you're using the rule keyword. If you're using token that it's not allowed. But you also can redefine. So that's the default built-in rule called WS, white space, which is explained what in white space is. So it's not just a space. It's like new line, whatever. And you can redefine it, for example, to implement comments. Yeah? Okay, then thanks a lot.