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 --- 304 unchanged lines hidden (view full) --- 313 p[0] = ast.EnumDeclAST(self, p[3], p[4], p[7]) 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_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 330 def p_type_member__0(self, p): 331 """type_member : obj_decl 332 | func_decl 333 | func_def""" 334 p[0] = p[1] 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" 343 p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3], None) 344 345 def p_obj_decl__1(self, p): 346 "obj_decl : type STAR ident pairs SEMI" 347 p[0] = ast.ObjDeclAST(self, p[1], p[3], p[4], None) 348 349 def p_obj_decl__2(self, p): 350 "obj_decl : type ident ASSIGN expr SEMI" 351 p[0] = ast.ObjDeclAST(self, p[1], p[2], ast.PairListAST(self), p[4]) 352 353 def p_obj_decl__3(self, p): 354 "obj_decl : type STAR ident ASSIGN expr SEMI" 355 p[0] = ast.ObjDeclAST(self, p[1], p[3], ast.PairListAST(self), p[5]) 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 364 | type ident '(' params ')' pairs SEMI""" 365 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None) 366 |
367 def p_func_decl__1(self, p): 368 """func_decl : void ident '(' types ')' pairs SEMI 369 | type ident '(' types ')' pairs SEMI""" 370 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None) 371 |
372 def p_decl__func_def(self, p): 373 "decl : func_def" 374 p[0] = p[1] 375 376 def p_func_def__0(self, p): 377 """func_def : void ident '(' params ')' pairs statements 378 | type ident '(' params ')' pairs statements""" 379 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7]) 380 |
381 # Enum fields 382 def p_type_enums__list(self, p): 383 "type_enums : type_enum type_enums" 384 p[0] = [ p[1] ] + p[2] 385 386 def p_type_enums__empty(self, p): 387 "type_enums : empty" 388 p[0] = [] --- 10 unchanged lines hidden (view full) --- 399 def p_type_states__empty(self, p): 400 "type_states : empty" 401 p[0] = [] 402 403 def p_type_state(self, p): 404 "type_state : ident ',' enumeration pairs SEMI" 405 p[0] = ast.TypeFieldStateAST(self, p[1], p[3], p[4]) 406 |
407 # Formal Param 408 def p_params__many(self, p): 409 "params : param ',' params" 410 p[0] = [ p[1] ] + p[3] 411 412 def p_params__one(self, p): 413 "params : param" 414 p[0] = [ p[1] ] --- 21 unchanged lines hidden (view full) --- 436 def p_param__default_bool(self, p): 437 "param : type ident '=' LIT_BOOL" 438 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4]) 439 440 def p_param__default_string(self, p): 441 "param : type ident '=' 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): 450 "types : type" 451 p[0] = [ p[1] ] 452 453 def p_types__empty(self, p): 454 "types : empty" 455 p[0] = [] 456 457 def p_typestr__multi(self, p): 458 "typestr : typestr DOUBLE_COLON ident" 459 p[0] = '%s::%s' % (p[1], p[3]) 460 461 def p_typestr__single(self, p): 462 "typestr : ident" 463 p[0] = p[1] 464 465 def p_type__one(self, p): 466 "type : typestr" 467 p[0] = ast.TypeAST(self, p[1]) 468 469 def p_void(self, p): 470 "void : VOID" 471 p[0] = ast.TypeAST(self, p[1]) 472 |
473 # Idents and lists 474 def p_idents__braced(self, p): 475 "idents : '{' identx '}'" 476 p[0] = p[2] 477 478 def p_idents__bare(self, p): 479 "idents : ident" 480 p[0] = [ p[1] ] --- 245 unchanged lines hidden --- |