Skip to content
0:00 / 0:00

#perl6#raku#grammars

Andrew Shitov. Perl 6 grammars for simple compilers (lightning talk)

Andrey Shitov

191 subscribers • 2 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.
  • A classic. People kept recommending it from 2018 to 2023.
  • Presented by Andrew Shitov

Intermediate. Assumes working knowledge.

1.9K views7 years ago1 recommendation

Programming languagesSystems programmingCompilers and interpreters

Andrew Shitov demonstrates how to quickly build a grammar for a simple programming language using Perl 6.

A live demonstration of how to create a grammar for a simple programming language. Lightning talk at Perl & Friends 2018 in Barcelona. 17 November 2019

Why it's here

1 person recommends this

What people say. Recommended as a fast, fun, and practical introduction to writing grammars in Perl 6.

u/raiphin r/ProgrammingLanguages • Recommends

On “Perl 6 as a new tool for language compilers - YouTube”

I recommend Andrew's **4 minute** live coding session video over the OP 20 minute video. Same code, more laughter, smoother presentation, less P6.

u/raiphin r/ProgrammingLanguages • Recommends

On “"Perl 6 as a new tool for language compilers" talk @ FOSDEM 2019 (x-post /r/Perl6)”

Skepticism is good. If someone wants power, P6 provides customizable lexing, unrestricted grammar class power, AST generation, the works. But why does a presentation have to discuss lexing and parsing if simply writing a grammar gets the job done? The P6 compiler is written in P6 using P6 grammars/actions. It starts by inheriting from a generic HLL grammar, just adding what makes P6 P6: grammar Perl6::Grammar is HLL::Grammar No need to discuss lexing or parsing, just get on with writing the grammar and the job's done. Omitting a ton of detail, here's a high level view of the general coding pattern Andrew will use: grammar my-programming-language { rule TOP {…

u/raiphin r/ProgrammingLanguages • Recommends

On “What's a good open source project for learning about programming languages?”

This sub is a good place for learning. I've been visiting here for a decade and the learning never ends. :) ---- While I love this sub I've also spent many years learning from a wonderful open source community focused on creating PLs and their implementations, including a PL that anyone could either alter as part of learning about creating PLs and their implementations, or could use to create their own PLs from scratch. I'll introduce it by discussing Audrey Tang's involvement. Audrey began programming in Perl at 12 years old. Later she began learning Haskell, and one weekend in 2005 started a Haskell prototype of the community's PL (recently renamed Raku), and joined a chat channel of th…

u/raiphin r/ProgrammingLanguages • Recommends

On “How can I create a language?”

There are three sections in this comment covering quickly creating your first, second, and third programming languages, with each being more ambitious, using the programming language creation tool Raku. It's just a suggestion for a fun easy way to get going. Ultimately, whatever tech you choose to use, don't forget to apply the -Ofun compiler option. 🤩 # Your *first* toy language Use an online Raku evaluator such as replit's to follow this **4 minutes 20 second** live coding video in which Andrew starts a programming language from scratch and successfully runs its first couple programs, typing and explaining everything, no cheating. He: * Introduces Raku (which used to be called Perl…

u/raiphin r/ProgrammingLanguages • Recommends

On “Books, books, books...”

There are a million ways to get started. I'm going to have fun describing one that's *lightning fast*. It'll sound just like an infomercial, trying to sell you something. It's actually all classic bona fide open source community stuff but why should that stop me being over the top? :) The rest of this comment is to be heard in your head using whatever infomercial crap announcer voice you prefer... A live coding session that covers everything, every single keystroke, for starting a programming language from scratch, and successfully running its first couple programs, including: * Introducing the tools being used; * Introducing a new programming language; * Writing an initial test case (a…

u/raiphin r/ProgrammingLanguages • Recommends

On “Which n languages would expose someone to the largest breadth of paradigms/features?”

What about multiple paradigm languages? Especially ones that can be arbitrarily extended to support any and all languages/paradigms? \---- A recent article called P6 "the world's worst ML", referring to P6 emulating ML family languages like Haskell. In response a P6 designer who has in the past demoed P6 emulating lisp and haskell doing quicksort wrote: >I think that we’re pretty happy with \P6\ being the “World’s Worst ML”, so long as it can also (simultaneously) be: the “World’s Worst Smalltalk”, the “World’s Worst Lisp”, the “World’s Worst Snobol”, the “World’s Worst QCL”, the “World’s Worst Erlang”, the “World’s Worst Prolog”, the “World’s Worst Python”, the “World’s Worst C”, and…

u/raiphin r/ProgrammingLanguages • Recommends

On “What would be wrong with a multi-syntax programming language?”

You might want to check out What are examples of language syntaxes which do a GOOD job embedding (an)other language(s) in a host language?, a thread written in this sub a while back. The usual suspects get mentioned (Haskell's quasiquoting, Racket) but also some others. I wrote one of the highest voted top level comments. It was about what might seem like a minor cosmetic thing (*seamless weaving* of multiple syntaxes) but what should be of interest today is the underlying multi language technology that Raku and its sibling nqp ("not quite paradise") are both built on and make available for any devs using them. That multi language tech began with a comment I quoted in a non-authoritative b…

u/raiphin r/ProgrammingLanguages • Recommends

On “Are there any languages that use a PEG in their official specification?”

I think the Language Machine that's mentioned on the wikipedia page I linked looks interesting but I haven't yet explored it. nqp and P6 are themselves examples of nqp/P6 grammars because their grammars are defined in nqp grammars which are both of an ilk. (nqp is written in nqp. P6 is written in P6 and nqp. nqp is a subset of P6 designed for writing compilers, including its own compiler, and for bootstrapping P6.) But the first grammars I'll link you to are vastly simpler so you won't immediately get overwhelmed. First, [a 4 minute live coding session showing creation of a basic grammar/parser/"compiler" for a single line of code] of some imagined language. The author did this session fo…

u/raiphin r/ProgrammingLanguages • Mentions

On “A parser generator language.”

It's cool that the input is reparsed, and the AST redisplayed, automatically as you change the rules. Some links to stuff you might like to explore if you haven't already: * Wikipedia's Analytic Grammars section. I find The Language Machine the most interesting of the links in that section. * The first program that I think is along the lines you describe from the early 1960s: META\_II. * My focus is raku, whose grammar formalism / parser generator belongs in the Wikipedia Analytic Grammars section linked above though I've not bothered to add it. The formalism is Turing complete in both parsing and generating aspects. For a taste, there's a live coding video showing [construction of a compi…

u/raiphin r/ProgrammingLanguages • Mentions

On “Wow, how do u do it?”

Here's one way to look at it. The conversation we're having could be said to have started with you *encoding* something in your head into *English* with some effort to follow a relatively fixed *grammar* it supposedly has, into chunks such as *paragraphs*, *sentences* and *clauses*,with some *punctuation* thrown in too, using *words* from an evolving *vocabulary*. Then you wrote it on reddit. Then *I* looked at reddit. I saw your comment and decided to read it. I *parsed* the words you've written *and* then constructed an *understanding* of your intended meaning (which may or may not have matched what you *really* meant) and then *chose* to *do something* based on my understanding. In this…

u/raiphin r/ProgrammingLanguages • Mentions

On “Creating a programming language that allows a programmer to create their own language”

Imo your basic idea is spot on. And imo having a go at great ideas is itself a great idea. Regardless of whether others have tried the same thing. \---- Very loosely speaking there are a few languages/systems that have attempted what you outline. The three I know of are Oracle's Graal/Truffle, the Lisp Racket, and Raku. Each of these systems has its own strengths and weaknesses. My focus is Raku. I would say Raku is more ambitious than Oracle's system in terms of what it delivers for devs into the spirit of open source, and more practical than Racket in terms of interoperation with existing languages and their compilers. Here's a live coding session, with commentary, that goes from scr…

u/raiphin r/ProgrammingLanguages • Mentions

On “Are there composable compilers?”

I focus on Raku. I'd say Raku works more or less as you describe. Raku is a mutable collection of mutable cooperating "slangs" (aka sub-languages aka DSLs). To get up to speed, first review how one builds a *single* (toy) language with Raku (in 4 minutes 19 seconds). Next, imagine multiple mutually recursively embedding grammars/languages: grammar DSL-B { ... } grammar DSL-A { rule TOP { 'Hi' <DSL-B::TOP>? } } grammar DSL-B { rule TOP { 'Bye' <DSL-A::TOP>? } } say DSL-A .parse: 'Hi Bye Hi Bye Hi' displays: 「Hi Bye Hi Bye Hi」 DSL-B::TOP => 「Bye Hi Bye Hi」 DSL-A::TOP => 「Hi Bye Hi」 DSL-B::TOP => 「Bye Hi」 DSL-A::TOP => 「Hi」 (I've just sho…

u/raiphin r/ProgrammingLanguages • Mentions

On “Where to start for self-learning of the basics?”

*(Edited to replace the fishing rod (camas is currently 404ing), replace 'raku' for searching years prior to introduction of that name, and other tweaks.)* ---- Hi. I focus on Raku, another "language oriented programming" language that *might* be of interest. (Think Racket, but then think again.) I've commented about it many times in this sub over the last decade, including many comments about its use for folk in your situation. I do so again in this comment. But let me first given you a fishing rod in the form of a way to search this sub (or indeed the entire of reddit) for comments about aspects of Racket, self-learning, Raku, or whatever. ---- Not a lot of people are aware of pushsh…

u/raiphin r/ProgrammingLanguages • Mentions

On “Video resources to help learn”

This 4 minute video should change open minded folks' thinking about what is possible. When this video was produced (2018), the languages ecosystem underlying the builder it demonstrates wasn't mature enough to change the rules of the game. (Moreover, in the end, the rules of the programming game, and thus the programming of programming languages game, is all just nomics.) But I think it's well worth a watch to: * **See what's possible for PL lovers** The language developed in those 4 minutes is just the creamy filling of a Twinkie. But if you imagine a Twinkie as a form of food, and let your imagination soar rather than cynicism overrule your heart, you should begin to see *possibiliti…

u/raiphin r/ProgrammingLanguages • Mentions

On “Implicit Multiplication”

> Thanks very much for sharing and giving me an excuse to look into Raku. This might be useful for test driving new syntax. I find it perfect for that sort of thing. But I already know Raku. It's hard to know if you'd find it useful or not. It's really about one's sense of aesthetics, and social sensitivities. Folk typically either love it or hate it and its community members (folk like me ;)). > I have already built a parser and interpreter in Rust that can handle expressions like ax\^2 + bx + c, but it just parses single expressions. It would be just a few extra lines to handle nested expressions and an interpreter in a Raku program. Here are some links to some other repl.its I've made:…

u/raiphin r/ProgrammingLanguages • Mentions

On “Are there anonymous languages?”

The above link is to slides covering three approaches. Sometimes a short video is worth a thousand words. Here's [Andrew Shitov doing a live coding screen cast at what sounds like a small programming enthusiasts' meeting]. Starting from scratch, and chatting as he goes along, he picks a simple initial design for a couple constructs of an anonymous language, writes a sample program, creates the corresponding grammar, invokes the built in parser, writes an initial interpreter, shows it working, extends the program, shows that works too, and then lets out a laugh because ***it's clearly easy and he's done it in FOUR MINUTES***. This anonymous language gets extras like a debugger and profile…