Changeset 391 for python/trunk/Grammar


Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Grammar/Grammar

    r2 r391  
    1111# "How to Change Python's Grammar"
    1212
    13 # Commands for Kees Blom's railroad program
    14 #diagram:token NAME
    15 #diagram:token NUMBER
    16 #diagram:token STRING
    17 #diagram:token NEWLINE
    18 #diagram:token ENDMARKER
    19 #diagram:token INDENT
    20 #diagram:output\input python.bla
    21 #diagram:token DEDENT
    22 #diagram:output\textwidth 20.04cm\oddsidemargin  0.0cm\evensidemargin 0.0cm
    23 #diagram:rules
    24 
    2513# Start symbols for the grammar:
    26 #       single_input is a single interactive statement;
    27 #       file_input is a module or sequence of commands read from an input file;
    28 #       eval_input is the input for the eval() and input() functions.
     14#       single_input is a single interactive statement;
     15#       file_input is a module or sequence of commands read from an input file;
     16#       eval_input is the input for the eval() and input() functions.
    2917# NB: compound_stmt in single_input is followed by extra NEWLINE!
    3018single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
     
    8169try_stmt: ('try' ':' suite
    8270           ((except_clause ':' suite)+
    83             ['else' ':' suite]
    84             ['finally' ':' suite] |
    85            'finally' ':' suite))
    86 with_stmt: 'with' test [ with_var ] ':' suite
    87 with_var: 'as' expr
     71            ['else' ':' suite]
     72            ['finally' ':' suite] |
     73           'finally' ':' suite))
     74with_stmt: 'with' with_item (',' with_item)* ':' suite
     75with_item: test ['as' expr]
    8876# NB compile.c makes sure that the default except clause is last
    8977except_clause: 'except' [test [('as' | ',') test]]
     
    113101factor: ('+'|'-'|'~') factor | power
    114102power: atom trailer* ['**' factor]
    115 atom: ('(' [yield_expr|testlist_gexp] ')' |
     103atom: ('(' [yield_expr|testlist_comp] ')' |
    116104       '[' [listmaker] ']' |
    117        '{' [dictmaker] '}' |
     105       '{' [dictorsetmaker] '}' |
    118106       '`' testlist1 '`' |
    119107       NAME | NUMBER | STRING+)
    120108listmaker: test ( list_for | (',' test)* [','] )
    121 testlist_gexp: test ( gen_for | (',' test)* [','] )
     109testlist_comp: test ( comp_for | (',' test)* [','] )
    122110lambdef: 'lambda' [varargslist] ':' test
    123111trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
     
    127115exprlist: expr (',' expr)* [',']
    128116testlist: test (',' test)* [',']
    129 dictmaker: test ':' test (',' test ':' test)* [',']
     117dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
     118                  (test (comp_for | (',' test)* [','])) )
    130119
    131120classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
     
    134123                         |'*' test (',' argument)* [',' '**' test]
    135124                         |'**' test)
    136 argument: test [gen_for] | test '=' test  # Really [keyword '='] test
     125# The reason that keywords are test nodes instead of NAME is that using NAME
     126# results in an ambiguity. ast.c makes sure it's a NAME.
     127argument: test [comp_for] | test '=' test
    137128
    138129list_iter: list_for | list_if
     
    140131list_if: 'if' old_test [list_iter]
    141132
    142 gen_iter: gen_for | gen_if
    143 gen_for: 'for' exprlist 'in' or_test [gen_iter]
    144 gen_if: 'if' old_test [gen_iter]
     133comp_iter: comp_for | comp_if
     134comp_for: 'for' exprlist 'in' or_test [comp_iter]
     135comp_if: 'if' old_test [comp_iter]
    145136
    146137testlist1: test (',' test)*
Note: See TracChangeset for help on using the changeset viewer.