parser.py (10307:6df951dcd7d9) parser.py (10308:8c0870dbae5c)
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 244 unchanged lines hidden (view full) ---

253 dirname = os.path.dirname(self.current_source)
254 if os.path.exists(os.path.join(dirname, p[2])):
255 filename = os.path.join(dirname, p[2])
256 else:
257 filename = os.path.join(self.base_dir, p[2])
258 p[0] = self.parse_file(filename)
259
260 def p_decl__machine0(self, p):
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 244 unchanged lines hidden (view full) ---

253 dirname = os.path.dirname(self.current_source)
254 if os.path.exists(os.path.join(dirname, p[2])):
255 filename = os.path.join(dirname, p[2])
256 else:
257 filename = os.path.join(self.base_dir, p[2])
258 p[0] = self.parse_file(filename)
259
260 def p_decl__machine0(self, p):
261 "decl : MACHINE '(' idents ')' ':' params '{' decls '}'"
261 "decl : MACHINE '(' idents ')' ':' obj_decls '{' decls '}'"
262 p[0] = ast.MachineAST(self, p[3], [], p[7], p[9])
263
264 def p_decl__machine1(self, p):
262 p[0] = ast.MachineAST(self, p[3], [], p[7], p[9])
263
264 def p_decl__machine1(self, p):
265 "decl : MACHINE '(' idents pairs ')' ':' params '{' decls '}'"
265 "decl : MACHINE '(' idents pairs ')' ':' obj_decls '{' decls '}'"
266 p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9])
267
268 def p_decl__action(self, p):
269 "decl : ACTION '(' ident pairs ')' statements"
270 p[0] = ast.ActionDeclAST(self, p[3], p[4], p[6])
271
272 def p_decl__in_port(self, p):
273 "decl : IN_PORT '(' ident ',' type ',' var pairs ')' statements"

--- 40 unchanged lines hidden (view full) ---

314
315 def p_decl__state_decl(self, p):
316 "decl : STATE_DECL '(' type pairs ')' '{' type_states '}'"
317 p[4]["enumeration"] = "yes"
318 p[4]["state_decl"] = "yes"
319 p[0] = ast.StateDeclAST(self, p[3], p[4], p[7])
320
321 # Type fields
266 p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9])
267
268 def p_decl__action(self, p):
269 "decl : ACTION '(' ident pairs ')' statements"
270 p[0] = ast.ActionDeclAST(self, p[3], p[4], p[6])
271
272 def p_decl__in_port(self, p):
273 "decl : IN_PORT '(' ident ',' type ',' var pairs ')' statements"

--- 40 unchanged lines hidden (view full) ---

314
315 def p_decl__state_decl(self, p):
316 "decl : STATE_DECL '(' type pairs ')' '{' type_states '}'"
317 p[4]["enumeration"] = "yes"
318 p[4]["state_decl"] = "yes"
319 p[0] = ast.StateDeclAST(self, p[3], p[4], p[7])
320
321 # Type fields
322 def p_obj_decls__list(self, p):
323 "obj_decls : obj_decl obj_decls"
324 p[0] = [ p[1] ] + p[2]
325
326 def p_obj_decls__empty(self, p):
327 "obj_decls : empty"
328 p[0] = []
329
322 def p_type_members__list(self, p):
323 "type_members : type_member type_members"
324 p[0] = [ p[1] ] + p[2]
325
326 def p_type_members__empty(self, p):
327 "type_members : empty"
328 p[0] = []
329

--- 5 unchanged lines hidden (view full) ---

335
336 # Member / Variable declarations
337 def p_decl__obj_decl(self, p):
338 "decl : obj_decl"
339 p[0] = p[1]
340
341 def p_obj_decl__0(self, p):
342 "obj_decl : type ident pairs SEMI"
330 def p_type_members__list(self, p):
331 "type_members : type_member type_members"
332 p[0] = [ p[1] ] + p[2]
333
334 def p_type_members__empty(self, p):
335 "type_members : empty"
336 p[0] = []
337

--- 5 unchanged lines hidden (view full) ---

