| 1 |
(* mcLexBuf.def provides a buffer for the all the tokens created by m2.lex. |
| 2 |
|
| 3 |
Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
DEFINITION MODULE mcLexBuf ; |
| 23 |
|
| 24 |
|
| 25 |
FROM SYSTEM IMPORT ADDRESS ; |
| 26 |
FROM mcReserved IMPORT toktype ; |
| 27 |
FROM DynamicStrings IMPORT String ; |
| 28 |
FROM mcComment IMPORT commentDesc ; |
| 29 |
|
| 30 |
|
| 31 |
VAR |
| 32 |
currenttoken : toktype ; |
| 33 |
currentstring : ADDRESS ; |
| 34 |
currentcolumn : CARDINAL ; |
| 35 |
currentinteger: INTEGER ; |
| 36 |
lastcomment, |
| 37 |
currentcomment: commentDesc ; |
| 38 |
|
| 39 |
|
| 40 |
(* |
| 41 |
getProcedureComment - returns the procedure comment if it exists, |
| 42 |
or NIL otherwise. |
| 43 |
*) |
| 44 |
|
| 45 |
PROCEDURE getProcedureComment () : commentDesc ; |
| 46 |
|
| 47 |
|
| 48 |
(* |
| 49 |
getBodyComment - returns the body comment if it exists, |
| 50 |
or NIL otherwise. |
| 51 |
*) |
| 52 |
|
| 53 |
PROCEDURE getBodyComment () : commentDesc ; |
| 54 |
|
| 55 |
|
| 56 |
(* |
| 57 |
getAfterComment - returns the after comment if it exists, |
| 58 |
or NIL otherwise. |
| 59 |
*) |
| 60 |
|
| 61 |
PROCEDURE getAfterComment () : commentDesc ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
openSource - Attempts to open the source file, s. |
| 66 |
The success of the operation is returned. |
| 67 |
*) |
| 68 |
|
| 69 |
PROCEDURE openSource (s: String) : BOOLEAN ; |
| 70 |
|
| 71 |
|
| 72 |
(* |
| 73 |
closeSource - closes the current open file. |
| 74 |
*) |
| 75 |
|
| 76 |
PROCEDURE closeSource ; |
| 77 |
|
| 78 |
|
| 79 |
(* |
| 80 |
reInitialize - re-initialize the all the data structures. |
| 81 |
*) |
| 82 |
|
| 83 |
PROCEDURE reInitialize ; |
| 84 |
|
| 85 |
|
| 86 |
(* |
| 87 |
resetForNewPass - reset the buffer pointers to the beginning ready for |
| 88 |
a new pass |
| 89 |
*) |
| 90 |
|
| 91 |
PROCEDURE resetForNewPass ; |
| 92 |
|
| 93 |
|
| 94 |
(* |
| 95 |
getToken - gets the next token into currenttoken. |
| 96 |
*) |
| 97 |
|
| 98 |
PROCEDURE getToken ; |
| 99 |
|
| 100 |
|
| 101 |
(* |
| 102 |
insertToken - inserts a symbol, token, infront of the current token |
| 103 |
ready for the next pass. |
| 104 |
*) |
| 105 |
|
| 106 |
PROCEDURE insertToken (token: toktype) ; |
| 107 |
|
| 108 |
|
| 109 |
(* |
| 110 |
insertTokenAndRewind - inserts a symbol, token, infront of the current token |
| 111 |
and then moves the token stream back onto the inserted token. |
| 112 |
*) |
| 113 |
|
| 114 |
PROCEDURE insertTokenAndRewind (token: toktype) ; |
| 115 |
|
| 116 |
|
| 117 |
(* |
| 118 |
getPreviousTokenLineNo - returns the line number of the previous token. |
| 119 |
*) |
| 120 |
|
| 121 |
PROCEDURE getPreviousTokenLineNo () : CARDINAL ; |
| 122 |
|
| 123 |
|
| 124 |
(* |
| 125 |
getLineNo - returns the current line number where the symbol occurs in |
| 126 |
the source file. |
| 127 |
*) |
| 128 |
|
| 129 |
PROCEDURE getLineNo () : CARDINAL ; |
| 130 |
|
| 131 |
|
| 132 |
(* |
| 133 |
getTokenNo - returns the current token number. |
| 134 |
*) |
| 135 |
|
| 136 |
PROCEDURE getTokenNo () : CARDINAL ; |
| 137 |
|
| 138 |
|
| 139 |
(* |
| 140 |
tokenToLineNo - returns the line number of the current file for the |
| 141 |
TokenNo. The depth refers to the include depth. |
| 142 |
A depth of 0 is the current file, depth of 1 is the file |
| 143 |
which included the current file. Zero is returned if the |
| 144 |
depth exceeds the file nesting level. |
| 145 |
*) |
| 146 |
|
| 147 |
PROCEDURE tokenToLineNo (tokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ; |
| 148 |
|
| 149 |
|
| 150 |
(* |
| 151 |
getColumnNo - returns the current column where the symbol occurs in |
| 152 |
the source file. |
| 153 |
*) |
| 154 |
|
| 155 |
PROCEDURE getColumnNo () : CARDINAL ; |
| 156 |
|
| 157 |
|
| 158 |
(* |
| 159 |
tokenToColumnNo - returns the column number of the current file for the |
| 160 |
TokenNo. The depth refers to the include depth. |
| 161 |
A depth of 0 is the current file, depth of 1 is the file |
| 162 |
which included the current file. Zero is returned if the |
| 163 |
depth exceeds the file nesting level. |
| 164 |
*) |
| 165 |
|
| 166 |
PROCEDURE tokenToColumnNo (tokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ; |
| 167 |
|
| 168 |
|
| 169 |
(* |
| 170 |
findFileNameFromToken - returns the complete FileName for the appropriate |
| 171 |
source file yields the token number, TokenNo. |
| 172 |
The, Depth, indicates the include level: 0..n |
| 173 |
Level 0 is the current. NIL is returned if n+1 |
| 174 |
is requested. |
| 175 |
*) |
| 176 |
|
| 177 |
PROCEDURE findFileNameFromToken (tokenNo: CARDINAL; depth: CARDINAL) : String ; |
| 178 |
|
| 179 |
|
| 180 |
(* |
| 181 |
getFileName - returns a String defining the current file. |
| 182 |
*) |
| 183 |
|
| 184 |
PROCEDURE getFileName () : String ; |
| 185 |
|
| 186 |
|
| 187 |
(* *********************************************************************** |
| 188 |
* |
| 189 |
* These functions allow m2.lex to deliver tokens into the buffer |
| 190 |
* |
| 191 |
************************************************************************* *) |
| 192 |
|
| 193 |
(* |
| 194 |
addTok - adds a token to the buffer. |
| 195 |
*) |
| 196 |
|
| 197 |
PROCEDURE addTok (t: toktype) ; |
| 198 |
|
| 199 |
|
| 200 |
(* |
| 201 |
addTokCharStar - adds a token to the buffer and an additional string, s. |
| 202 |
A copy of string, s, is made. |
| 203 |
*) |
| 204 |
|
| 205 |
PROCEDURE addTokCharStar (t: toktype; s: ADDRESS) ; |
| 206 |
|
| 207 |
|
| 208 |
(* |
| 209 |
addTokInteger - adds a token and an integer to the buffer. |
| 210 |
*) |
| 211 |
|
| 212 |
PROCEDURE addTokInteger (t: toktype; i: INTEGER) ; |
| 213 |
|
| 214 |
|
| 215 |
(* |
| 216 |
addTokComment - adds a token to the buffer and a comment descriptor, com. |
| 217 |
*) |
| 218 |
|
| 219 |
PROCEDURE addTokComment (t: toktype; com: commentDesc) ; |
| 220 |
|
| 221 |
|
| 222 |
(* |
| 223 |
setFile - sets the current filename to, filename. |
| 224 |
*) |
| 225 |
|
| 226 |
PROCEDURE setFile (filename: ADDRESS) ; |
| 227 |
|
| 228 |
|
| 229 |
(* |
| 230 |
pushFile - indicates that, filename, has just been included. |
| 231 |
*) |
| 232 |
|
| 233 |
PROCEDURE pushFile (filename: ADDRESS) ; |
| 234 |
|
| 235 |
|
| 236 |
(* |
| 237 |
popFile - indicates that we are returning to, filename, having finished |
| 238 |
an include. |
| 239 |
*) |
| 240 |
|
| 241 |
PROCEDURE popFile (filename: ADDRESS) ; |
| 242 |
|
| 243 |
|
| 244 |
END mcLexBuf. |