惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 大约在冬季

如何在IronPython中使用C#扩展方法 LINQ入门教程示例使用F#的实现 宝宝照片更新喽 再谈两种不同字符串比较方法的性能对比 - 大约在冬季 - 博客园 如何让DevExpress.TreeList单元格中的自定义控件包含标签 见证中国A股市场:上午大盘加速寻底 沪指跌129点,探低至4241.02 漂亮宝宝100天啦!庆祝一下! F# 学习笔记(1/n) 权重股杀跌沪指半日破两关跌135点 WCF服务契约 听课笔记 最近性能优化一些感触,分享中…… 两种不同字符串比较方法的性能对比 .Net 事件类型的实现和推荐做法 设计时支持:如何获取环境数据 如何在C#中调用 IronPython 代码 (基于IronPython 2.0A3) 运行Oracle数据库配置向导创建数据库失败ORA-24324的解决方案 C#3.0 自动属性——只能在简单属性上偷懒 性能——换个角度看问题 设计模式的滋味
IronPyton分析表达式
大约在冬季 · 2007-11-07 · via 博客园 - 大约在冬季

全部代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using IronPython.Runtime;
using IronPython.Compiler;
using IronPython.Compiler.Ast;

namespace ConsoleApplication1 {
    
class Program {
        
static void Main(string[] args) {
            
//string expression = "Sum(ActiveObject.Parent.Discount*ActiveObject.PrimePrice*Amount)";
            string expression = "Sum(ActiveObject.Parent.Details,\"Money\")*ActiveObject.ExchangeRate";
            SystemState state 
= new SystemState();
            CompilerContext context 
= new CompilerContext();
            Parser p 
= Parser.FromString(state, context, expression);
            IronPython.Compiler.Ast.Expression ex 
= p.ParseTestListAsExpression();
            MyWalker w 
= new MyWalker();
            ex.Walk(w);
            
foreach (string item in w._expressions) {
                Console.WriteLine(item);                
            }

            Console.ReadLine();

        }

        
class MyWalker : AstWalker {
            
private Stack<string> _stack;
            
public List<string> _expressions;
            
public MyWalker() {
                _stack 
= new Stack<string>();
                _expressions 
= new List<string>();
            }

            
public override bool Walk(FieldExpression node) {
                
//        node.Target.ToString()    "IronPython.Compiler.Ast.FieldExpression:Parent"    string
                
//        node.Name.ToString()    "Discount"    string
                string name = node.Name.ToString();
                
if (_stack.Count > 0{
                    
if (_stack.Peek() != name) {
                        _stack.Push(name);
                    }

                }

                
else {
                    _stack.Push(name);
                }

                
string[] temps = node.Target.ToString().Split(':');
                
string target = temps[1];
                _stack.Push(target);
                
if (target == "ActiveObject"{
                    
//弹出
                    StringBuilder expressionBuilder = new StringBuilder();
                    
while (_stack.Count > 1{
                        expressionBuilder.Append(_stack.Pop())
                       .Append(
".");
                    }

                    expressionBuilder.Append(_stack.Pop());
                    _expressions.Add(expressionBuilder.ToString());
                }

                
                
//Console.WriteLine("NodeName = "+node.Name + ",      NodeTrage = " + node.Target);
                
                

                
return base.Walk(node);
            }


            
public override bool Walk(ConstantExpression node) {
                
int lastIndex = this._expressions.Count - 1;
                
if (lastIndex > -1{
                    
this._expressions[lastIndex] = this._expressions[lastIndex] + "." + node.Value.ToString();
                }

                
return base.Walk(node);
            }


        }

    }

}

posted @ 2007-11-07 15:23  大约在冬季  阅读(260)  评论(0)    收藏  举报

刷新页面返回顶部