2 * This file is part of the pep8analyser project.
4 * Copyright 2013 Alexis Laferriere <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. */
25 /*****************************************************************************/
27 /*****************************************************************************/
30 lowercase = 'a' .. 'z';
31 uppercase = 'A' .. 'Z';
33 letter = lowercase | uppercase | digit | '_';
38 any = all - (cr | lf);
44 eol_helper = cr lf | cr | lf; // This takes care of different platforms;
46 hex_digit = '0' .. '9' | 'A' .. 'F' | 'a' .. 'f';
53 hex = '0' ('x'|'X') hex_digit+;
54 float = digit* '.' digit+;
55 char = ('\'' ((any - '\'') - '\\') '\'')
56 | ('\'' '\\' any '\'')
57 | ('\'' '\\' 'x' hex_digit hex_digit '\'');
58 string = '"' str_char* '"';
64 tk_byte = '.' ('B'|'b') ('Y'|'y') ('T'|'t') ('E'|'e');
65 tk_word = '.' ('W'|'w') ('O'|'o') ('R'|'r') ('D'|'d');
66 tk_block = '.' ('B'|'b') ('L'|'l') ('O'|'o') ('C'|'c') ('K'|'k');
67 tk_ascii = '.' ('A'|'a') ('S'|'s') ('C'|'c') ('I'|'i') ('I'|'i');
68 tk_addrss = '.' ('A'|'a') ('D'|'d') ('D'|'d') ('R'|'r') ('S'|'s') ('S'|'s');
69 tk_equate = '.' ('E'|'e') ('Q'|'q') ('U'|'u') ('A'|'a') ('T'|'t') ('E'|'e');
70 tk_burn = '.' ('B'|'b') ('U'|'u') ('R'|'r') ('N'|'n');
72 end_block = '.' ('E'|'e') ('N'|'n') ('D'|'d') (any | eol_helper)*;
74 id = (lowercase|uppercase|'_') letter*;
76 /*****************************************************************************/
78 /*****************************************************************************/
80 listing = [lines]:line* label_decl? end_block;
83 = {empty} label_decl? comment? eol
84 | {instruction} label_decl? instruction comment? eol
85 | {directive} label_decl? directive comment? eol;
87 label_decl = id colon;
91 | {binary} id operand;
94 * We will manage which operands are possible with each stmt at a higher level.
95 * This will allow better error messages and a cleaner model. */
98 | {any} value comma id;
106 = {byte} tk_byte value
107 | {word} tk_word value
108 | {block} tk_block value
109 | {ascii} tk_ascii value
110 | {addrss} tk_addrss value
111 | {equate} tk_equate value
112 | {burn} tk_burn value;