cparse.py (4479:61d3ed46e373) | cparse.py (6498:e21e9ab5fad0) |
---|---|
1# ----------------------------------------------------------------------------- 2# cparse.py 3# 4# Simple parser for ANSI C. Based on the grammar in K&R, 2nd Ed. 5# ----------------------------------------------------------------------------- 6 7import sys 8import clex --- 141 unchanged lines hidden (view full) --- 150 151# struct-declaration-list: 152 153def p_struct_declaration_list_1(t): 154 'struct_declaration_list : struct_declaration' 155 pass 156 157def p_struct_declaration_list_2(t): | 1# ----------------------------------------------------------------------------- 2# cparse.py 3# 4# Simple parser for ANSI C. Based on the grammar in K&R, 2nd Ed. 5# ----------------------------------------------------------------------------- 6 7import sys 8import clex --- 141 unchanged lines hidden (view full) --- 150 151# struct-declaration-list: 152 153def p_struct_declaration_list_1(t): 154 'struct_declaration_list : struct_declaration' 155 pass 156 157def p_struct_declaration_list_2(t): |
158 'struct_declaration_list : struct_declarator_list struct_declaration' | 158 'struct_declaration_list : struct_declaration_list struct_declaration' |
159 pass 160 161# init-declarator-list: 162 163def p_init_declarator_list_1(t): 164 'init_declarator_list : init_declarator' 165 pass 166 --- 606 unchanged lines hidden (view full) --- 773 774def p_unary_expression_5(t): 775 'unary_expression : SIZEOF unary_expression' 776 pass 777 778def p_unary_expression_6(t): 779 'unary_expression : SIZEOF LPAREN type_name RPAREN' 780 pass | 159 pass 160 161# init-declarator-list: 162 163def p_init_declarator_list_1(t): 164 'init_declarator_list : init_declarator' 165 pass 166 --- 606 unchanged lines hidden (view full) --- 773 774def p_unary_expression_5(t): 775 'unary_expression : SIZEOF unary_expression' 776 pass 777 778def p_unary_expression_6(t): 779 'unary_expression : SIZEOF LPAREN type_name RPAREN' 780 pass |
781 | 781 |
782#unary-operator 783def p_unary_operator(t): 784 '''unary_operator : AND 785 | TIMES | 782#unary-operator 783def p_unary_operator(t): 784 '''unary_operator : AND 785 | TIMES |
786 | PLUS | 786 | PLUS |
787 | MINUS 788 | NOT 789 | LNOT ''' 790 pass 791 792# postfix-expression: 793def p_postfix_expression_1(t): 794 'postfix_expression : primary_expression' --- 37 unchanged lines hidden (view full) --- 832 833# argument-expression-list: 834def p_argument_expression_list(t): 835 '''argument_expression_list : assignment_expression 836 | argument_expression_list COMMA assignment_expression''' 837 pass 838 839# constant: | 787 | MINUS 788 | NOT 789 | LNOT ''' 790 pass 791 792# postfix-expression: 793def p_postfix_expression_1(t): 794 'postfix_expression : primary_expression' --- 37 unchanged lines hidden (view full) --- 832 833# argument-expression-list: 834def p_argument_expression_list(t): 835 '''argument_expression_list : assignment_expression 836 | argument_expression_list COMMA assignment_expression''' 837 pass 838 839# constant: |
840def p_constant(t): | 840def p_constant(t): |
841 '''constant : ICONST 842 | FCONST 843 | CCONST''' 844 pass 845 846 847def p_empty(t): 848 'empty : ' 849 pass 850 851def p_error(t): | 841 '''constant : ICONST 842 | FCONST 843 | CCONST''' 844 pass 845 846 847def p_empty(t): 848 'empty : ' 849 pass 850 851def p_error(t): |
852 print "Whoa. We're hosed" | 852 print("Whoa. We're hosed") |
853 854import profile 855# Build the grammar 856 857yacc.yacc(method='LALR') 858 859#profile.run("yacc.yacc(method='LALR')") 860 861 862 863 | 853 854import profile 855# Build the grammar 856 857yacc.yacc(method='LALR') 858 859#profile.run("yacc.yacc(method='LALR')") 860 861 862 863 |