Lexical Analyser Tool for Scala

Good afternoon,

I am new to Scala, and wanted to check whether there is something to similar to leex and yecc for Erlang. Two tools which help you in the lexical analysis and parsing of inputted strings.

Thanks a lot and good day

Antlr is the JVM standby for parser generators. That said, in the scala world, parser combinators rule supreme. Take a look at fastparse or atto: You may find that a lot more ergonomic than parser generators.

1 Like

Thanks a lot for your help. :slightly_smiling_face:

Is ANTLR an external component to Scala, or is it part of the Scala libraries please ?

Just to understand clearly, is ANTLR a lexer and parser generator, or does it need a form of tokens and symbols to run please ?

Thanks a lot and good day

You could consider using a parser combinator lib instead of a parser generator.
I would recommend having a look at FastParse

which provides a nice API similar to Scala parser combinators but with much better performance.


General context: relatively little is part of the official Scala libraries, deliberately. Scala strongly embraces the open-source ethos, so things like this are usually external.

(There used to be an official scala-parser-generators library, but it was eventually was superceded by newer ones like FastParse, and so it was removed and became an external library.)


ANTLR (https://www.antlr.org/) is an open source a parser generator in the tradition of yacc and bison. It’s target language is java and can be consumed from scala.

Its use in the scala infrastructure is at best infrequent, and has been taken over almost completely or completely by parser combinator libraries like fastparse.

Scala itself just provides a compiler a standard library and runtime library.

1 Like

Is there a proper tutorial of how to use Antlr or Fast Parse please ?


1 Like


I am trying to write a compiler from scratch. Does anyone know by any chance how to write a compiler using parser combinators for Scala obviously, as those are the specifications for the program?

Thanks a lot and good day

Well - you could start by using ScalaParse written by Mr. FastParse: https://www.lihaoyi.com/fastparse/#ScalaParse

1 Like

Thanks a lot for your help.

Please feel free to share any other tutorials or webpages related to Scala Parse Combinators. :slight_smile:

Thanks a lot and good day