2 * This file is part of the pep8analyser project.
4 * Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
6 * Inspired from the Nit language grammar by:
7 * Copyright 2008-2009 Jean Privat <jean@pryen.org>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 /* This grammar defines the Pep/8 language. */
24 /*****************************************************************************/
26 /*****************************************************************************/
29 lowercase = ['a' .. 'z'];
30 uppercase = ['A' .. 'Z'];
32 letter = lowercase | uppercase | digit | '_';
37 any = [all - [cr + lf]];
43 eol_helper = cr lf | cr | lf; // This takes care of different platforms;
45 hex_digit = ['0' .. '9'] | ['A' .. 'F'] | ['a' .. 'f'];
47 /*****************************************************************************/
49 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
61 float = digit* '.' digit+;
62 char = (''' [[any - '''] - '\'] ''')
64 | (''' '\' 'x' hex_digit hex_digit ''');
65 string = '"' str_char* '"';
66 hex = '0' ('x'|'X') hex_digit+;
72 tk_byte = '.' ('B'|'b') ('Y'|'y') ('T'|'t') ('E'|'e');
73 tk_word = '.' ('W'|'w') ('O'|'o') ('R'|'r') ('D'|'d');
74 tk_block = '.' ('B'|'b') ('L'|'l') ('O'|'o') ('C'|'c') ('K'|'k');
75 tk_ascii = '.' ('A'|'a') ('S'|'s') ('C'|'c') ('I'|'i') ('I'|'i');
76 tk_addrss = '.' ('A'|'a') ('D'|'d') ('D'|'d') ('R'|'r') ('S'|'s') ('S'|'s');
77 tk_equate = '.' ('E'|'e') ('Q'|'q') ('U'|'u') ('A'|'a') ('T'|'t') ('E'|'e');
78 tk_burn = '.' ('B'|'b') ('U'|'u') ('R'|'r') ('N'|'n');
80 end_block = '.' ('E'|'e') ('N'|'n') ('D'|'d') (any | eol_helper)*;
84 /*****************************************************************************/
86 /*****************************************************************************/
90 /*****************************************************************************/
92 /*****************************************************************************/
93 listing = [lines]:line* label_decl? end_block;
96 = {empty} label_decl? comment? eol
97 | {instruction} label_decl? instruction comment? eol
98 | {directive} label_decl? directive comment? eol;
100 label_decl = id colon;
104 | {binary} id operand;
107 * We will manage which operands are possible with each stmt at a higher level.
108 * This will allow better error messages and a cleaner model. */
111 | {any} value comma id;
120 = {byte} tk_byte value
121 | {word} tk_word value
122 | {block} tk_block value
123 | {ascii} tk_ascii value
124 | {addrss} tk_addrss value
125 | {equate} tk_equate value
126 | {burn} tk_burn value;