343
344 # Member / Variable declarations
345 def p_decl__obj_decl(self, p):
346 "decl : obj_decl"
347 p[0] = p[1]
348
349 def p_obj_decl__0(self, p):
350 "obj_decl : type ident pairs SEMI"
343 p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3], None)
351 p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3], None, False)
344
345 def p_obj_decl__1(self, p):
346 "obj_decl : type STAR ident pairs SEMI"
352
353 def p_obj_decl__1(self, p):
354 "obj_decl : type STAR ident pairs SEMI"
347 p[0] = ast.ObjDeclAST(self, p[1], p[3], p[4], None)
355 p[0] = ast.ObjDeclAST(self, p[1], p[3], p[4], None, True)
348
349 def p_obj_decl__2(self, p):
350 "obj_decl : type ident ASSIGN expr SEMI"
356
357 def p_obj_decl__2(self, p):
358 "obj_decl : type ident ASSIGN expr SEMI"
351 p[0] = ast.ObjDeclAST(self, p[1], p[2], ast.PairListAST(self), p[4])
359 p[0] = ast.ObjDeclAST(self, p[1], p[2], ast.PairListAST(self), p[4],
360 False)
352
353 def p_obj_decl__3(self, p):
354 "obj_decl : type STAR ident ASSIGN expr SEMI"
361
362 def p_obj_decl__3(self, p):
363 "obj_decl : type STAR ident ASSIGN expr SEMI"
355 p[0] = ast.ObjDeclAST(self, p[1], p[3], ast.PairListAST(self), p[5])
364 p[0] = ast.ObjDeclAST(self, p[1], p[3], ast.PairListAST(self), p[5],
365 True)
356
357 # Function definition and declaration
358 def p_decl__func_decl(self, p):
359 "decl : func_decl"
360 p[0] = p[1]
361
362 def p_func_decl__0(self, p):
363 """func_decl : void ident '(' params ')' pairs SEMI

--- 57 unchanged lines hidden (view full) ---

421 "param : type ident"
422 p[0] = ast.FormalParamAST(self, p[1], p[2])
423
424 def p_param__pointer(self, p):
425 "param : type STAR ident"
426 p[0] = ast.FormalParamAST(self, p[1], p[3], None, True)
427
428 def p_param__pointer_default(self, p):
366
367 # Function definition and declaration
368 def p_decl__func_decl(self, p):
369 "decl : func_decl"
370 p[0] = p[1]
371
372 def p_func_decl__0(self, p):
373 """func_decl : void ident '(' params ')' pairs SEMI

--- 57 unchanged lines hidden (view full) ---

431 "param : type ident"
432 p[0] = ast.FormalParamAST(self, p[1], p[2])
433
434 def p_param__pointer(self, p):
435 "param : type STAR ident"
436 p[0] = ast.FormalParamAST(self, p[1], p[3], None, True)
437
438 def p_param__pointer_default(self, p):
429 "param : type STAR ident '=' STRING"
439 "param : type STAR ident ASSIGN STRING"
430 p[0] = ast.FormalParamAST(self, p[1], p[3], p[5], True)
431
432 def p_param__default_number(self, p):
440 p[0] = ast.FormalParamAST(self, p[1], p[3], p[5], True)
441
442 def p_param__default_number(self, p):
433 "param : type ident '=' NUMBER"
443 "param : type ident ASSIGN NUMBER"
434 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
435
436 def p_param__default_bool(self, p):
444 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
445
446 def p_param__default_bool(self, p):
437 "param : type ident '=' LIT_BOOL"
447 "param : type ident ASSIGN LIT_BOOL"
438 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
439
440 def p_param__default_string(self, p):
448 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
449
450 def p_param__default_string(self, p):
441 "param : type ident '=' STRING"
451 "param : type ident ASSIGN STRING"
442 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
443
444 # Type
445 def p_types__multiple(self, p):
446 "types : type ',' types"
447 p[0] = [ p[1] ] + p[3]
448
449 def p_types__one(self, p):

--- 276 unchanged lines hidden ---
452 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
453
454 # Type
455 def p_types__multiple(self, p):
456 "types : type ',' types"
457 p[0] = [ p[1] ] + p[3]
458
459 def p_types__one(self, p):

--- 276 unchanged lines hidden ---