Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
1.in
1.note
1.out
1.validator
2.in
2.note
2.out
2.validator
3.in
3.note
3.out
3.validator
4.in
4.note
4.out
4.validator
README.md
example.in
example.out
example.validator
validator

README.md

nbd-lang

You're going to write a small programming language! Relax, it will be easy. It will only support integers, addition/subtraction, ifzero statements, and println.

The problem

Here's the grammar for the language:

<program>     ::= <statements>
<statements>  ::= <statement>
                | <statement> ";" <statements>
<statement>   ::= <ifzero>
                | <assignment>
                | <addition> | <subtraction>
                | <println>
<ifzero>      ::= "?" <value> "{" <statements> "}"
<assignment>  ::= <variable> "=" <value>
<addition>    ::= <variable> "+=" <value>
<subtraction> ::= <variable> "-=" <value>
<println>     ::= "!" <value>
<value>       ::= <variable> | <integer>
<variable>    ::= [a-zA-Z][a-zA-Z0-9]*
<integer>     ::= [0-9]+

Optional whitespace is allowed between each term, but not required anywhere.

Example

STDIN

Here's an example program exercising all of the language:

x = 3;
y = 2;
y += x;
y -= 2;
x -= y;
? x {
  ! 1;
  y = 0;
  z = 0
};
? y {
  ! 2
};
? z {
  ! 3
}

STDOUT

1
2
3