Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Conversation

@skx
Copy link
Owner

@skx skx commented Jun 15, 2020

This pull-request, once complete, will replace our inline parsing with a standalone brainfuck lexer.

The lexer will produce a stream of tokens, along with a count of how many times those tokens were seen repeated.

So given an input string of "<<<<<>>>>>" we'll expect to see:

  • {Type: "<", Repeat: 5}
  • {Type: ">", Repeat: 5}
  • {Type: EOF, Repeat: 1}

Trivial cases added too, but not exhaustively. This will close #3.

skx added 4 commits June 15, 2020 08:04
This lexer will parse programs, skipping unknown characters, and
collapsing repeated occurrences of identical tokens.  The result
will be a stream of values which can be compiled.
I've updated the lexer to skip newlines/unknown characters, and
avoid handling repeated loop open/closes - since we need to count
those separately.

We're now using the lexer in our generation and that is good.
Oftentimes brainfuck programs are formatted in a "readable" fashion
with newlines, and spaces.  If we have an input-program that
looks like this:

> ---------------------------------
> ---------------------------------
> +++----

We'd parse that naively as:

>  {Type: "-", Repeat: X}
>  {Type: "-", Repeat: X}
>  {Type: "+", Repeat: X}
>  {Type: "-", Repeat: X}

i.e. The first two lines would count as two tokens.  If we remove
the newlines before we process the input we instead get:

>  {Type: "-", Repeat: X}
>  {Type: "+", Repeat: X}
>  {Type: "-", Repeat: X}
@skx skx merged commit e3bc7f8 into master Jun 15, 2020
@skx skx deleted the 3-lexer branch June 15, 2020 07:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite with a lexer, parser, etc.

2 participants