Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Yet another attempt at a safe eval() call Date: Fri, 4 Jan 2013 18:43:46 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 24 Message-ID: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1357325026 27122 64.122.56.22 (4 Jan 2013 18:43:46 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 4 Jan 2013 18:43:46 +0000 (UTC) User-Agent: slrn/pre1.0.0-18 (Linux) X-Received-Bytes: 2233 Xref: csiph.com comp.lang.python:36130 On 2013-01-04, Chris Angelico wrote: > On Sat, Jan 5, 2013 at 5:09 AM, Grant Edwards wrote: >> The error messages are still pretty cryptic, so improving >> that will add a few more lines. One nice thing about the ast code is >> that it's simple to add code to allow C-like character constants such >> that ('A' === 0x41). Here's the first pass at ast-based code: > > Looks cool, and fairly neat! Now I wonder, is it possible to use that > to create new operators, such as the letter d? Binary operator, takes > two integers... I don't think you can define new operators. AFAICT, the lexing/parsing is done using the built-in Python grammar. You can control the behavior of the predefined operators and reject operators you don't like, but you can't add new ones or change precedence/syntax or anything like that. If you want to tweak the grammar itself, then I think you need to use something like pyparsing. -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank!