Exemple #1
0
def str2stmt(string, isfree=True, isstrict=False):
    """ Convert Fortran code to Statement tree.
    """
    from readfortran import Line, FortranStringReader
    from parsefortran import FortranParser
    reader = FortranStringReader(string, isfree, isstrict)
    parser = FortranParser(reader)
    parser.parse()
    parser.analyze()
    block = parser.block
    while len(block.content) == 1:
        block = block.content[0]
    return block
def str2stmt(string, isfree=True, isstrict=False):
    """ Convert Fortran code to Statement tree.
    """
    from readfortran import Line, FortranStringReader
    from parsefortran import FortranParser
    reader = FortranStringReader(string, isfree, isstrict)
    parser = FortranParser(reader)
    parser.parse()
    parser.analyze()
    block = parser.block
    while len(block.content)==1:
        block = block.content[0]
    return block
Exemple #3
0
def parse(input, isfree=None, isstrict=None, include_dirs=None):
    """ Parse input and return Statement tree.

    input            --- string or filename.
    isfree, isstrict --- specify input Fortran format.
                         Defaults are True, False, respectively, or
                         determined from input.
    include_dirs     --- list of include directories.
                         Default contains current working directory
                         and the directory of file name.
    """
    from parsefortran import FortranParser
    reader = get_reader(input, isfree, isstrict, include_dirs)
    parser = FortranParser(reader)
    parser.parse()
    parser.analyze()
    return parser.block
Exemple #4
0
def parse(input, isfree=None, isstrict=None, include_dirs = None):
    """ Parse input and return Statement tree.

    input            --- string or filename.
    isfree, isstrict --- specify input Fortran format.
                         Defaults are True, False, respectively, or
                         determined from input.
    include_dirs     --- list of include directories.
                         Default contains current working directory
                         and the directory of file name.
    """
    from parsefortran import FortranParser
    reader = get_reader(input, isfree, isstrict, include_dirs)
    parser = FortranParser(reader)
    parser.parse()
    parser.analyze()
    return parser.block
Exemple #5
0
for ffile in argset:
    print '@@@@@ '+ffile+' @@@@@ start -----'
    reader = FortranFileReader(ffile)
#


### test1 #############################################################
#    for i in getmembers(reader):
#        print i

### test2 #####################
    reader.set_mode(isfree=False,isstrict=False)
    parser=FortranParser(reader,ignore_comments=False)
    parser.parse()
    parser.analyze()
#    print parser.block.torepr(3)
#    print parser.block
    for i in dir(parser.block):
        print i
    print '----------------------'
    print 'aaa ',parser.block.name
    print 'aaa ',parser.block.blocktype

    ix=0
    for i in parser.block.content:
        ix=ix+1
        try:
            print 'zzzzzzzzz', ix,'  ',i.blocktype #,i.name,i.item #,i.a
            print ' a =',i.a
            iy=0
Exemple #6
0
def parse(input, isfree=None, isstrict=None, include_dirs = None, source_only = None,
          ignore_comments = True, analyze=True):
    """ Parse input and return Statement tree.

    Parameters
    ----------
    input : str
      Specify a string or filename containing Fortran code.
    isfree, isstrict : {None, bool}
      Specify input Fortran format. The values are determined from the
      input. If that fails then isfree=True and isstrict=False is assumed.
    include_dirs : {None, list}
      Specify a list of include directories. The default list (when
      include_dirs=None) contains the current working directory and
      the directory of ``filename``.
    source_only : {None, list}
      Specify a list of Fortran file names that are searched when the
      ``USE`` statement is encountered.
    ignore_comments : bool
      When True then discard all comment lines in the Fortran code.
    analyze : bool
      When True then apply run analyze method on the Fortran code tree.

    Returns
    -------
    block : `fparser.api.BeginSource`

    Examples
    --------

        >>> code = '''
        ... c comment
        ...       subroutine foo(a)
        ...         integer a
        ...         print*, "a=",a
        ...       end
        ... '''
        >>> tree = parse(code,isfree=False)
        >>> print tree
              !BEGINSOURCE <cStringIO.StringI object at 0x1798030> mode=fix90
                SUBROUTINE foo(a)
                  INTEGER a
                  PRINT *, "a=", a
                END SUBROUTINE foo
        >>> print `tree`
              BeginSource
                blocktype='beginsource'
                name='<cStringIO.StringI object at 0x1798030> mode=fix90'
                a=AttributeHolder:
              external_subprogram=<dict with keys ['foo']>
                content:
                  Subroutine
                    args=['a']
                    item=Line('subroutine foo(a)',(3, 3),'')
                    a=AttributeHolder:
                variables=<dict with keys ['a']>
                    content:
                      Integer
                        selector=('', '')
                        entity_decls=['a']
                        item=Line('integer a',(4, 4),'')
                      Print
                        item=Line('print*, "a=",a',(5, 5),'')
                  EndSubroutine
                    blocktype='subroutine'
                    name='foo'
            item=Line('end',(6, 6),'')

    See also
    --------
    get_reader
    """
    from parsefortran import FortranParser
    reader = get_reader(input, isfree, isstrict, include_dirs, source_only)
    parser = FortranParser(reader, ignore_comments = ignore_comments)
    parser.parse()
    if analyze:
        parser.analyze()
    return parser.block
Exemple #7
0
#         return item
#     except StopIteration:
#         return 'eof'
#     return

for ffile in argset:
    print '@@@@@ ' + ffile + ' @@@@@ start -----'
    reader = FortranFileReader(ffile)
    ### test1 #############################################################
    #    for i in getmembers(reader):
    #        print i
    ### test2 #####################
    reader.set_mode(isfree=False, isstrict=False)
    parser = FortranParser(reader, ignore_comments=False)
    parser.parse()
    parser.analyze()
    #    print parser.block.torepr(3)
    #    print parser.block
    #    for i in dir(parser.block):
    #        print i
    #print '----------------------'
    #print 'aaa ',parser.block.name
    #print 'aaa ',parser.block.blocktype
    ix = 0
    for i in parser.block.content:
        ix = ix + 1
        try:
            k = i.blocktype
            print lineall(i.item)  #i.name,i.a
            #print i.a.variable_names
            vardic = i.a.variables