
    \h"                         S SK JrJrJr  S SKJr  S SKJr  \" S5      r\" SSS/0S9r	\(       a  S S	K
Jr  \	(       a  S S
KJr  \" SS/S9 " S S5      5       rg)    )pycodeccodefcode)import_module)doctest_depends_onlfortranzclang.cindexfromlistcindex)import_kwargs)src_to_sympy)parse_c)modulesc                   N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )SymPyExpression   a7  Class to store and handle SymPy expressions

This class will hold SymPy Expressions and handle the API for the
conversion to and from different languages.

It works with the C and the Fortran Parser to generate SymPy expressions
which are stored here and which can be converted to multiple language's
source code.

Notes
=====

The module and its API are currently under development and experimental
and can be changed during development.

The Fortran parser does not support numeric assignments, so all the
variables have been Initialized to zero.

The module also depends on external dependencies:

- LFortran which is required to use the Fortran parser
- Clang which is required for the C parser

Examples
========

Example of parsing C code:

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src = '''
... int a,b;
... float c = 2, d =4;
... '''
>>> a = SymPyExpression(src, 'c')
>>> a.return_expr()
[Declaration(Variable(a, type=intc)),
Declaration(Variable(b, type=intc)),
Declaration(Variable(c, type=float32, value=2.0)),
Declaration(Variable(d, type=float32, value=4.0))]

An example of variable definition:

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src2 = '''
... integer :: a, b, c, d
... real :: p, q, r, s
... '''
>>> p = SymPyExpression()
>>> p.convert_to_expr(src2, 'f')
>>> p.convert_to_c()
['int a = 0', 'int b = 0', 'int c = 0', 'int d = 0', 'double p = 0.0', 'double q = 0.0', 'double r = 0.0', 'double s = 0.0']

An example of Assignment:

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src3 = '''
... integer :: a, b, c, d, e
... d = a + b - c
... e = b * d + c * e / a
... '''
>>> p = SymPyExpression(src3, 'f')
>>> p.convert_to_python()
['a = 0', 'b = 0', 'c = 0', 'd = 0', 'e = 0', 'd = a + b - c', 'e = b*d + c*e/a']

An example of function definition:

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src = '''
... integer function f(a,b)
... integer, intent(in) :: a, b
... integer :: r
... end function
... '''
>>> a = SymPyExpression(src, 'f')
>>> a.convert_to_python()
['def f(a, b):\n   f = 0\n    r = 0\n    return f']

