Changeset 51d4040 in mainline for contrib/arch/hadlbppp.py
- Timestamp:
- 2009-09-16T23:22:20Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1fb1d1
- Parents:
- cf7b3e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/arch/hadlbppp.py
rcf7b3e0 r51d4040 35 35 36 36 # TODO: 37 # - alternative token38 # - iface protocol repetition39 37 # - interface inheritance 40 38 … … 130 128 return True 131 129 132 def preproc_bp(name, tokens):130 def tentative_bp(name, tokens): 133 131 "Preprocess tentative statements in Behavior Protocol" 134 132 … … 153 151 if (level == 0): 154 152 result.append("(") 155 result.extend( preproc_bp(name, tokens[start:(i - 1)]))153 result.extend(tentative_bp(name, tokens[start:(i - 1)])) 156 154 result.append(")") 157 155 result.append("+") … … 162 160 print "%s: Syntax error in tentative statement" % name 163 161 else: 164 print "%s: Unexpected token intentative statement" % name162 print "%s: Expected '{' for tentative statement" % name 165 163 else: 166 164 result.append(tokens[i]) … … 170 168 return result 171 169 170 def alternative_bp(name, tokens): 171 "Preprocess alternative statements in Behavior Protocol" 172 173 result = [] 174 i = 0 175 176 while (i < len(tokens)): 177 if (tokens[i] == "alternative"): 178 if ((i + 1 < len(tokens)) and (tokens[i + 1] == "(")): 179 i += 2 180 reps = [] 181 182 while ((i < len(tokens)) and (tokens[i] != ")")): 183 reps.append(tokens[i]) 184 if ((i + 1 < len(tokens)) and (tokens[i + 1] == ";")): 185 i += 2 186 else: 187 i += 1 188 189 if (len(reps) >= 2): 190 if ((i + 1 < len(tokens)) and (tokens[i + 1] == "{")): 191 i += 2 192 193 start = i 194 level = 1 195 196 while ((i < len(tokens)) and (level > 0)): 197 if (tokens[i] == "{"): 198 level += 1 199 elif (tokens[i] == "}"): 200 level -= 1 201 202 i += 1 203 204 if (level == 0): 205 first = True 206 207 for rep in reps[1:]: 208 retokens = [] 209 for token in tokens[start:(i - 1)]: 210 parts = token.split(".") 211 if ((len(parts) == 2) and (parts[0] == reps[0])): 212 retokens.append("%s.%s" % (rep, parts[1])) 213 else: 214 retokens.append(token) 215 216 if (first): 217 first = False 218 else: 219 result.append("+") 220 221 result.append("(") 222 result.extend(alternative_bp(name, retokens)) 223 result.append(")") 224 225 if (i < len(tokens)): 226 result.append(tokens[i]) 227 else: 228 print "%s: Syntax error in alternative statement" % name 229 else: 230 print "%s: Expected '{' for alternative statement body" % name 231 else: 232 print "%s: At least one pattern and one replacement required for alternative statement" % name 233 else: 234 print "%s: Expected '(' for alternative statement head" % name 235 else: 236 result.append(tokens[i]) 237 238 i += 1 239 240 return result 241 172 242 def split_bp(protocol): 173 243 "Convert Behavior Protocol to tokens" … … 176 246 177 247 def extend_bp(name, tokens, iface): 178 " Add interface to incoming messages"179 180 result = [ ]248 "Convert interface Behavior Protocol to generic protocol" 249 250 result = ["("] 181 251 i = 0 182 252 … … 198 268 i += 1 199 269 270 result.append(")") 271 result.append("*") 272 200 273 return result 201 274 … … 227 300 "Parse Behavior Protocol" 228 301 229 tokens = preproc_bp(name, tokens) 302 tokens = tentative_bp(name, tokens) 303 tokens = alternative_bp(name, tokens) 230 304 231 305 indent = base_indent
Note:
See TracChangeset
for help on using the changeset viewer.