ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] Re: Algebraic symbol manipulation program idea
by Danny Yoo other posts by this author
Aug 19 2001 7:14AM messages near this date
[Tutor] Re: Algebraic symbol manipulation program idea | Re: [Tutor] Re: Algebraic symbol manipulation program idea
On Fri, 10 Aug 2001, Christopher Smith wrote:

>  When given 2*3+2^2/3 Pythonica returns:
>  
>  	in FullForm: Divide[Plus[Times[2,3],Power[2,2]],3]
>  	evaluates to: 3.33333333333
>  
>  but it should probably be something like:
>  
>  	Plus[Times[2,3],Divide[Power[2,2],3]]
>  
>  and evaluate to 7.33333333333

[I'm not quite sure if my message is appropriate on tutor, but perhaps
someone is interested in recursive descent parsing.  Recursive descent
parsing is a technique that's used to try converting arithmetic
expressions into a form that's supposedly easy to work with.  *grin*]


Pythonica seems pretty interesting!  I'm taking a closer look at this now.  
Does anyone have a formal context free grammar for Pythonica or
Mathematica?  I'm working on a Pythonica recursive descent parser now to
fix this bug.  Here's the link to what I have so far:

    http://hkn.eecs.berkeley.edu/~dyoo/python/pythonica/


As a warning, this is ROUGH code; it doesn't even connect to Pythonica
yet.  For now, PythonicaParser.py can only build the parse tree for simple
arithmetic expressions.  Here's a sample run:

###
dyoo@einfall:~/pythonica$ python PythonicaParser.py
> >> 3 * 4 + 5 * (foo + bar)
['Expression',
 ['Term',
  ['Factor', 'NUMBER', '3'],
  ['Term1', '*', ['Factor', 'NUMBER', '4'], None]],
 ['Expression1',
  '+',
  ['Term',
   ['Factor', 'NUMBER', '5'],
   ['Term1',
    '*',
    ['Factor',
     'GROUP',
     ['Expression',
      ['Term', ['Factor', 'IDENTIFIER', 'foo'], None],
      ['Expression1',
       '+',
       ['Term', ['Factor', 'IDENTIFIER', 'bar'], None],
       None]]],
    None]],
  None]]
None
###

I'll see if I can coax it to handle more interesting things like
exponentiation tonight.  *grin*


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Christopher Smith
Danny Yoo
Roeland Rengelink
Roeland Rengelink

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved