240 likes | 681 Views
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?.
E N D
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
Explanation Extend a simple parser
Explanation Write a regex for “number”
Explanation Create a parser named “value”
Explanation The parse result is Scala.Any
Explanation We accept any input that matches “number”
Calculating the Result Live Coding Demo
Building a Small Programming Language • Variable Assignments • Loops • Conditionals • Functions • Error Handling
Small Language in Action Live Coding Demo
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
Miscellaneous • Code examples are available on GitHub: • https://github.com/travisdazell • Contact Information: • travis.dazell@digikey.com