File: syntax.bnf

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (35 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Main brainfuck syntax. Based on the BS language.
// Files start with a number, the space needed by the
// brainfuck program. Each file will be declared as its
// own function. A function takes a string for input, and
// returns a string, which is the output from the program.
delimiter = BFDelimiter;

void BFDelimiter();
BFDelimiter : "[ \n\r\t]*";

Str SNumber();
SNumber => v : "[0-9]+" v #constant;

BfExpr SFile();
SFile => BfExpr(pos, space, code) : SNumber space - SComment - SRoot code;

// Note: the {} chars are used to end blocks in other languages.
void SComment();
SComment : "[^<>,\.\+\-\[\]{}]*" #comment;

Array<BfToken> SRoot();
SRoot => Array<BfToken>() : ( SToken -> push - SComment )*;

BfToken SToken();
SToken => BfBack(pos) : "<";
SToken => BfFwd(pos) : ">";
SToken => BfInput(pos) : ",";
SToken => BfOutput(pos) : "\.";
SToken => BfInc(pos) : "\+";
SToken => BfDec(pos) : "\-";
SToken => BfLoop(pos, c) : "\[" #keyword, SRoot c, "\]" #keyword;

// Integration with BS.
lang.bs.SAtom => BfExpr(pos, space, code, input) :
    "bf" #typeName, "(", lang.bs.SExpr(block) input, ",", SNumber space, ")", "{", SRoot code, "}";