1 / 21

Developing Small Languages with Scala Parser Combinators

Developing Small Languages with Scala Parser Combinators. Travis Dazell Systems Architect Digi -Key Corporation. Agenda. What’s in a Scala parser? Demonstrate basic parser functionality Generating ASTs Put it all together to build a small language. Can I really learn this stuff?.

manton
Download Presentation

Developing Small Languages with Scala Parser Combinators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing Small Languages with Scala Parser Combinators Travis Dazell Systems Architect Digi-Key Corporation

  2. Agenda • What’s in a Scala parser? • Demonstrate basic parser functionality • Generating ASTs • Put it all together to build a small language

  3. Can I really learn this stuff?

  4. The Simplest of Parsers

  5. What’s going on here?

  6. Explanation Extend a simple parser

  7. Explanation Write a regex for “number”

  8. Explanation Create a parser named “value”

  9. Explanation The parse result is Scala.Any

  10. Explanation We accept any input that matches “number”

  11. Can we calculate the result?

  12. Calculating the Result Live Coding Demo

  13. I’m starting to get this!

  14. Can we build a language?

  15. Building a Small Programming Language • Variable Assignments • Loops • Conditionals • Functions • Error Handling

  16. Small Language in Action Live Coding Demo

  17. That’s cool!

  18. Conclusion • Scala parser combinators are powerful, but easy to learn • These parsers can be utilized to perform simple transformations, acting as an adapter between unwanted input and desired output • These parsers can also be used to write entirely new languages, such as our small language example

  19. Miscellaneous • Code examples are available on GitHub: • https://github.com/travisdazell • Contact Information: • travis.dazell@digikey.com

  20. Good Reads

  21. Questions?

More Related