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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
indexing
description:
"Scanner skeletons for Eiffel parsers"
author: "Eric Bezault <ericb@gobosoft.com>"
copyright: "Copyright (c) 1999-2001, Eric Bezault and others"
license: "Eiffel Forum Freeware License v1 (see forum.txt)"
date: "$Date: 2001/01/20 09:31:22 $"
revision: "$Revision: 1.3 $"
deferred class ET_EIFFEL_SCANNER_SKELETON
inherit
YY_COMPRESSED_SCANNER_SKELETON
rename
make as make_compressed_scanner_skeleton,
reset as reset_compressed_scanner_skeleton
end
ET_EIFFEL_TOKENS
export {NONE} all end
UT_CHARACTER_CODES
export {NONE} all end
KL_IMPORTED_INTEGER_ROUTINES
KL_IMPORTED_STRING_ROUTINES
KL_SHARED_PLATFORM
feature {NONE} -- Initialization
make (a_filename: STRING; an_error_handler: like error_handler) is
-- Create a new Eiffel scanner.
require
a_filename_not_void: a_filename /= Void
an_error_handler_not_void: an_error_handler /= Void
do
make_with_buffer (Empty_buffer)
filename := a_filename
error_handler := an_error_handler
ensure
filename_set: filename = a_filename
error_handler_set: error_handler = an_error_handler
end
feature -- Initialization
reset is
-- Reset scanner before scanning next input.
do
reset_compressed_scanner_skeleton
last_class := Void
end
feature -- Access
filename: STRING
-- Name of file being parsed
last_class: ET_CLASS
-- Class being parsed
last_value: ANY
-- Semantic value to be passed to the parser
current_position: ET_POSITION is
-- Current position
-- (Create a new object at each call.)
do
if last_class /= Void then
!ET_CLASS_POSITION! Result.make (last_class, line, column)
else
!ET_FILE_POSITION! Result.make (filename, line, column)
end
ensure
current_position_not_void: Result /= Void
end
error_handler: ET_ERROR_HANDLER
-- Error handler
feature -- Status report
create_keyword: BOOLEAN
-- Should `create' be considered as
-- a keyword (otherwise identifier)?
feature -- Statut setting
set_create_keyword (b: BOOLEAN) is
-- Set `create_keyword' to `b'.
do
create_keyword := b
ensure
create_keyword_set: create_keyword = b
end
feature -- AST factory
new_bit_constant (a_literal: STRING): ET_BIT_CONSTANT is
-- New bit constant
require
a_literal_not_void: a_literal /= Void
do
!! Result.make (a_literal, current_position)
ensure
bit_constant_not_void: Result /= Void
end
new_c2_character_constant (a_value: CHARACTER): ET_CHARACTER_CONSTANT is
-- New character constant of the form '%A'
do
!ET_C2_CHARACTER_CONSTANT! Result.make (a_value, current_position)
ensure
character_constant_not_void: Result /= Void
end
new_c3_character_constant (a_literal: STRING): ET_CHARACTER_CONSTANT is
-- New character constant of the form '%/code/`'
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: [0-9]+
do
!ET_C3_CHARACTER_CONSTANT! Result.make (a_literal, current_position)
ensure
character_constant_not_void: Result /= Void
end
new_character_constant (a_value: CHARACTER): ET_CHARACTER_CONSTANT is
-- New character constant of the form 'A'
do
!ET_C1_CHARACTER_CONSTANT! Result.make (a_value, current_position)
ensure
character_constant_not_void: Result /= Void
end
new_false_constant: ET_FALSE_CONSTANT is
-- New False constant
do
!! Result.make (current_position)
ensure
false_constant_not_void: Result /= Void
end
new_identifier (a_text: STRING): ET_IDENTIFIER is
-- New identifier
require
a_text_not_void: a_text /= Void
do
!! Result.make (a_text, current_position)
ensure
identifier_not_void: Result /= Void
end
new_integer_constant (a_literal: STRING): ET_INTEGER_CONSTANT is
-- New integer constant with no underscore
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: [0-9]+
do
!ET_REGULAR_INTEGER_CONSTANT! Result.make (a_literal, current_position)
ensure
integer_constant_not_void: Result /= Void
end
new_manifest_string (a_literal: STRING): ET_MANIFEST_STRING is
-- New manifest string with no special character
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: \"[^"%\n]*\"
do
!ET_REGULAR_MANIFEST_STRING! Result.make (a_literal, current_position)
ensure
manifest_string_not_void: Result /= Void
end
new_real_constant (a_literal: STRING): ET_REAL_CONSTANT is
-- New real constant with no underscore
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: ([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([eE][+-]?[0-9]+)?
do
!ET_REGULAR_REAL_CONSTANT! Result.make (a_literal, current_position)
ensure
real_constant_not_void: Result /= Void
end
new_special_manifest_string (a_literal: STRING): ET_MANIFEST_STRING is
-- New manifest string with special characters
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: \"([^"%\n]|%([^\n]|\/[0-9]+\/|[ \t\r]*\n[ \t\r\n]*%))*\"
do
!ET_SPECIAL_MANIFEST_STRING! Result.make (a_literal, current_position)
ensure
manifest_string_not_void: Result /= Void
end
new_token (a_text: STRING): ET_TOKEN is
-- New token
require
a_text_not_void: a_text /= Void
do
!! Result.make (a_text, current_position)
ensure
token_not_void: Result /= Void
end
new_true_constant: ET_TRUE_CONSTANT is
-- New True constant
do
!! Result.make (current_position)
ensure
true_constant_not_void: Result /= Void
end
new_underscored_integer_constant (a_literal: STRING): ET_INTEGER_CONSTANT is
-- New integer constant with underscores
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: (_*[0-9]+_*)+
do
!ET_UNDERSCORED_INTEGER_CONSTANT! Result.make (a_literal, current_position)
ensure
integer_constant_not_void: Result /= Void
end
new_underscored_real_constant (a_literal: STRING): ET_REAL_CONSTANT is
-- New real constant with underscores
require
a_literal_not_void: a_literal /= Void
-- valid_literal: regexp: ((_*[0-9]+_*)+\.(_*[0-9]_*)*|(_*[0-9]_*)*\.(_*[0-9]_*)+)([eE][+-]?(_*[0-9]_*)+)?
do
!ET_UNDERSCORED_REAL_CONSTANT! Result.make (a_literal, current_position)
ensure
real_constant_not_void: Result /= Void
end
feature {NONE} -- Implementation
ms_line, ms_column: INTEGER
-- Line and column numbers of currently
-- scanned special manifest string
feature {NONE} -- Processing
process_one_character_symbol (a_token: INTEGER) is
-- Process Eiffel symbol made up of one character.
do
last_token := a_token
last_value := current_position
end
process_two_character_symbol (a_token: INTEGER) is
-- Process Eiffel symbol made up of two characters.
do
last_token := a_token
last_value := current_position
end
process_c2_character_constant (a_value: CHARACTER) is
-- Process character constant of the form '%A'.
do
last_token := E_CHARACTER
last_value := new_c2_character_constant ('%A')
end
process_lower_case_c2_character_constant (a_value: CHARACTER) is
-- Process character constant of the form '%a'.
do
-- Syntax error: special character specification
-- %l where l is a letter code should be in
-- upper-case in character constant.
column := column + 2
error_handler.report_SCCU_error (current_position)
column := column - 2
last_token := E_CHARACTER
last_value := new_c2_character_constant ('%A')
end
invariant
filename_not_void: filename /= Void
error_handler_not_void: error_handler /= Void
end -- class ET_EIFFEL_SCANNER_SKELETON
|