Understanding Elixir Tokenization and Parsing Using Erlang Tools

283
clicks
Understanding Elixir Tokenization and Parsing Using Erlang Tools

Source: andrealeopardi.com

Type: Post

This article explores lexical analysis and parsing as applied within Elixir programming, specifically using the tools leex and yecc provided by Erlang. The author, Andrea Leopardi, presents an approachable guide to these concepts, emphasizing the practical aspect rather than the theory. The article first addresses misconceptions about the complexity of lexers and parsers as compared to manual string manipulation or regular expressions. Leopardi goes on to give a detailed walkthrough of creating a lexer with leex, explaining the syntax, rules, and how to write and compile a lexer file. After that, the article covers building a parser with yece, understanding grammar rules, defining terminals and non-terminals, as well as explaining rule creation and the conversion into Elixir lists. The final part of the article integrates these tools within an Elixir Mix project, detailing how Mix can conveniently manage the file compilation process. A small update notes the use of 'String.to_charlist/1' replacing the deprecated spelling 'String.to_char_list/1' as of Elixir 1.3. The author concludes by highlighting the ease of using Erlang from Elixir and urges readers to explore more advanced features and refer to the official documentation for more complex usage.

© HashMerge 2024