Best Python code snippet using avocado_python
parser.py
Source:parser.py  
...16class Node(object):17    def __init__(self, data):18        self.data = data19        self.children = []20    def add_child(self, obj):21        self.children.append(obj)22i = 023f = open('parse_tree.dot','wb')24f.write('strict digraph graphname {\n\n0 [label="program"]\n')25def print_all(n):26	global i27	global f28	ni = i29	i = i+130	for c in n.children:31		a = '{} {} {} {} \n'.format(i,'[label="',c.data,'"];')32		f.write(a)33		a = '{} {} {} {} \n'.format(ni,'->',i,';')34		f.write(a)35		print_all(c)36def p_program_1(t):37	'program : statements'38	n = Node('program')39	n.add_child(t[1])40	t[0] = n41	print n.data42	print_all(n)43	f.write('\n\n}')44	f.close()45	pass46def p_statements_1(t):47	'statements : statements statement'48	n = Node('statements1')49	n.add_child(t[1])50	n.add_child(t[2])51	t[0] = n52	pass53def p_statements_2(t):54	'statements : statement'55	n = Node('statements2')56	n.add_child(t[1])57	t[0] = n58	pass59def p_statement_1(t):60	'statement : declaration'61	n = Node('statement1')62	n.add_child(t[1])63	t[0] = n64	pass65def p_statement_2(t):66	'statement : exp SEMI_COLON'67	n = Node('statement2')68	n.add_child(t[1])69	n.add_child(Node(t[2]))70	t[0] = n71	pass72def p_statement_3(t):73	'statement : iterative_statement'74	n = Node('statement3')75	n.add_child(t[1])76	t[0] = n77	pass78def p_statement_4(t):79	'statement : function'80	n = Node('statement4')81	n.add_child(t[1])82	t[0] = n83	pass84def p_statement_5(t):85	'statement : constant_statement'86	n = Node('statement5')87	n.add_child(t[1])88	t[0] = n89	pass90def p_statement_6(t):91	'statement : conditional_statement'92	n = Node('statement6')93	n.add_child(t[1])94	t[0] = n95	pass96def p_statement_7(t):97	'statement : COMMENT'98	n = Node('statement7')99	n.add_child(Node(t[1]))100	t[0] = n101	pass102def p_constant_statement_1(t):103	'constant_statement : BREAK SEMI_COLON'104	n = Node('constant_statement1')105	n.add_child(Node(t[1]))106	n.add_child(Node(t[2]))107	t[0] = n108	pass109def p_constant_statement_2(t):110	'constant_statement : CONTINUE SEMI_COLON'111	n = Node('constant_statement2')112	n.add_child(Node(t[1]))113	n.add_child(Node(t[2]))114	t[0] = n115	pass116def p_constant_statement_3(t):117	'constant_statement : RETURN SEMI_COLON'118	n = Node('constant_statement3')119	n.add_child(Node(t[1]))120	n.add_child(Node(t[2]))121	t[0] = n122	pass123def p_constant_statement_4(t):124	'constant_statement : RETURN exp SEMI_COLON'125	n = Node('constant_statement4')126	n.add_child(Node(t[1]))127	n.add_child(t[2])128	n.add_child(Node(t[3]))129	t[0] = n130	pass131def p_declaration_1(t):132	'declaration : type enum_list SEMI_COLON'133	n = Node('declaration1')134	n.add_child(t[1])135	n.add_child(t[2])136	n.add_child(Node(t[3]))137	t[0] = n138	pass139def p_enum_list_1(t):140	'enum_list : VARIABLE COMMA enum_list'141	n = Node('enum_list1')142	n.add_child(Node(t[1]))143	n.add_child(Node(t[2]))144	n.add_child(t[3])145	t[0] = n146	pass147def p_enum_list_2(t):148	'enum_list : VARIABLE EQUALS exp COMMA enum_list'149	n = Node('enum_list2')150	n.add_child(Node(t[1]))151	n.add_child(Node(t[2]))152	n.add_child(t[3])153	n.add_child(Node(t[4]))154	n.add_child(t[5])155	t[0] = n156	pass157def p_enum_list_3(t):158	'enum_list : VARIABLE'159	n = Node('enum_list3')160	n.add_child(Node(t[1]))161	t[0] = n162	pass163def p_enum_list_4(t):164	'enum_list : VARIABLE EQUALS exp'165	n = Node('enum_list4')166	n.add_child(Node(t[1]))167	n.add_child(Node(t[2]))168	n.add_child(t[3])169	t[0] = n170	pass171def p_enum_list_5(t):172	'enum_list : array COMMA enum_list'173	n = Node('enum_list5')174	n.add_child(t[1])175	n.add_child(Node(t[2]))176	n.add_child(t[3])177	t[0] = n178	pass179def p_enum_list_6(t):180	'enum_list : array EQUALS LBRACE num_list RBRACE COMMA enum_list'181	n = Node('enum_list6')182	n.add_child(t[1])183	n.add_child(Node(t[2]))184	n.add_child(Node(t[3]))185	n.add_child(t[4])186	n.add_child(Node(t[5]))187	n.add_child(Node(t[6]))188	n.add_child(t[7])189	t[0] = n190	pass191def p_enum_list_7(t):192	'enum_list : array'193	n = Node('enum_list7')194	n.add_child(t[1])195	t[0] = n196	pass197def p_enum_list_8(t):198	'enum_list : array EQUALS LBRACE num_list RBRACE'199	n = Node('enum_list8')200	n.add_child(t[1])201	n.add_child(Node(t[2]))202	n.add_child(Node(t[3]))203	n.add_child(t[4])204	n.add_child(Node(t[5]))205	t[0] = n206	pass207def p_array_1(t):208	'array : VARIABLE LBIG exp RBIG'209	n = Node('array')210	n.add_child(Node(t[1]))211	n.add_child(Node(t[2]))212	n.add_child(t[3])213	n.add_child(Node(t[4]))214	t[0] = n215	pass216def p_num_list_1(t):217	'num_list : exp COMMA num_list'218	n = Node('num_list1')219	n.add_child(t[1])220	n.add_child(Node(t[2]))221	n.add_child(t[3])222	t[0] = n223	pass224def p_num_list_2(t):225	'num_list : exp'226	n = Node('num_list1')227	n.add_child(t[1])228	t[0] = n229	pass230def p_type_1(t):231	'type : INT'232	n = Node('type1')233	n.add_child(Node(t[1]))234	t[0] = n235	pass236def p_type_2(t):237	'type : FLOAT'238	n = Node('type2')239	n.add_child(Node(t[1]))240	t[0] = n241	pass242def p_type_3(t):243	'type : CHAR'244	n = Node('type3')245	n.add_child(Node(t[1]))246	t[0] = n247	pass248def p_type_4(t):249	'type : DOUBLE'250	n = Node('type4')251	n.add_child(Node(t[1]))252	t[0] = n253	pass254def p_type_5(t):255	'type : VOID'256	n = Node('type5')257	n.add_child(Node(t[1]))258	t[0] = n259	pass260def p_type_6(t):261	'type : SHORT'262	n = Node('type6')263	n.add_child(Node(t[1]))264	t[0] = n265	pass266def p_type_7(t):267	'type : LONG'268	n = Node('type7')269	n.add_child(Node(t[1]))270	t[0] = n271	pass272def p_constant_1(t):273	'constant : HEX_INT'274	n = Node('constant1')275	n.add_child(Node(t[1]))276	t[0] = n277	pass278def p_constant_2(t):279	'constant : DOT_REAL'280	n = Node('constant2')281	n.add_child(Node(t[1]))282	t[0] = n283	pass284def p_constant_3(t):285	'constant : EXP_REAL'286	n = Node('constant3')287	n.add_child(Node(t[1]))288	t[0] = n289	pass290def p_constant_4(t):291	'constant : DEC_INT'292	n = Node('constant4')293	n.add_child(Node(t[1]))294	t[0] = n295	pass296def p_constant_5(t):297	'constant : CHARACTER'298	n = Node('constant5')299	n.add_child(Node(t[1]))300	t[0] = n301	pass302def p_exp_1(t):303	'exp : exp ADD exp'304	n = Node('exp1')305	n.add_child(t[1])306	n.add_child(Node(t[2]))307	n.add_child(t[3])308	t[0] = n309	pass310def p_exp_2(t):311	'exp : exp MINUS exp'312	n = Node('exp2')313	n.add_child(t[1])314	n.add_child(Node(t[2]))315	n.add_child(t[3])316	t[0] = n317	pass318def p_exp_3(t):319	'exp : exp MULT exp'320	n = Node('exp3')321	n.add_child(t[1])322	n.add_child(Node(t[2]))323	n.add_child(t[3])324	t[0] = n325	pass326def p_exp_4(t):327	'exp : exp DIV exp'328	n = Node('exp4')329	n.add_child(t[1])330	n.add_child(Node(t[2]))331	n.add_child(t[3])332	t[0] = n333	pass334def p_exp_5(t):335	'exp : exp MOD exp'336	n = Node('exp5')337	n.add_child(t[1])338	n.add_child(Node(t[2]))339	n.add_child(t[3])340	t[0] = n341	pass342def p_exp_6(t):343	'exp : exp L_OP exp'344	n = Node('exp6')345	n.add_child(t[1])346	n.add_child(Node(t[2]))347	n.add_child(t[3])348	t[0] = n349	pass350def p_exp_7(t):351	'exp : exp G_OP exp'352	n = Node('exp7')353	n.add_child(t[1])354	n.add_child(Node(t[2]))355	n.add_child(t[3])356	t[0] = n357	pass358def p_exp_8(t):359	'exp : exp LE_OP exp'360	n = Node('exp8')361	n.add_child(t[1])362	n.add_child(Node(t[2]))363	n.add_child(t[3])364	t[0] = n365	pass366def p_exp_9(t):367	'exp : exp GE_OP exp'368	n = Node('exp9')369	n.add_child(t[1])370	n.add_child(Node(t[2]))371	n.add_child(t[3])372	t[0] = n373	pass374def p_exp_10(t):375	'exp : exp NOTEQUALS exp'376	n = Node('exp10')377	n.add_child(t[1])378	n.add_child(Node(t[2]))379	n.add_child(t[3])380	t[0] = n381	pass382def p_exp_11(t):383	'exp : exp EQUALS_OP exp'384	n = Node('exp11')385	n.add_child(t[1])386	n.add_child(Node(t[2]))387	n.add_child(t[3])388	t[0] = n389	pass390def p_exp_12(t):391	'exp : exp OR_OP exp'392	n = Node('exp12')393	n.add_child(t[1])394	n.add_child(Node(t[2]))395	n.add_child(t[3])396	t[0] = n397	pass398def p_exp_13(t):399	'exp : exp AND_OP exp'400	n = Node('exp13')401	n.add_child(t[1])402	n.add_child(Node(t[2]))403	n.add_child(t[3])404	t[0] = n405	pass406def p_exp_14(t):407	'exp : exp MUL_ASSIGN exp'408	n = Node('exp14')409	n.add_child(t[1])410	n.add_child(Node(t[2]))411	n.add_child(t[3])412	t[0] = n413	pass414def p_exp_15(t):415	'exp : exp DIV_ASSIGN exp'416	n = Node('exp15')417	n.add_child(t[1])418	n.add_child(Node(t[2]))419	n.add_child(t[3])420	t[0] = n421	pass422def p_exp_16(t):423	'exp : exp MOD_ASSIGN exp'424	n = Node('exp16')425	n.add_child(t[1])426	n.add_child(Node(t[2]))427	n.add_child(t[3])428	t[0] = n429	pass430def p_exp_17(t):431	'exp : exp ADD_ASSIGN exp'432	n = Node('exp17')433	n.add_child(t[1])434	n.add_child(Node(t[2]))435	n.add_child(t[3])436	t[0] = n437	pass438def p_exp_18(t):439	'exp : exp SUB_ASSIGN exp'440	n = Node('exp18')441	n.add_child(t[1])442	n.add_child(Node(t[2]))443	n.add_child(t[3])444	t[0] = n445	pass446def p_exp_19(t):447	'exp : exp LEFT_ASSIGN exp'448	n = Node('exp19')449	n.add_child(t[1])450	n.add_child(Node(t[2]))451	n.add_child(t[3])452	t[0] = n453	pass454def p_exp_20(t):455	'exp : exp RIGHT_ASSIGN exp'456	n = Node('exp20')457	n.add_child(t[1])458	n.add_child(Node(t[2]))459	n.add_child(t[3])460	t[0] = n461	pass462def p_exp_21(t):463	'exp : exp AND_ASSIGN exp'464	n = Node('exp21')465	n.add_child(t[1])466	n.add_child(Node(t[2]))467	n.add_child(t[3])468	t[0] = n469	pass470def p_exp_22(t):471	'exp : exp XOR_ASSIGN exp'472	n = Node('exp22')473	n.add_child(t[1])474	n.add_child(Node(t[2]))475	n.add_child(t[3])476	t[0] = n477	pass478def p_exp_23(t):479	'exp : exp OR_ASSIGN exp'480	n = Node('exp23')481	n.add_child(t[1])482	n.add_child(Node(t[2]))483	n.add_child(t[3])484	t[0] = n485	pass486def p_exp_24(t):487	'exp : exp EQUALS exp'488	n = Node('exp24')489	n.add_child(t[1])490	n.add_child(Node(t[2]))491	n.add_child(t[3])492	t[0] = n493	pass494def p_exp_25(t):495	'exp : unary_expression'496	n = Node('exp25')497	n.add_child(t[1])498	t[0] = n499	pass500def p_exp_26(t):501	'exp : LPAREN exp RPAREN'502	n = Node('exp26')503	n.add_child(Node(t[1]))504	n.add_child(t[2])505	n.add_child(Node(t[3]))506	t[0] = n507	pass508def p_exp_27(t):509	'exp : constant'510	n = Node('exp27')511	n.add_child(t[1])512	t[0] = n513	pass514def p_exp_28(t):515	'exp : VARIABLE'516	n = Node('exp28')517	n.add_child(Node(t[1]))518	t[0] = n519	pass520def p_exp_29(t):521	'exp : array'522	n = Node('exp29')523	n.add_child(t[1])524	t[0] = n525	pass526def p_exp_30(t):527	'exp : function_call'528	n = Node('exp30')529	n.add_child(t[1])530	t[0] = n531	pass532def p_unary_expression_1(t):533	'unary_expression : VARIABLE unary_operator'534	n = Node('unary_expression1')535	n.add_child(Node(t[1]))536	n.add_child(t[2])537	t[0] = n538	pass539def p_unary_expression_2(t):540	'unary_expression : unary_operator VARIABLE'541	n = Node('unary_expression2')542	n.add_child(t[1])543	n.add_child(Node(t[2]))544	t[0] = n545	pass546def p_unary_expression_3(t):547	'unary_expression : array unary_operator'548	n = Node('unary_expression3')549	n.add_child(t[1])550	n.add_child(t[2])551	t[0] = n552	pass553def p_unary_expression_4(t):554	'unary_expression : unary_operator array'555	n = Node('unary_expression4')556	n.add_child(t[1])557	n.add_child(t[2])558	t[0] = n559	pass560def p_unary_operator_1(t):561	'unary_operator : INCREMENT'562	n = Node('unary_operator1')563	n.add_child(Node(t[1]))564	t[0] = n565	pass566def p_unary_operator_2(t):567	'unary_operator : DECREMENT'568	n = Node('unary_operator2')569	n.add_child(Node(t[1]))570	t[0] = n571	pass572def p_iterative_statement_1(t):573	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN statement'574	n = Node('iterative_statement1')575	n.add_child(Node(t[1]))576	n.add_child(Node(t[2]))577	n.add_child(t[3])578	n.add_child(Node(t[4]))579	n.add_child(t[5])580	n.add_child(Node(t[6]))581	n.add_child(t[7])582	n.add_child(Node(t[8]))583	n.add_child(t[9])584	t[0] = n585	pass586def p_iterative_statement_2(t):587	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN LBRACE statements RBRACE'588	n = Node('iterative_statement2')589	n.add_child(Node(t[1]))590	n.add_child(Node(t[2]))591	n.add_child(t[3])592	n.add_child(Node(t[4]))593	n.add_child(t[5])594	n.add_child(Node(t[6]))595	n.add_child(t[7])596	n.add_child(Node(t[8]))597	n.add_child(Node(t[9]))598	n.add_child(t[10])599	n.add_child(Node(t[11]))600	t[0] = n601	pass602def p_iterative_statement_3(t):603	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN SEMI_COLON'604	n = Node('iterative_statement3')605	n.add_child(Node(t[1]))606	n.add_child(Node(t[2]))607	n.add_child(t[3])608	n.add_child(Node(t[4]))609	n.add_child(t[5])610	n.add_child(Node(t[6]))611	n.add_child(t[7])612	n.add_child(Node(t[8]))613	n.add_child(Node(t[9]))614	t[0] = n615	pass616def p_iterative_statement_4(t):617	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN LBRACE RBRACE'618	n = Node('iterative_statement4')619	n.add_child(Node(t[1]))620	n.add_child(Node(t[2]))621	n.add_child(t[3])622	n.add_child(Node(t[4]))623	n.add_child(t[5])624	n.add_child(Node(t[6]))625	n.add_child(t[7])626	n.add_child(Node(t[8]))627	n.add_child(Node(t[9]))628	n.add_child(Node(t[10]))629	t[0] = n630	pass631def p_iterative_statement_5(t):632	'iterative_statement : WHILE LPAREN exp RPAREN statement'633	n = Node('iterative_statement5')634	n.add_child(Node(t[1]))635	n.add_child(Node(t[2]))636	n.add_child(t[3])637	n.add_child(Node(t[4]))638	n.add_child(t[5])639	t[0] = n640	pass641def p_iterative_statement_6(t):642	'iterative_statement : WHILE LPAREN exp RPAREN SEMI_COLON'643	n = Node('iterative_statement6')644	n.add_child(Node(t[1]))645	n.add_child(Node(t[2]))646	n.add_child(t[3])647	n.add_child(Node(t[4]))648	n.add_child(Node(t[5]))649	t[0] = n650	pass651def p_iterative_statement_7(t):652	'iterative_statement : WHILE LPAREN exp RPAREN LBRACE statements RBRACE'653	n = Node('iterative_statement7')654	n.add_child(Node(t[1]))655	n.add_child(Node(t[2]))656	n.add_child(t[3])657	n.add_child(Node(t[4]))658	n.add_child(Node(t[5]))659	n.add_child(t[6])660	n.add_child(Node(t[7]))661	t[0] = n662	pass663def p_iterative_statement_8(t):664	'iterative_statement : WHILE LPAREN exp RPAREN LBRACE RBRACE'665	n = Node('iterative_statement8')666	n.add_child(Node(t[1]))667	n.add_child(Node(t[2]))668	n.add_child(t[3])669	n.add_child(Node(t[4]))670	n.add_child(Node(t[5]))671	n.add_child(Node(t[6]))672	t[0] = n673	pass674def p_iterative_statement_9(t):675	'iterative_statement : DO statement WHILE LPAREN exp RPAREN SEMI_COLON'676	n = Node('iterative_statement9')677	n.add_child(Node(t[1]))678	n.add_child(t[2])679	n.add_child(Node(t[3]))680	n.add_child(Node(t[4]))681	n.add_child(t[5])682	n.add_child(Node(t[6]))683	n.add_child(Node(t[7]))684	t[0] = n685	pass686def p_iterative_statement_10(t):687	'iterative_statement : DO LBRACE statements RBRACE WHILE LPAREN exp RPAREN SEMI_COLON'688	n = Node('iterative_statement10')689	n.add_child(Node(t[1]))690	n.add_child(Node(t[2]))691	n.add_child(t[3])692	n.add_child(Node(t[4]))693	n.add_child(Node(t[5]))694	n.add_child(Node(t[6]))695	n.add_child(t[7])696	n.add_child(Node(t[8]))697	n.add_child(Node(t[9]))698	t[0] = n699	pass700def p_iterative_statement_11(t):701	'iterative_statement : DO SEMI_COLON WHILE LPAREN exp RPAREN SEMI_COLON'702	n = Node('iterative_statement11')703	n.add_child(Node(t[1]))704	n.add_child(Node(t[2]))705	n.add_child(Node(t[3]))706	n.add_child(Node(t[4]))707	n.add_child(t[5])708	n.add_child(Node(t[6]))709	n.add_child(Node(t[7]))710	t[0] = n711	pass712def p_iterative_statement_12(t):713	'iterative_statement : DO LBRACE RBRACE WHILE LPAREN exp RPAREN SEMI_COLON'714	n = Node('iterative_statement12')715	n.add_child(Node(t[1]))716	n.add_child(Node(t[2]))717	n.add_child(Node(t[3]))718	n.add_child(Node(t[4]))719	n.add_child(Node(t[5]))720	n.add_child(t[6])721	n.add_child(Node(t[7]))722	n.add_child(Node(t[8]))723	t[0] = n724	pass725def p_iterative_exp_1(t):726	'iterative_exp : exp COMMA iterative_exp'727	n = Node('iterative_exp1')728	n.add_child(t[1])729	n.add_child(Node(t[2]))730	n.add_child(t[3])731	t[0] = n732	pass733def p_iterative_exp_2(t):734	'iterative_exp : exp'735	n = Node('iterative_exp2')736	n.add_child(t[1])737	t[0] = n738	pass739def p_conditional_statement_1(t):740	'conditional_statement : IF LPAREN exp RPAREN statement %prec UELSE'741	n = Node('conditional_statement1')742	n.add_child(Node(t[1]))743	n.add_child(Node(t[2]))744	n.add_child(t[3])745	n.add_child(Node(t[4]))746	n.add_child(t[5])747	t[0] = n748	pass749def p_conditional_statement_2(t):750	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE %prec UELSE'751	n = Node('conditional_statement2')752	n.add_child(Node(t[1]))753	n.add_child(Node(t[2]))754	n.add_child(t[3])755	n.add_child(Node(t[4]))756	n.add_child(Node(t[5]))757	n.add_child(t[6])758	n.add_child(Node(t[7]))759	t[0] = n760	pass761def p_conditional_statement_3(t):762	'conditional_statement : IF LPAREN exp RPAREN statement ELSE statement'763	n = Node('conditional_statement3')764	n.add_child(Node(t[1]))765	n.add_child(Node(t[2]))766	n.add_child(t[3])767	n.add_child(Node(t[4]))768	n.add_child(t[5])769	n.add_child(Node(t[6]))770	n.add_child(t[7])771	t[0] = n772	pass773def p_conditional_statement_4(t):774	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE ELSE statement'775	n = Node('conditional_statement4')776	n.add_child(Node(t[1]))777	n.add_child(Node(t[2]))778	n.add_child(t[3])779	n.add_child(Node(t[4]))780	n.add_child(Node(t[5]))781	n.add_child(t[6])782	n.add_child(Node(t[7]))783	n.add_child(Node(t[8]))784	n.add_child(t[9])785	t[0] = n786	pass787def p_conditional_statement_5(t):788	'conditional_statement : IF LPAREN exp RPAREN statement ELSE LBRACE statements RBRACE'789	n = Node('conditional_statement5')790	n.add_child(Node(t[1]))791	n.add_child(Node(t[2]))792	n.add_child(t[3])793	n.add_child(Node(t[4]))794	n.add_child(t[5])795	n.add_child(Node(t[6]))796	n.add_child(Node(t[7]))797	n.add_child(t[8])798	n.add_child(Node(t[9]))799	t[0] = n800	pass801def p_conditional_statement_6(t):802	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE ELSE LBRACE statements RBRACE'803	n = Node('conditional_statement6')804	n.add_child(Node(t[1]))805	n.add_child(Node(t[2]))806	n.add_child(t[3])807	n.add_child(Node(t[4]))808	n.add_child(Node(t[5]))809	n.add_child(t[6])810	n.add_child(Node(t[7]))811	n.add_child(Node(t[8]))812	n.add_child(Node(t[9]))813	n.add_child(t[10])814	n.add_child(Node(t[11]))815	t[0] = n816	pass817def p_function_1(t):818	'function : normal_function'819	n = Node('function1')820	n.add_child(t[1])821	t[0] = n822	pass823def p_function_2(t):824	'function : main_function'825	n = Node('function2')826	n.add_child(t[1])827	t[0] = n828	pass829def p_main_function_1(t):830	'main_function : type MAIN LPAREN parameters RPAREN LBRACE statements RBRACE'831	n = Node('main_function1')832	n.add_child(t[1])833	n.add_child(Node(t[2]))834	n.add_child(Node(t[3]))835	n.add_child(t[4])836	n.add_child(Node(t[5]))837	n.add_child(Node(t[6]))838	n.add_child(t[7])839	n.add_child(Node(t[8]))840	t[0] = n841	pass842def p_main_function_2(t):843	'main_function : type MAIN LPAREN parameters RPAREN LBRACE RBRACE'844	n = Node('main_function2')845	n.add_child(t[1])846	n.add_child(Node(t[2]))847	n.add_child(Node(t[3]))848	n.add_child(t[4])849	n.add_child(Node(t[5]))850	n.add_child(Node(t[6]))851	n.add_child(Node(t[7]))852	t[0] = n853	pass854def p_main_function_3(t):855	'main_function : MAIN LPAREN parameters RPAREN LBRACE statements RBRACE'856	n = Node('main_function3')857	n.add_child(Node("VOID"))858	n.add_child(Node(t[1]))859	n.add_child(Node(t[2]))860	n.add_child(t[3])861	n.add_child(Node(t[4]))862	n.add_child(Node(t[5]))863	n.add_child(t[6])864	n.add_child(Node(t[7]))865	t[0] = n866	pass867def p_main_function_4(t):868	'main_function : MAIN LPAREN parameters RPAREN LBRACE RBRACE'869	n = Node('main_function4')870	n.add_child(Node("VOID"))871	n.add_child(Node(t[1]))872	n.add_child(Node(t[2]))873	n.add_child(t[3])874	n.add_child(Node(t[4]))875	n.add_child(Node(t[5]))876	n.add_child(Node(t[6]))877	t[0] = n878	pass879def p_main_function_5(t):880	'main_function : type MAIN LPAREN RPAREN LBRACE statements RBRACE'881	n = Node('main_function5')882	n.add_child(t[1])883	n.add_child(Node(t[2]))884	n.add_child(Node(t[3]))885	n.add_child(Node(t[4]))886	n.add_child(Node(t[5]))887	n.add_child(t[6])888	n.add_child(Node(t[7]))889	t[0] = n890	pass891def p_main_function_6(t):892	'main_function : type MAIN LPAREN RPAREN LBRACE RBRACE'893	n = Node('main_function6')894	n.add_child(t[1])895	n.add_child(Node(t[2]))896	n.add_child(Node(t[3]))897	n.add_child(Node(t[4]))898	n.add_child(Node(t[5]))899	n.add_child(Node(t[6]))900	t[0] = n901	pass902def p_main_function_7(t):903	'main_function : MAIN LPAREN RPAREN LBRACE statements RBRACE'904	n = Node('main_function7')905	n.add_child(Node("VOID"))906	n.add_child(Node(t[1]))907	n.add_child(Node(t[2]))908	n.add_child(Node(t[3]))909	n.add_child(Node(t[4]))910	n.add_child(t[5])911	n.add_child(Node(t[6]))912	t[0] = n913	pass914def p_main_function_8(t):915	'main_function : MAIN LPAREN RPAREN LBRACE RBRACE'916	n = Node('main_function8')917	n.add_child(Node("VOID"))918	n.add_child(Node(t[1]))919	n.add_child(Node(t[2]))920	n.add_child(Node(t[3]))921	n.add_child(Node(t[4]))922	n.add_child(Node(t[5]))923	t[0] = n924	pass925def p_normal_function_1(t):926	'normal_function : type VARIABLE LPAREN parameters RPAREN LBRACE statements RBRACE'927	n = Node('normal_function1')928	n.add_child(t[1])929	n.add_child(Node(t[2]))930	n.add_child(Node(t[3]))931	n.add_child(t[4])932	n.add_child(Node(t[5]))933	n.add_child(Node(t[6]))934	n.add_child(t[7])935	n.add_child(Node(t[8]))936	t[0] = n937	pass938def p_normal_function_2(t):939	'normal_function : type VARIABLE LPAREN parameters RPAREN LBRACE RBRACE'940	n = Node('normal_function2')941	n.add_child(t[1])942	n.add_child(Node(t[2]))943	n.add_child(Node(t[3]))944	n.add_child(t[4])945	n.add_child(Node(t[5]))946	n.add_child(Node(t[6]))947	n.add_child(Node(t[7]))948	t[0] = n949	pass950def p_normal_function_3(t):951	'normal_function : VARIABLE LPAREN parameters RPAREN LBRACE statements RBRACE'952	n = Node('normal_function3')953	n.add_child(Node("VOID"))954	n.add_child(Node(t[1]))955	n.add_child(Node(t[2]))956	n.add_child(t[3])957	n.add_child(Node(t[4]))958	n.add_child(Node(t[5]))959	n.add_child(t[6])960	n.add_child(Node(t[7]))961	t[0] = n962	pass963def p_normal_function_4(t):964	'normal_function : VARIABLE LPAREN parameters RPAREN LBRACE RBRACE'965	n = Node('normal_function4')966	n.add_child(Node("VOID"))967	n.add_child(Node(t[1]))968	n.add_child(Node(t[2]))969	n.add_child(t[3])970	n.add_child(Node(t[4]))971	n.add_child(Node(t[5]))972	n.add_child(Node(t[6]))973	t[0] = n974	pass975def p_normal_function_5(t):976	'normal_function : type VARIABLE LPAREN RPAREN LBRACE statements RBRACE'977	n = Node('normal_function5')978	n.add_child(t[1])979	n.add_child(Node(t[2]))980	n.add_child(Node(t[3]))981	n.add_child(Node(t[4]))982	n.add_child(Node(t[5]))983	n.add_child(t[6])984	n.add_child(Node(t[7]))985	t[0] = n986	pass987def p_normal_function_6(t):988	'normal_function : type VARIABLE LPAREN RPAREN LBRACE RBRACE'989	n = Node('normal_function6')990	n.add_child(t[1])991	n.add_child(Node(t[2]))992	n.add_child(Node(t[3]))993	n.add_child(Node(t[4]))994	n.add_child(Node(t[5]))995	n.add_child(Node(t[6]))996	t[0] = n997	pass998def p_normal_function_7(t):999	'normal_function : VARIABLE LPAREN RPAREN LBRACE statements RBRACE'1000	n = Node('normal_function7')1001	n.add_child(Node("VOID"))1002	n.add_child(Node(t[1]))1003	n.add_child(Node(t[2]))1004	n.add_child(Node(t[3]))1005	n.add_child(Node(t[4]))1006	n.add_child(t[5])1007	n.add_child(Node(t[6]))1008	t[0] = n1009	pass1010def p_normal_function_8(t):1011	'normal_function : VARIABLE LPAREN RPAREN LBRACE RBRACE'1012	n = Node('normal_function8')1013	n.add_child(Node("VOID"))1014	n.add_child(Node(t[1]))1015	n.add_child(Node(t[2]))1016	n.add_child(Node(t[3]))1017	n.add_child(Node(t[4]))1018	n.add_child(Node(t[5]))1019	t[0] = n1020	pass1021def p_parameters_1(t):1022	'parameters : type VARIABLE COMMA parameters'1023	n = Node('parameters1')1024	n.add_child(t[1])1025	n.add_child(Node(t[2]))1026	n.add_child(Node(t[3]))1027	n.add_child(t[4])1028	t[0] = n1029	pass1030def p_parameters_2(t):1031	'parameters : type VARIABLE'1032	n = Node('parameters2')1033	n.add_child(t[1])1034	n.add_child(Node(t[2]))1035	t[0] = n1036	pass1037def p_function_call_1(t):1038	'function_call : VARIABLE LPAREN arguments RPAREN'1039	n = Node('function_call1')1040	n.add_child(Node(t[1]))1041	n.add_child(Node(t[2]))1042	n.add_child(t[3])1043	n.add_child(Node(t[4]))1044	t[0] = n1045	pass1046def p_function_call_2(t):1047	'function_call : VARIABLE LPAREN RPAREN'1048	n = Node('function_call2')1049	n.add_child(Node(t[1]))1050	n.add_child(Node(t[2]))1051	n.add_child(Node(t[3]))1052	t[0] = n1053	pass1054def p_arguments_1(t):1055	'arguments : arguments COMMA exp'1056	n = Node('arguments1')1057	n.add_child(t[1])1058	n.add_child(Node(t[2]))1059	n.add_child(t[3])1060	t[0] = n1061	pass1062def p_arguments_2(t):1063	'arguments : exp'1064	n = Node('arguments2')1065	n.add_child(t[1])1066	t[0] = n1067	pass 1068def p_empty(t):1069	'empty : '1070	t[0] = Node('empty')1071	pass1072def p_error(t):1073    print "ERROR"1074def parse():1075	f = open(sys.argv[1])1076	p = yacc.parse(f.read(), debug=1)1077	print p1078import profile1079parser = yacc.yacc()...AST.py
Source:AST.py  
...16class Node(object):17    def __init__(self, data):18        self.data = data19        self.children = []20    def add_child(self, obj):21        self.children.append(obj)22i = 023f = open('ast.dot','wb')24f.write('strict digraph graphname {\n\n0 [label="program"]\n')25def print_all(n):26	global i27	global f28	ni = i29	i = i+130	for c in n.children:31		a = '{} {} {} {} \n'.format(i,'[label="',c.data,'"];')32		f.write(a)33		a = '{} {} {} {} \n'.format(ni,'->',i,';')34		f.write(a)35		print_all(c)36def p_program_1(t):37	'program : statements'38	t[0] = t[1]39	print t[0].data40	print_all(t[0])41	f.write('\n\n}')42	f.close()43	pass44def p_statements_1(t):45	'statements : statements statement'46	n = Node('statements1')47	n.add_child(t[1])48	n.add_child(t[2])49	t[0] = n50	pass51def p_statements_2(t):52	'statements : statement'53	t[0] = t[1]54	pass55def p_statement_1(t):56	'statement : declaration'57	t[0] = t[1]58	pass59def p_statement_2(t):60	'statement : exp SEMI_COLON'61	n = Node('statement2')62	n.add_child(t[1])63	n.add_child(Node(t[2]))64	t[0] = n65	pass66def p_statement_3(t):67	'statement : iterative_statement'68	t[0] = t[1]69	pass70def p_statement_4(t):71	'statement : function'72	t[0] = t[1]73	pass74def p_statement_5(t):75	'statement : constant_statement'76	t[0] = t[1]77	pass78def p_statement_6(t):79	'statement : conditional_statement'80	t[0] = t[1]81	pass82def p_statement_7(t):83	'statement : COMMENT'84	t[0] = Node(t[1])85	pass86def p_constant_statement_1(t):87	'constant_statement : BREAK SEMI_COLON'88	n = Node('constant_statement1')89	n.add_child(Node(t[1]))90	n.add_child(Node(t[2]))91	t[0] = n92	pass93def p_constant_statement_2(t):94	'constant_statement : CONTINUE SEMI_COLON'95	n = Node('constant_statement2')96	n.add_child(Node(t[1]))97	n.add_child(Node(t[2]))98	t[0] = n99	pass100def p_constant_statement_3(t):101	'constant_statement : RETURN SEMI_COLON'102	n = Node('constant_statement3')103	n.add_child(Node(t[1]))104	n.add_child(Node(t[2]))105	t[0] = n106	pass107def p_constant_statement_4(t):108	'constant_statement : RETURN exp SEMI_COLON'109	n = Node('constant_statement4')110	n.add_child(Node(t[1]))111	n.add_child(t[2])112	n.add_child(Node(t[3]))113	t[0] = n114	pass115def p_declaration_1(t):116	'declaration : type enum_list SEMI_COLON'117	n = Node('declaration1')118	n.add_child(t[1])119	n.add_child(t[2])120	n.add_child(Node(t[3]))121	t[0] = n122	pass123def p_enum_list_1(t):124	'enum_list : VARIABLE COMMA enum_list'125	n = Node('enum_list1')126	n.add_child(Node(t[1]))127	n.add_child(Node(t[2]))128	n.add_child(t[3])129	t[0] = n130	pass131def p_enum_list_2(t):132	'enum_list : VARIABLE EQUALS exp COMMA enum_list'133	n = Node('enum_list2')134	x = Node(t[2])135	x.add_child(Node(t[1]))136	x.add_child(t[3])137	n.add_child(x)138	n.add_child(Node(t[4]))139	n.add_child(t[5])140	t[0] = n141	pass142def p_enum_list_3(t):143	'enum_list : VARIABLE'144	t[0] = Node(t[1])145	pass146def p_enum_list_4(t):147	'enum_list : VARIABLE EQUALS exp'148	n = Node(t[2])149	n.add_child(Node(t[1]))150	n.add_child(t[3])151	t[0] = n152	pass153def p_enum_list_5(t):154	'enum_list : array COMMA enum_list'155	n = Node('enum_list5')156	n.add_child(t[1])157	n.add_child(Node(t[2]))158	n.add_child(t[3])159	t[0] = n160	pass161def p_enum_list_6(t):162	'enum_list : array EQUALS LBRACE num_list RBRACE COMMA enum_list'163	n = Node('enum_list6')164	n.add_child(t[1])165	n.add_child(Node(t[2]))166	n.add_child(Node(t[3]))167	n.add_child(t[4])168	n.add_child(Node(t[5]))169	n.add_child(Node(t[6]))170	n.add_child(t[7])171	t[0] = n172	pass173def p_enum_list_7(t):174	'enum_list : array'175	t[0] = t[1]176	pass177def p_enum_list_8(t):178	'enum_list : array EQUALS LBRACE num_list RBRACE'179	n = Node('enum_list8')180	n.add_child(t[1])181	n.add_child(Node(t[2]))182	n.add_child(Node(t[3]))183	n.add_child(t[4])184	n.add_child(Node(t[5]))185	t[0] = n186	pass187def p_array_1(t):188	'array : VARIABLE LBIG exp RBIG'189	n = Node('array')190	n.add_child(Node(t[1]))191	n.add_child(Node(t[2]))192	n.add_child(t[3])193	n.add_child(Node(t[4]))194	t[0] = n195	pass196def p_num_list_1(t):197	'num_list : exp COMMA num_list'198	n = Node('num_list1')199	n.add_child(t[1])200	n.add_child(Node(t[2]))201	n.add_child(t[3])202	t[0] = n203	pass204def p_num_list_2(t):205	'num_list : exp'206	t[0] = t[1]207	pass208def p_type_1(t):209	'type : INT'210	t[0] = Node(t[1])211	pass212def p_type_2(t):213	'type : FLOAT'214	t[0] = Node(t[1])215	pass216def p_type_3(t):217	'type : CHAR'218	t[0] = Node(t[1])219	pass220def p_type_4(t):221	'type : DOUBLE'222	t[0] = Node(t[1])223	pass224def p_type_5(t):225	'type : VOID'226	t[0] = Node(t[1])227	pass228def p_type_6(t):229	'type : SHORT'230	t[0] = Node(t[1])231	pass232def p_type_7(t):233	'type : LONG'234	t[0] = Node(t[1])235	pass236def p_constant_1(t):237	'constant : HEX_INT'238	t[0] = Node(t[1])239	pass240def p_constant_2(t):241	'constant : DOT_REAL'242	t[0] = Node(t[1])243	pass244def p_constant_3(t):245	'constant : EXP_REAL'246	t[0] = Node(t[1])247	pass248def p_constant_4(t):249	'constant : DEC_INT'250	t[0] = Node(t[1])251	pass252def p_constant_5(t):253	'constant : CHARACTER'254	t[0] = Node(t[1])255	pass256def p_exp_1(t):257	'exp : exp ADD exp'258	n = Node(t[2])259	n.add_child(t[1])260	n.add_child(t[3])261	t[0] = n262	pass263def p_exp_2(t):264	'exp : exp MINUS exp'265	n = Node(t[2])266	n.add_child(t[1])267	n.add_child(t[3])268	t[0] = n269	pass270def p_exp_3(t):271	'exp : exp MULT exp'272	n = Node(t[2])273	n.add_child(t[1])274	n.add_child(t[3])275	t[0] = n276	pass277def p_exp_4(t):278	'exp : exp DIV exp'279	n = Node(t[2])280	n.add_child(t[1])281	n.add_child(t[3])282	t[0] = n283	pass284def p_exp_5(t):285	'exp : exp MOD exp'286	n = Node(t[2])287	n.add_child(t[1])288	n.add_child(t[3])289	t[0] = n290	pass291def p_exp_6(t):292	'exp : exp L_OP exp'293	n = Node(t[2])294	n.add_child(t[1])295	n.add_child(t[3])296	t[0] = n297	pass298def p_exp_7(t):299	'exp : exp G_OP exp'300	n = Node(t[2])301	n.add_child(t[1])302	n.add_child(t[3])303	t[0] = n304	pass305def p_exp_8(t):306	'exp : exp LE_OP exp'307	n = Node(t[2])308	n.add_child(t[1])309	n.add_child(t[3])310	t[0] = n311	pass312def p_exp_9(t):313	'exp : exp GE_OP exp'314	n = Node(t[2])315	n.add_child(t[1])316	n.add_child(t[3])317	t[0] = n318	pass319def p_exp_10(t):320	'exp : exp NOTEQUALS exp'321	n = Node(t[2])322	n.add_child(t[1])323	n.add_child(t[3])324	t[0] = n325	pass326def p_exp_11(t):327	'exp : exp EQUALS_OP exp'328	n = Node(t[2])329	n.add_child(t[1])330	n.add_child(t[3])331	t[0] = n332	pass333def p_exp_12(t):334	'exp : exp OR_OP exp'335	n = Node(t[2])336	n.add_child(t[1])337	n.add_child(t[3])338	t[0] = n339	pass340def p_exp_13(t):341	'exp : exp AND_OP exp'342	n = Node(t[2])343	n.add_child(t[1])344	n.add_child(t[3])345	t[0] = n346	pass347def p_exp_14(t):348	'exp : exp MUL_ASSIGN exp'349	n = Node(t[2])350	n.add_child(t[1])351	n.add_child(t[3])352	t[0] = n353	pass354def p_exp_15(t):355	'exp : exp DIV_ASSIGN exp'356	n = Node(t[2])357	n.add_child(t[1])358	n.add_child(t[3])359	t[0] = n360	pass361def p_exp_16(t):362	'exp : exp MOD_ASSIGN exp'363	n = Node(t[2])364	n.add_child(t[1])365	n.add_child(t[3])366	t[0] = n367	pass368def p_exp_17(t):369	'exp : exp ADD_ASSIGN exp'370	n = Node(t[2])371	n.add_child(t[1])372	n.add_child(t[3])373	t[0] = n374	pass375def p_exp_18(t):376	'exp : exp SUB_ASSIGN exp'377	n = Node(t[2])378	n.add_child(t[1])379	n.add_child(t[3])380	t[0] = n381	pass382def p_exp_19(t):383	'exp : exp LEFT_ASSIGN exp'384	n = Node(t[2])385	n.add_child(t[1])386	n.add_child(t[3])387	t[0] = n388	pass389def p_exp_20(t):390	'exp : exp RIGHT_ASSIGN exp'391	n = Node(t[2])392	n.add_child(t[1])393	n.add_child(t[3])394	t[0] = n395	pass396def p_exp_21(t):397	'exp : exp AND_ASSIGN exp'398	n = Node(t[2])399	n.add_child(t[1])400	n.add_child(t[3])401	t[0] = n402	pass403def p_exp_22(t):404	'exp : exp XOR_ASSIGN exp'405	n = Node(t[2])406	n.add_child(t[1])407	n.add_child(t[3])408	t[0] = n409	pass410def p_exp_23(t):411	'exp : exp OR_ASSIGN exp'412	n = Node(t[2])413	n.add_child(t[1])414	n.add_child(t[3])415	t[0] = n416	pass417def p_exp_24(t):418	'exp : exp EQUALS exp'419	n = Node(t[2])420	n.add_child(t[1])421	n.add_child(t[3])422	t[0] = n423	pass424def p_exp_25(t):425	'exp : unary_expression'426	t[0] = t[1]427	pass428def p_exp_26(t):429	'exp : LPAREN exp RPAREN'430	n = Node('exp26')431	n.add_child(Node(t[1]))432	n.add_child(t[2])433	n.add_child(Node(t[3]))434	t[0] = n435	pass436def p_exp_27(t):437	'exp : constant'438	t[0] = t[1]439	pass440def p_exp_28(t):441	'exp : VARIABLE'442	t[0] = Node(t[1])443	pass444def p_exp_29(t):445	'exp : array'446	t[0] = t[1]447	pass448def p_exp_30(t):449	'exp : function_call'450	t[0] = t[1]451	pass452def p_unary_expression_1(t):453	'unary_expression : VARIABLE unary_operator'454	n = Node('unary_expression1')455	n.add_child(Node(t[1]))456	n.add_child(t[2])457	t[0] = n458	pass459def p_unary_expression_2(t):460	'unary_expression : unary_operator VARIABLE'461	n = Node('unary_expression2')462	n.add_child(t[1])463	n.add_child(Node(t[2]))464	t[0] = n465	pass466def p_unary_expression_3(t):467	'unary_expression : array unary_operator'468	n = Node('unary_expression3')469	n.add_child(t[1])470	n.add_child(t[2])471	t[0] = n472	pass473def p_unary_expression_4(t):474	'unary_expression : unary_operator array'475	n = Node('unary_expression4')476	n.add_child(t[1])477	n.add_child(t[2])478	t[0] = n479	pass480def p_unary_operator_1(t):481	'unary_operator : INCREMENT'482	t[0] = Node(t[1])483	pass484def p_unary_operator_2(t):485	'unary_operator : DECREMENT'486	t[0] = Node(t[1])487	pass488def p_iterative_statement_1(t):489	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN statement'490	n = Node('iterative_statement1')491	n.add_child(Node(t[1]))492	n.add_child(Node(t[2]))493	n.add_child(t[3])494	n.add_child(Node(t[4]))495	n.add_child(t[5])496	n.add_child(Node(t[6]))497	n.add_child(t[7])498	n.add_child(Node(t[8]))499	n.add_child(t[9])500	t[0] = n501	pass502def p_iterative_statement_2(t):503	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN LBRACE statements RBRACE'504	n = Node('iterative_statement2')505	n.add_child(Node(t[1]))506	n.add_child(Node(t[2]))507	n.add_child(t[3])508	n.add_child(Node(t[4]))509	n.add_child(t[5])510	n.add_child(Node(t[6]))511	n.add_child(t[7])512	n.add_child(Node(t[8]))513	n.add_child(Node(t[9]))514	n.add_child(t[10])515	n.add_child(Node(t[11]))516	t[0] = n517	pass518def p_iterative_statement_3(t):519	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN SEMI_COLON'520	n = Node('iterative_statement3')521	n.add_child(Node(t[1]))522	n.add_child(Node(t[2]))523	n.add_child(t[3])524	n.add_child(Node(t[4]))525	n.add_child(t[5])526	n.add_child(Node(t[6]))527	n.add_child(t[7])528	n.add_child(Node(t[8]))529	n.add_child(Node(t[9]))530	t[0] = n531	pass532def p_iterative_statement_4(t):533	'iterative_statement : FOR LPAREN iterative_exp SEMI_COLON iterative_exp SEMI_COLON iterative_exp RPAREN LBRACE RBRACE'534	n = Node('iterative_statement4')535	n.add_child(Node(t[1]))536	n.add_child(Node(t[2]))537	n.add_child(t[3])538	n.add_child(Node(t[4]))539	n.add_child(t[5])540	n.add_child(Node(t[6]))541	n.add_child(t[7])542	n.add_child(Node(t[8]))543	n.add_child(Node(t[9]))544	n.add_child(Node(t[10]))545	t[0] = n546	pass547def p_iterative_statement_5(t):548	'iterative_statement : WHILE LPAREN exp RPAREN statement'549	n = Node('iterative_statement5')550	n.add_child(Node(t[1]))551	n.add_child(Node(t[2]))552	n.add_child(t[3])553	n.add_child(Node(t[4]))554	n.add_child(t[5])555	t[0] = n556	pass557def p_iterative_statement_6(t):558	'iterative_statement : WHILE LPAREN exp RPAREN SEMI_COLON'559	n = Node('iterative_statement6')560	n.add_child(Node(t[1]))561	n.add_child(Node(t[2]))562	n.add_child(t[3])563	n.add_child(Node(t[4]))564	n.add_child(Node(t[5]))565	t[0] = n566	pass567def p_iterative_statement_7(t):568	'iterative_statement : WHILE LPAREN exp RPAREN LBRACE statements RBRACE'569	n = Node('iterative_statement7')570	n.add_child(Node(t[1]))571	n.add_child(Node(t[2]))572	n.add_child(t[3])573	n.add_child(Node(t[4]))574	n.add_child(Node(t[5]))575	n.add_child(t[6])576	n.add_child(Node(t[7]))577	t[0] = n578	pass579def p_iterative_statement_8(t):580	'iterative_statement : WHILE LPAREN exp RPAREN LBRACE RBRACE'581	n = Node('iterative_statement8')582	n.add_child(Node(t[1]))583	n.add_child(Node(t[2]))584	n.add_child(t[3])585	n.add_child(Node(t[4]))586	n.add_child(Node(t[5]))587	n.add_child(Node(t[6]))588	t[0] = n589	pass590def p_iterative_statement_9(t):591	'iterative_statement : DO statement WHILE LPAREN exp RPAREN SEMI_COLON'592	n = Node('iterative_statement9')593	n.add_child(Node(t[1]))594	n.add_child(t[2])595	n.add_child(Node(t[3]))596	n.add_child(Node(t[4]))597	n.add_child(t[5])598	n.add_child(Node(t[6]))599	n.add_child(Node(t[7]))600	t[0] = n601	pass602def p_iterative_statement_10(t):603	'iterative_statement : DO LBRACE statements RBRACE WHILE LPAREN exp RPAREN SEMI_COLON'604	n = Node('iterative_statement10')605	n.add_child(Node(t[1]))606	n.add_child(Node(t[2]))607	n.add_child(t[3])608	n.add_child(Node(t[4]))609	n.add_child(Node(t[5]))610	n.add_child(Node(t[6]))611	n.add_child(t[7])612	n.add_child(Node(t[8]))613	n.add_child(Node(t[9]))614	t[0] = n615	pass616def p_iterative_statement_11(t):617	'iterative_statement : DO SEMI_COLON WHILE LPAREN exp RPAREN SEMI_COLON'618	n = Node('iterative_statement11')619	n.add_child(Node(t[1]))620	n.add_child(Node(t[2]))621	n.add_child(Node(t[3]))622	n.add_child(Node(t[4]))623	n.add_child(t[5])624	n.add_child(Node(t[6]))625	n.add_child(Node(t[7]))626	t[0] = n627	pass628def p_iterative_statement_12(t):629	'iterative_statement : DO LBRACE RBRACE WHILE LPAREN exp RPAREN SEMI_COLON'630	n = Node('iterative_statement12')631	n.add_child(Node(t[1]))632	n.add_child(Node(t[2]))633	n.add_child(Node(t[3]))634	n.add_child(Node(t[4]))635	n.add_child(Node(t[5]))636	n.add_child(t[6])637	n.add_child(Node(t[7]))638	n.add_child(Node(t[8]))639	t[0] = n640	pass641def p_iterative_exp_1(t):642	'iterative_exp : exp COMMA iterative_exp'643	n = Node('iterative_exp1')644	n.add_child(t[1])645	n.add_child(Node(t[2]))646	n.add_child(t[3])647	t[0] = n648	pass649def p_iterative_exp_2(t):650	'iterative_exp : exp'651	t[0] = t[1]652	pass653def p_conditional_statement_1(t):654	'conditional_statement : IF LPAREN exp RPAREN statement %prec UELSE'655	n = Node('conditional_statement1')656	n.add_child(Node(t[1]))657	n.add_child(Node(t[2]))658	n.add_child(t[3])659	n.add_child(Node(t[4]))660	n.add_child(t[5])661	t[0] = n662	pass663def p_conditional_statement_2(t):664	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE %prec UELSE'665	n = Node('conditional_statement2')666	n.add_child(Node(t[1]))667	n.add_child(Node(t[2]))668	n.add_child(t[3])669	n.add_child(Node(t[4]))670	n.add_child(Node(t[5]))671	n.add_child(t[6])672	n.add_child(Node(t[7]))673	t[0] = n674	pass675def p_conditional_statement_3(t):676	'conditional_statement : IF LPAREN exp RPAREN statement ELSE statement'677	n = Node('conditional_statement3')678	n.add_child(Node(t[1]))679	n.add_child(Node(t[2]))680	n.add_child(t[3])681	n.add_child(Node(t[4]))682	n.add_child(t[5])683	n.add_child(Node(t[6]))684	n.add_child(t[7])685	t[0] = n686	pass687def p_conditional_statement_4(t):688	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE ELSE statement'689	n = Node('conditional_statement4')690	n.add_child(Node(t[1]))691	n.add_child(Node(t[2]))692	n.add_child(t[3])693	n.add_child(Node(t[4]))694	n.add_child(Node(t[5]))695	n.add_child(t[6])696	n.add_child(Node(t[7]))697	n.add_child(Node(t[8]))698	n.add_child(t[9])699	t[0] = n700	pass701def p_conditional_statement_5(t):702	'conditional_statement : IF LPAREN exp RPAREN statement ELSE LBRACE statements RBRACE'703	n = Node('conditional_statement5')704	n.add_child(Node(t[1]))705	n.add_child(Node(t[2]))706	n.add_child(t[3])707	n.add_child(Node(t[4]))708	n.add_child(t[5])709	n.add_child(Node(t[6]))710	n.add_child(Node(t[7]))711	n.add_child(t[8])712	n.add_child(Node(t[9]))713	t[0] = n714	pass715def p_conditional_statement_6(t):716	'conditional_statement : IF LPAREN exp RPAREN LBRACE statements RBRACE ELSE LBRACE statements RBRACE'717	n = Node('conditional_statement6')718	n.add_child(Node(t[1]))719	n.add_child(Node(t[2]))720	n.add_child(t[3])721	n.add_child(Node(t[4]))722	n.add_child(Node(t[5]))723	n.add_child(t[6])724	n.add_child(Node(t[7]))725	n.add_child(Node(t[8]))726	n.add_child(Node(t[9]))727	n.add_child(t[10])728	n.add_child(Node(t[11]))729	t[0] = n730	pass731def p_function_1(t):732	'function : normal_function'733	t[0] = t[1]734	pass735def p_function_2(t):736	'function : main_function'737	t[0] = t[1]738	pass739def p_main_function_1(t):740	'main_function : type MAIN LPAREN parameters RPAREN LBRACE statements RBRACE'741	n = Node('main_function1')742	n.add_child(t[1])743	n.add_child(Node(t[2]))744	n.add_child(Node(t[3]))745	n.add_child(t[4])746	n.add_child(Node(t[5]))747	n.add_child(Node(t[6]))748	n.add_child(t[7])749	n.add_child(Node(t[8]))750	t[0] = n751	pass752def p_main_function_2(t):753	'main_function : type MAIN LPAREN parameters RPAREN LBRACE RBRACE'754	n = Node('main_function2')755	n.add_child(t[1])756	n.add_child(Node(t[2]))757	n.add_child(Node(t[3]))758	n.add_child(t[4])759	n.add_child(Node(t[5]))760	n.add_child(Node(t[6]))761	n.add_child(Node(t[7]))762	t[0] = n763	pass764def p_main_function_3(t):765	'main_function : MAIN LPAREN parameters RPAREN LBRACE statements RBRACE'766	n = Node('main_function3')767	n.add_child(Node("VOID"))768	n.add_child(Node(t[1]))769	n.add_child(Node(t[2]))770	n.add_child(t[3])771	n.add_child(Node(t[4]))772	n.add_child(Node(t[5]))773	n.add_child(t[6])774	n.add_child(Node(t[7]))775	t[0] = n776	pass777def p_main_function_4(t):778	'main_function : MAIN LPAREN parameters RPAREN LBRACE RBRACE'779	n = Node('main_function4')780	n.add_child(Node("VOID"))781	n.add_child(Node(t[1]))782	n.add_child(Node(t[2]))783	n.add_child(t[3])784	n.add_child(Node(t[4]))785	n.add_child(Node(t[5]))786	n.add_child(Node(t[6]))787	t[0] = n788	pass789def p_main_function_5(t):790	'main_function : type MAIN LPAREN RPAREN LBRACE statements RBRACE'791	n = Node('main_function5')792	n.add_child(t[1])793	n.add_child(Node(t[2]))794	n.add_child(Node(t[3]))795	n.add_child(Node(t[4]))796	n.add_child(Node(t[5]))797	n.add_child(t[6])798	n.add_child(Node(t[7]))799	t[0] = n800	pass801def p_main_function_6(t):802	'main_function : type MAIN LPAREN RPAREN LBRACE RBRACE'803	n = Node('main_function6')804	n.add_child(t[1])805	n.add_child(Node(t[2]))806	n.add_child(Node(t[3]))807	n.add_child(Node(t[4]))808	n.add_child(Node(t[5]))809	n.add_child(Node(t[6]))810	t[0] = n811	pass812def p_main_function_7(t):813	'main_function : MAIN LPAREN RPAREN LBRACE statements RBRACE'814	n = Node('main_function7')815	n.add_child(Node("VOID"))816	n.add_child(Node(t[1]))817	n.add_child(Node(t[2]))818	n.add_child(Node(t[3]))819	n.add_child(Node(t[4]))820	n.add_child(t[5])821	n.add_child(Node(t[6]))822	t[0] = n823	pass824def p_main_function_8(t):825	'main_function : MAIN LPAREN RPAREN LBRACE RBRACE'826	n = Node('main_function8')827	n.add_child(Node("VOID"))828	n.add_child(Node(t[1]))829	n.add_child(Node(t[2]))830	n.add_child(Node(t[3]))831	n.add_child(Node(t[4]))832	n.add_child(Node(t[5]))833	t[0] = n834	pass835def p_normal_function_1(t):836	'normal_function : type VARIABLE LPAREN parameters RPAREN LBRACE statements RBRACE'837	n = Node('normal_function1')838	n.add_child(t[1])839	n.add_child(Node(t[2]))840	n.add_child(Node(t[3]))841	n.add_child(t[4])842	n.add_child(Node(t[5]))843	n.add_child(Node(t[6]))844	n.add_child(t[7])845	n.add_child(Node(t[8]))846	t[0] = n847	pass848def p_normal_function_2(t):849	'normal_function : type VARIABLE LPAREN parameters RPAREN LBRACE RBRACE'850	n = Node('normal_function2')851	n.add_child(t[1])852	n.add_child(Node(t[2]))853	n.add_child(Node(t[3]))854	n.add_child(t[4])855	n.add_child(Node(t[5]))856	n.add_child(Node(t[6]))857	n.add_child(Node(t[7]))858	t[0] = n859	pass860def p_normal_function_3(t):861	'normal_function : VARIABLE LPAREN parameters RPAREN LBRACE statements RBRACE'862	n = Node('normal_function3')863	n.add_child(Node("VOID"))864	n.add_child(Node(t[1]))865	n.add_child(Node(t[2]))866	n.add_child(t[3])867	n.add_child(Node(t[4]))868	n.add_child(Node(t[5]))869	n.add_child(t[6])870	n.add_child(Node(t[7]))871	t[0] = n872	pass873def p_normal_function_4(t):874	'normal_function : VARIABLE LPAREN parameters RPAREN LBRACE RBRACE'875	n = Node('normal_function4')876	n.add_child(Node("VOID"))877	n.add_child(Node(t[1]))878	n.add_child(Node(t[2]))879	n.add_child(t[3])880	n.add_child(Node(t[4]))881	n.add_child(Node(t[5]))882	n.add_child(Node(t[6]))883	t[0] = n884	pass885def p_normal_function_5(t):886	'normal_function : type VARIABLE LPAREN RPAREN LBRACE statements RBRACE'887	n = Node('normal_function5')888	n.add_child(t[1])889	n.add_child(Node(t[2]))890	n.add_child(Node(t[3]))891	n.add_child(Node(t[4]))892	n.add_child(Node(t[5]))893	n.add_child(t[6])894	n.add_child(Node(t[7]))895	t[0] = n896	pass897def p_normal_function_6(t):898	'normal_function : type VARIABLE LPAREN RPAREN LBRACE RBRACE'899	n = Node('normal_function6')900	n.add_child(t[1])901	n.add_child(Node(t[2]))902	n.add_child(Node(t[3]))903	n.add_child(Node(t[4]))904	n.add_child(Node(t[5]))905	n.add_child(Node(t[6]))906	t[0] = n907	pass908def p_normal_function_7(t):909	'normal_function : VARIABLE LPAREN RPAREN LBRACE statements RBRACE'910	n = Node('normal_function7')911	n.add_child(Node("VOID"))912	n.add_child(Node(t[1]))913	n.add_child(Node(t[2]))914	n.add_child(Node(t[3]))915	n.add_child(Node(t[4]))916	n.add_child(t[5])917	n.add_child(Node(t[6]))918	t[0] = n919	pass920def p_normal_function_8(t):921	'normal_function : VARIABLE LPAREN RPAREN LBRACE RBRACE'922	n = Node('normal_function8')923	n.add_child(Node("VOID"))924	n.add_child(Node(t[1]))925	n.add_child(Node(t[2]))926	n.add_child(Node(t[3]))927	n.add_child(Node(t[4]))928	n.add_child(Node(t[5]))929	t[0] = n930	pass931def p_parameters_1(t):932	'parameters : type VARIABLE COMMA parameters'933	n = Node('parameters1')934	n.add_child(t[1])935	n.add_child(Node(t[2]))936	n.add_child(Node(t[3]))937	n.add_child(t[4])938	t[0] = n939	pass940def p_parameters_2(t):941	'parameters : type VARIABLE'942	n = Node('parameters2')943	n.add_child(t[1])944	n.add_child(Node(t[2]))945	t[0] = n946	pass947def p_function_call_1(t):948	'function_call : VARIABLE LPAREN arguments RPAREN'949	n = Node('function_call1')950	n.add_child(Node(t[1]))951	n.add_child(Node(t[2]))952	n.add_child(t[3])953	n.add_child(Node(t[4]))954	t[0] = n955	pass956def p_function_call_2(t):957	'function_call : VARIABLE LPAREN RPAREN'958	n = Node('function_call2')959	n.add_child(Node(t[1]))960	n.add_child(Node(t[2]))961	n.add_child(Node(t[3]))962	t[0] = n963	pass964def p_arguments_1(t):965	'arguments : arguments COMMA exp'966	n = Node('arguments1')967	n.add_child(t[1])968	n.add_child(Node(t[2]))969	n.add_child(t[3])970	t[0] = n971	pass972def p_arguments_2(t):973	'arguments : exp'974	t[0] = t[1]975	pass976def p_empty(t):977	'empty : '978	t[0] = Node('empty')979	pass980def p_error(t):981    print "ERROR"982def parse():983	f = open(sys.argv[1])...gen_oxml_classes.py
Source:gen_oxml_classes.py  
...3031    def __getitem__(self, key):32        return self.__getattribute__(key)3334    def add_child(self, tag, cardinality='?'):35        self.children.append(ChildDef(self, tag, cardinality))3637    def add_attribute(self, name, required=False, default=None):38        self.attributes.append(AttributeDef(self, name, required, default))3940    def add_attributes(self, *names):41        for name in names:42            self.attributes.append(AttributeDef(self, name, False, None))4344    @property45    def indent(self):46        indent_len = 12 - len(self.tagname)47        if indent_len < 0:48            indent_len = 049        return ' ' * indent_len5051    @property52    def max_attr_name_len(self):53        return max([len(attr.name) for attr in self.attributes])5455    @property56    def max_child_tagname_len(self):57        return max([len(child.tagname) for child in self.children])5859    @property60    def optional_children(self):61        return [child for child in self.children if not child.is_required]6263    @property64    def required_attributes(self):65        return [attr for attr in self.attributes if attr.is_required]6667    @property68    def required_children(self):69        return [child for child in self.children if child.is_required]707172class AttributeDef(object):73    """74    Attribute definition75    """76    def __init__(self, element, name, required, default):77        self.element = element78        self.name = name79        self.required = required80        self.default = default81        self.varname = name.replace(':', '_')8283    def __getitem__(self, key):84        return self.__getattribute__(key)8586    @property87    def padding(self):88        return ' ' * (self.element.max_attr_name_len - len(self.name))8990    @property91    def indent(self):92        return ' ' * self.element.max_attr_name_len9394    @property95    def is_required(self):96        return self.required979899class ChildDef(object):100    """101    Child element definition102    """103    def __init__(self, element, tag, cardinality):104        self.element = element105        self.tag = tag106        self.cardinality = cardinality107        if not ':' in tag:108            tmpl = "missing namespace prefix in tag: '%s'"109            raise ValueError(tmpl % tag)110        tagparts = tag.split(':')111        self.nsprefix = tagparts[0]112        self.tagname = tagparts[1]113114    def __getitem__(self, key):115        return self.__getattribute__(key)116117    @property118    def indent(self):119        indent_len = self.element.max_child_tagname_len - len(self.tagname)120        return ' ' * indent_len121122    @property123    def is_required(self):124        return self.cardinality in '1+'125126127# ============================================================================128# Code templates129# ============================================================================130131class tmpl(object):132    attr_accessor = Template("    $varname$padding = property(lambda self: se"133        "lf.get('$name'),\n$indent                lambda self, value: self.se"134        "t('$name', value))\n")135136    class_def_head = Template('''class $classname(ElementBase):\n    """<$n'''137        '''sprefix:$tagname> custom element class"""\n''')138139    class_mapping = Template("        , '$tagname'$indent : $classname\n\n")140141    ns_attr_accessor = Template(142        "    $varname$padding = property(lambda self: self.get(_qtag('$name')"143        "),\n$indent                lambda self, value: self.set(_qtag('$name"144        "'), value))\n")145146    ns_reqd_attribute_constructor = Template("        _required_attribute(sel"147        "f, _qtag('$name'), default='$default')\n")148149    optional_child_accessor = Template("    $tagname$indent = property(lambda"150        " self: _get_child_or_append(self, '$tag'))\n")151152    reqd_attr_constructor = Template("        _required_attribute(self, '$nam"153        "e', default='$default')\n")154155    reqd_child_accessor = Template("    $tagname$indent = property(lambda sel"156        "f: _child(self, '$tag'))\n")157158    reqd_child_constructor = Template("        _required_child(self, '$tag')"159        "\n")160161162# ============================================================================163# binding specs164# ============================================================================165166# sldMaster = ElementDef('p:sldMaster', 'CT_SlideMaster')167# sldMaster.add_child('p:cSld'          , cardinality='1')168# sldMaster.add_child('p:clrMap'        , cardinality='1')169# sldMaster.add_child('p:sldLayoutIdLst', cardinality='?')170# sldMaster.add_child('p:transition'    , cardinality='?')171# sldMaster.add_child('p:timing'        , cardinality='?')172# sldMaster.add_child('p:hf'            , cardinality='?')173# sldMaster.add_child('p:txStyles'      , cardinality='?')174# sldMaster.add_child('p:extLst'        , cardinality='?')175# sldMaster.add_attributes('preserve')176177178179def class_template(element):180    out = ''181    out += tmpl.class_mapping.substitute(element)182    out += tmpl.class_def_head.substitute(element)183    if element.required_children or element.required_attributes:184        out += '    def _init(self):\n'185        for child in element.required_children:186            out += tmpl.reqd_child_constructor.substitute(child)187        for attribute in element.required_attributes:188            if ':' in attribute.name:189                out += tmpl.ns_reqd_attr_constructor.substitute(attribute)190            else:191                out += tmpl.reqd_attr_constructor.substitute(attribute)192        out += '\n'193    if element.children:194        out += '    # child accessors -----------------\n'195        for child in element.required_children:196            out += tmpl.reqd_child_accessor.substitute(child)197        for child in element.optional_children:198            out += tmpl.optional_child_accessor.substitute(child)199        out += '\n'200    if element.attributes:201        out += '    # attribute accessors -------------\n'202        for attribute in element.attributes:203            if ':' in attribute.name:204                out += tmpl.ns_attr_accessor.substitute(attribute)205            else:206                out += tmpl.attr_accessor.substitute(attribute)207        out += '\n'208    out += '\n'209    return out210211212213elements = ElementDef.instances214215out = '\n'216for element in elements:217    out += class_template(element)218219print out220221sys.exit()222223224# ============================================================================225# Element definitions226# ============================================================================227228# blip = ElementDef('a:blip', 'CT_Blip')229# blip.add_child('a:alphaBiLevel' , cardinality='?')230# blip.add_child('a:alphaCeiling' , cardinality='?')231# blip.add_child('a:alphaFloor'   , cardinality='?')232# blip.add_child('a:alphaInv'     , cardinality='?')233# blip.add_child('a:alphaMod'     , cardinality='?')234# blip.add_child('a:alphaModFix'  , cardinality='?')235# blip.add_child('a:alphaRepl'    , cardinality='?')236# blip.add_child('a:biLevel'      , cardinality='?')237# blip.add_child('a:blur'         , cardinality='?')238# blip.add_child('a:clrChange'    , cardinality='?')239# blip.add_child('a:clrRepl'      , cardinality='?')240# blip.add_child('a:duotone'      , cardinality='?')241# blip.add_child('a:fillOverlay'  , cardinality='?')242# blip.add_child('a:grayscl'      , cardinality='?')243# blip.add_child('a:hsl'          , cardinality='?')244# blip.add_child('a:lum'          , cardinality='?')245# blip.add_child('a:tint'         , cardinality='?')246# blip.add_child('a:extLst'       , cardinality='?')247# blip.add_attributes('r_embed', 'r_link', 'cstate')248249# blipFill = ElementDef('p:blipFill', 'CT_BlipFillProperties')250# blipFill.add_child('a:blip'    , cardinality='?')251# blipFill.add_child('a:srcRect' , cardinality='?')252# blipFill.add_child('a:tile'    , cardinality='?')253# blipFill.add_child('a:stretch' , cardinality='?')254# blipFill.add_attributes('dpi', 'rotWithShape')255256# bodyPr = ElementDef('a:bodyPr', 'CT_TextBodyProperties')257# bodyPr.add_child('a:spAutoFit', cardinality='?')258# bodyPr.add_attribute('wrap')259# bodyPr.add_attribute('rtlCol')260# bodyPr.add_attribute('anchor')261# bodyPr.add_attribute('anchorCtr')262263# cNvPr = ElementDef('p:cNvPr', 'CT_NonVisualDrawingProps')264# cNvPr.add_child('a:hlinkClick' , cardinality='?')265# cNvPr.add_child('a:hlinkHover' , cardinality='?')266# cNvPr.add_child('a:extLst'     , cardinality='?')267# cNvPr.add_attribute('id', required=True, default='0')268# cNvPr.add_attribute('name', required=True, default='Unnamed')269# cNvPr.add_attributes('descr', 'hidden', 'title')270271# cNvSpPr = ElementDef('p:cNvSpPr', 'CT_NonVisualDrawingShapeProps')272# cNvSpPr.add_child('a:spLocks', cardinality='?')273# cNvSpPr.add_child('a:extLst' , cardinality='?')274# cNvSpPr.add_attributes('txBox')275276# cSld = ElementDef('p:cSld', 'CT_CommonSlideData')277# cSld.add_child('p:bg'         , cardinality='?')278# cSld.add_child('p:spTree'     , cardinality='1')279# cSld.add_child('p:custDataLst', cardinality='?')280# cSld.add_child('p:controls'   , cardinality='?')281# cSld.add_child('p:extLst'     , cardinality='?')282# cSld.add_attributes('name')283284# defRPr = ElementDef('a:defRPr', 'CT_TextCharacterProperties')285# defRPr.add_child('a:ln'            , cardinality='?')286# defRPr.add_child('a:noFill'        , cardinality='?')287# defRPr.add_child('a:solidFill'     , cardinality='?')288# defRPr.add_child('a:gradFill'      , cardinality='?')289# defRPr.add_child('a:blipFill'      , cardinality='?')290# defRPr.add_child('a:pattFill'      , cardinality='?')291# defRPr.add_child('a:grpFill'       , cardinality='?')292# defRPr.add_child('a:effectLst'     , cardinality='?')293# defRPr.add_child('a:effectDag'     , cardinality='?')294# defRPr.add_child('a:highlight'     , cardinality='?')295# defRPr.add_child('a:uLnTx'         , cardinality='?')296# defRPr.add_child('a:uLn'           , cardinality='?')297# defRPr.add_child('a:uFillTx'       , cardinality='?')298# defRPr.add_child('a:uFill'         , cardinality='?')299# defRPr.add_child('a:latin'         , cardinality='?')300# defRPr.add_child('a:ea'            , cardinality='?')301# defRPr.add_child('a:cs'            , cardinality='?')302# defRPr.add_child('a:sym'           , cardinality='?')303# defRPr.add_child('a:hlinkClick'    , cardinality='?')304# defRPr.add_child('a:hlinkMouseOver', cardinality='?')305# defRPr.add_child('a:rtl'           , cardinality='?')306# defRPr.add_child('a:extLst'        , cardinality='?')307# defRPr.add_attributes('kumimoji', 'lang', 'altLang', 'sz', 'b', 'i', 'u',308#     'strike', 'kern', 'cap', 'spc', 'normalizeH', 'baseline', 'noProof',309#     'dirty', 'err', 'smtClean', 'smtId', 'bmk')310311# nvGrpSpPr = ElementDef('p:nvGrpSpPr', 'CT_GroupShapeNonVisual')312# nvGrpSpPr.add_child('p:cNvPr'     , cardinality='1')313# nvGrpSpPr.add_child('p:cNvGrpSpPr', cardinality='1')314# nvGrpSpPr.add_child('p:nvPr'      , cardinality='1')315316# nvPicPr = ElementDef('p:nvPicPr', 'CT_PictureNonVisual')317# nvPicPr.add_child('p:cNvPr'    , cardinality='1')318# nvPicPr.add_child('p:cNvPicPr' , cardinality='1')319# nvPicPr.add_child('p:nvPr'     , cardinality='1')320321# nvPr = ElementDef('p:nvPr', 'CT_ApplicationNonVisualDrawingProps')322# nvPr.add_child('p:ph'           , cardinality='?')323# nvPr.add_child('p:audioCd'      , cardinality='?')324# nvPr.add_child('p:wavAudioFile' , cardinality='?')325# nvPr.add_child('p:audioFile'    , cardinality='?')326# nvPr.add_child('p:videoFile'    , cardinality='?')327# nvPr.add_child('p:quickTimeFile', cardinality='?')328# nvPr.add_child('p:custDataLst'  , cardinality='?')329# nvPr.add_child('p:extLst'       , cardinality='?')330# nvPr.add_attributes('isPhoto', 'userDrawn')331332# nvSpPr = ElementDef('p:nvSpPr', 'CT_ShapeNonVisual')333# nvSpPr.add_child('p:cNvPr'  , cardinality='1')334# nvSpPr.add_child('p:cNvSpPr', cardinality='1')335# nvSpPr.add_child('p:nvPr'   , cardinality='1')336337# off = ElementDef('a:off', 'CT_Point2D')338# off.add_attribute('x', required=True, default='0')339# off.add_attribute('y', required=True, default='0')340341# p = ElementDef('a:p', 'CT_TextParagraph')342# p.add_child('a:pPr' , cardinality='?')343# p.add_child('a:r'   , cardinality='*')344# p.add_child('a:br'  , cardinality='*')345# p.add_child('a:fld' , cardinality='*')346# p.add_child('a:endParaRPr', cardinality='?')347348# ph = ElementDef('p:ph', 'CT_Placeholder')349# ph.add_child('p:extLst', cardinality='?')350# ph.add_attributes('type', 'orient', 'sz', 'idx', 'hasCustomPrompt')351352# pic = ElementDef('p:pic', 'CT_Picture')353# pic.add_child('p:nvPicPr'  , cardinality='1')354# pic.add_child('p:blipFill' , cardinality='1')355# pic.add_child('p:spPr'     , cardinality='1')356# pic.add_child('p:style'    , cardinality='?')357# pic.add_child('p:extLst'   , cardinality='?')358359# pPr = ElementDef('a:pPr', 'CT_TextParagraphProperties')360# pPr.add_child('a:lnSpc'    , cardinality='?')361# pPr.add_child('a:spcBef'   , cardinality='?')362# pPr.add_child('a:spcAft'   , cardinality='?')363# pPr.add_child('a:buClrTx'  , cardinality='?')364# pPr.add_child('a:buClr'    , cardinality='?')365# pPr.add_child('a:buSzTx'   , cardinality='?')366# pPr.add_child('a:buSzPct'  , cardinality='?')367# pPr.add_child('a:buSzPts'  , cardinality='?')368# pPr.add_child('a:buFontTx' , cardinality='?')369# pPr.add_child('a:buFont'   , cardinality='?')370# pPr.add_child('a:buNone'   , cardinality='?')371# pPr.add_child('a:buAutoNum', cardinality='?')372# pPr.add_child('a:buChar'   , cardinality='?')373# pPr.add_child('a:buBlip'   , cardinality='?')374# pPr.add_child('a:tabLst'   , cardinality='?')375# pPr.add_child('a:defRPr'   , cardinality='?')376# pPr.add_child('a:extLst'   , cardinality='?')377# pPr.add_attributes('marL', 'marR', 'lvl', 'indent', 'algn', 'defTabSz',378#     'rtl', 'eaLnBrk', 'fontAlgn', 'latinLnBrk', 'hangingPunct')379380# presentation = ElementDef('p:presentation', 'CT_Presentation')381# presentation.add_child('p:sldMasterIdLst'    , cardinality='?')382# presentation.add_child('p:notesMasterIdLst'  , cardinality='?')383# presentation.add_child('p:handoutMasterIdLst', cardinality='?')384# presentation.add_child('p:sldIdLst'          , cardinality='?')385# presentation.add_child('p:sldSz'             , cardinality='?')386# presentation.add_child('p:notesSz'           , cardinality='1')387# presentation.add_child('p:smartTags'         , cardinality='?')388# presentation.add_child('p:embeddedFontLst'   , cardinality='?')389# presentation.add_child('p:custShowLst'       , cardinality='?')390# presentation.add_child('p:photoAlbum'        , cardinality='?')391# presentation.add_child('p:custDataLst'       , cardinality='?')392# presentation.add_child('p:kinsoku'           , cardinality='?')393# presentation.add_child('p:defaultTextStyle'  , cardinality='?')394# presentation.add_child('p:modifyVerifier'    , cardinality='?')395# presentation.add_child('p:extLst'            , cardinality='?')396# presentation.add_attributes('serverZoom', 'firstSlideNum',397#     'showSpecialPlsOnTitleSld', 'rtl', 'removePersonalInfoOnSave',398#     'compatMode', 'strictFirstAndLastChars', 'embedTrueTypeFonts',399#     'saveSubsetFonts', 'autoCompressPictures', 'bookmarkIdSeed',400#     'conformance')401402# rPr = ElementDef('a:rPr', 'CT_TextCharacterProperties')403# rPr.add_child('a:ln', cardinality='?')404# rPr.add_attribute('sz')405# rPr.add_attribute('b')406# rPr.add_attribute('i')407# rPr.add_attribute('u')408# rPr.add_attribute('strike')409# rPr.add_attribute('kern')410# rPr.add_attribute('cap')411# rPr.add_attribute('spc')412# rPr.add_attribute('baseline')413414# sld = ElementDef('p:sld', 'CT_Slide')415# sld.add_child('p:cSld'       , cardinality='1')416# sld.add_child('p:clrMapOvr'  , cardinality='?')417# sld.add_child('p:transition' , cardinality='?')418# sld.add_child('p:timing'     , cardinality='?')419# sld.add_child('p:extLst'     , cardinality='?')420# sld.add_attributes('showMasterSp', 'showMasterPhAnim', 'show')421422# sldId = ElementDef('p:sldId', 'CT_SlideIdListEntry')423# sldId.add_child('p:extLst', cardinality='?')424# sldId.add_attribute('id', required=True, default='')425# sldId.add_attribute('r:id', required=True, default='')426427# sldIdLst = ElementDef('p:sldIdLst', 'CT_SlideIdList')428# sldIdLst.add_child('p:sldId', cardinality='*')429430# sldLayout = ElementDef('p:sldLayout', 'CT_SlideLayout')431# sldLayout.add_child('p:cSld'      , cardinality='1')432# sldLayout.add_child('p:clrMapOvr' , cardinality='?')433# sldLayout.add_child('p:transition', cardinality='?')434# sldLayout.add_child('p:timing'    , cardinality='?')435# sldLayout.add_child('p:hf'        , cardinality='?')436# sldLayout.add_child('p:extLst'    , cardinality='?')437# sldLayout.add_attributes('showMasterSp', 'showMasterPhAnim', 'matchingName', 'type', 'preserve', 'userDrawn')438439# spLocks = ElementDef('a:spLocks', 'CT_ShapeLocking')440# spLocks.add_child('a:extLst', cardinality='?')441# spLocks.add_attributes('noGrp', 'noSelect', 'noRot', 'noChangeAspect',442#     'noMove', 'noResize', 'noEditPoints', 'noAdjustHandles',443#     'noChangeArrowheads', 'noChangeShapeType', 'noTextEdit')444445# spPr = ElementDef('p:spPr', 'CT_ShapeProperties')446# spPr.add_child('a:xfrm'      , cardinality='?')447# spPr.add_child('a:custGeom'  , cardinality='?')448# spPr.add_child('a:prstGeom'  , cardinality='?')449# spPr.add_child('a:noFill'    , cardinality='?')450# spPr.add_child('a:solidFill' , cardinality='?')451# spPr.add_child('a:gradFill'  , cardinality='?')452# spPr.add_child('a:blipFill'  , cardinality='?')453# spPr.add_child('a:pattFill'  , cardinality='?')454# spPr.add_child('a:grpFill'   , cardinality='?')455# spPr.add_child('a:ln'        , cardinality='?')456# spPr.add_child('a:effectLst' , cardinality='?')457# spPr.add_child('a:effectDag' , cardinality='?')458# spPr.add_child('a:scene3d'   , cardinality='?')459# spPr.add_child('a:sp3d'      , cardinality='?')460# spPr.add_child('a:extLst'    , cardinality='?')461# spPr.add_attribute('bwMode')462463# spTree = ElementDef('p:spTree', 'CT_GroupShape')464# spTree.add_child('p:nvGrpSpPr'   , cardinality='1')465# spTree.add_child('p:grpSpPr'     , cardinality='1')466# spTree.add_child('p:sp'          , cardinality='?')467# spTree.add_child('p:grpSp'       , cardinality='?')468# spTree.add_child('p:graphicFrame', cardinality='?')469# spTree.add_child('p:cxnSp'       , cardinality='?')470# spTree.add_child('p:pic'         , cardinality='?')471# spTree.add_child('p:contentPart' , cardinality='?')472# spTree.add_child('p:extLst'      , cardinality='?')473474# stretch = ElementDef('a:stretch', 'CT_StretchInfoProperties')475# stretch.add_child('a:fillRect' , cardinality='?')476477# txBody = ElementDef('p:txBody', 'CT_TextBody')478# txBody.add_child('a:bodyPr'   , cardinality='1')479# txBody.add_child('a:lstStyle' , cardinality='?')480# txBody.add_child('a:p'        , cardinality='+')
...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
