Brainfuck compiler in scala

Want to make some kind of domain language (DSL) for practice, the first idea is to write a Brainfuck interpreter or compiler. The first idea was to redefine such functions as they will behave like Brainfuck commands: ">" , "<" , "+" , "-" , "." , "," , "[" , "]" . Unfortunately, you cannot decal a function as "." .

Is there a better solution for writing to Scala?

+7
source share
3 answers

You are not specifically talking about this in your question, but it seems that when you say DSL, do you mean Internal DSL ?

Internal DSLs are great, but in principle you are always limited by the syntax of the language you are trying to use. Scala is a particularly good language for writing internal DSL because it has a simple and flexible syntax. But it is not infinitely flexible.

Other options you might want to explore may be:

  • Select a different character instead of ".". Scala can support Unicode identifiers, so if you like to follow this path, perhaps you can use "∙"?
  • Instead of external DSL
+6
source

I suppose you know about that.

Also this example suggested by Mikaël Mayer in the comments.

+5
source

I wrote a BrainFuck interpreter that uses Scala parser combinators. source code is here if this can help.

+1
source

All Articles