CFG.g4 1015 Bytes
Newer Older
1
2
3
4
grammar CFG;

/* Parser Rules */

5
start:           (onerule NEWLINE+)* onerule (NEWLINE+ | ) comment;
6

7
onerule:         nonterm ARROW (rewrite DELIMITER)* rewrite;
8
9
10

rewrite:         (term_or_nonterm+ | EPSILON);

11
term_or_nonterm: (term | nonterm);
12

13
term:		 (TERMINAL | QUOTE anyvalue+ QUOTE);
14

15
nonterm:	 (CAPS | (LEFT_ANGLE symbol+ RIGHT_ANGLE (APOSTROPHE*)) | (symbol APOSTROPHE+));
16
17
18

symbol:          (TERMINAL | CAPS | UNDERSCORE);

19
20
comment:         (HASH anyvalue* | );

21
anyvalue:        LEFT_ANGLE | RIGHT_ANGLE | APOSTROPHE | UNDERSCORE | TERMINAL | CAPS | ARROW | EPSILON | DELIMITER | ANYCHAR | HASH;
22

23
24
25
26
27
28
29
30
/* Lexer Rules */

/* Tokens */

LEFT_ANGLE  : '<';
RIGHT_ANGLE : '>';
APOSTROPHE  : '\'';
UNDERSCORE  : '_';
31
TERMINAL    : [-~=a-z0-9];
32
33
34
35
36
CAPS        : [A-Z];
ARROW       : ('→' | '->');
EPSILON     : ('ε' | '\\''e');
DELIMITER   : '|';
NEWLINE     : ('\n' | ';' | ',');
37
HASH        : '#';
38
QUOTE       : '"';
39
40
41

/* Characters to be ignored */
WS : [ \r\t]+ -> skip ;
42
43

ANYCHAR     : .;
44
45
46
47

/*
vim: ft=antlr
*/