c                   > [         TU ]  5         U(       d  U(       d  / U l        gU(       a  U(       a  UR                  5       S:X  a'  [        (       a  [        U5      U l        g[        S5      eUR                  5       S:X  a'  [        (       a  [        U5      U l        g[        S5      e[        S5      e[        S5      e[        S5      e)	z%Constructor for SymPyExpression classf4LFortran is not installed, cannot parse Fortran codec+Clang is not installed, cannot parse C codez0Parser for specified language is not implementedzSource code not presentz$Please specify a mode for conversionN)super__init___exprlowerr   r   ImportErrorcinr   NotImplementedError
ValueError)selfsource_codemode	__class__s      N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/parsing/sym_expr.pyr   SymPyExpression.__init__^   s    {DJ::<3&x%1+%>
)*`aaZZ\S(s%,[%9
)*WXX-J  !!:;;CDD    c                    UR                  5       S:X  a'  [        (       a  [        U5      U l        g[	        S5      eUR                  5       S:X  a'  [
        (       a  [        U5      U l        g[	        S5      e[        S5      e)au  Converts the given source code to SymPy Expressions

Attributes
==========

src_code : String
    the source code or filename of the source code that is to be
    converted

mode: String
    the mode to determine which parser is to be used according to
    the language of the source code
    f or F for Fortran
    c or C for C/C++

Examples
========

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src3 = '''
... integer function f(a,b) result(r)
... integer, intent(in) :: a, b
... integer :: x
... r = a + b -x
... end function
... '''
>>> p = SymPyExpression()
>>> p.convert_to_expr(src3, 'f')
>>> p.return_expr()
[FunctionDefinition(integer, name=f, parameters=(Variable(a), Variable(b)), body=CodeBlock(
Declaration(Variable(r, type=integer, value=0)),
Declaration(Variable(x, type=integer, value=0)),
Assignment(Variable(r), a + b - x),
Return(Variable(r))
))]




r   r   r   r   z6Parser for specified language has not been implementedN)r   r   r   r   r   r   r   r   )r   src_coder!   s      r#   convert_to_exprSymPyExpression.convert_to_exprx   sk    R ::<3x)(3
!"XYYZZ\S s$X.
!"OPP%H r%   c                     / U l         U R                   H'  nU R                   R                  [        U5      5        M)     U R                   $ )a  Returns a list with Python code for the SymPy expressions

Examples
========

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src2 = '''
... integer :: a, b, c, d
... real :: p, q, r, s
... c = a/b
... d = c/a
... s = p/q
... r = q/p
... '''
>>> p = SymPyExpression(src2, 'f')
>>> p.convert_to_python()
['a = 0', 'b = 0', 'c = 0', 'd = 0', 'p = 0.0', 'q = 0.0', 'r = 0.0', 's = 0.0', 'c = a/b', 'd = c/a', 's = p/q', 'r = q/p']

)_pycoder   appendr   r   iters     r#   convert_to_python!SymPyExpression.convert_to_python   s9    ( JJDLLt- ||r%   c                     / U l         U R                   H'  nU R                   R                  [        U5      5        M)     U R                   $ )a  Returns a list with the c source code for the SymPy expressions


Examples
========

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src2 = '''
... integer :: a, b, c, d
... real :: p, q, r, s
... c = a/b
... d = c/a
... s = p/q
... r = q/p
... '''
>>> p = SymPyExpression()
>>> p.convert_to_expr(src2, 'f')
>>> p.convert_to_c()
['int a = 0', 'int b = 0', 'int c = 0', 'int d = 0', 'double p = 0.0', 'double q = 0.0', 'double r = 0.0', 'double s = 0.0', 'c = a/b;', 'd = c/a;', 's = p/q;', 'r = q/p;']

)_ccoder   r,   r   r-   s     r#   convert_to_cSymPyExpression.convert_to_c   s9    , JJDKKuT{+ {{r%   c                     / U l         U R                   H'  nU R                   R                  [        U5      5        M)     U R                   $ )a)  Returns a list with the fortran source code for the SymPy expressions

Examples
========

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src2 = '''
... integer :: a, b, c, d
... real :: p, q, r, s
... c = a/b
... d = c/a
... s = p/q
... r = q/p
... '''
>>> p = SymPyExpression(src2, 'f')
>>> p.convert_to_fortran()
['      integer*4 a', '      integer*4 b', '      integer*4 c', '      integer*4 d', '      real*8 p', '      real*8 q', '      real*8 r', '      real*8 s', '      c = a/b', '      d = c/a', '      s = p/q', '      r = q/p']

)_fcoder   r,   r   r-   s     r#   convert_to_fortran"SymPyExpression.convert_to_fortran   s9    ( JJDKKuT{+ {{r%   c                     U R                   $ )a>  Returns the expression list

Examples
========

>>> from sympy.parsing.sym_expr import SymPyExpression
>>> src3 = '''
... integer function f(a,b)
... integer, intent(in) :: a, b
... integer :: r
... r = a+b
... f = r
... end function
... '''
>>> p = SymPyExpression()
>>> p.convert_to_expr(src3, 'f')
>>> p.return_expr()
[FunctionDefinition(integer, name=f, parameters=(Variable(a), Variable(b)), body=CodeBlock(
Declaration(Variable(f, type=integer, value=0)),
Declaration(Variable(r, type=integer, value=0)),
Assignment(Variable(f), Variable(r)),
Return(Variable(f))
))]

)r   )r   s    r#   return_exprSymPyExpression.return_expr   s    4 zzr%   )r2   r   r6   r+   )NN)__name__
__module____qualname____firstlineno____doc__r   r(   r/   r3   r7   r:   __static_attributes____classcell__)r"   s   @r#   r   r      s/    M^E46p262 r%   r   N)sympy.printingr   r   r   sympy.externalr   sympy.utilities.decoratorr   r   r   $sympy.parsing.fortran.fortran_parserr   sympy.parsing.c.c_parserr   r    r%   r#   <module>rI      s^    / / ( 8$NZ(4LMA0Z89I I :Ir%   