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

推荐订阅源

WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Last Watchdog
The Last Watchdog
AI
AI
Webroot Blog
Webroot Blog
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog RSS Feed
小众软件
小众软件
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Vercel News
Vercel News
Y
Y Combinator Blog
P
Proofpoint News Feed
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
F
Fortinet All Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
MongoDB | Blog
MongoDB | Blog
SecWiki News
SecWiki News
The Register - Security
The Register - Security
博客园_首页
T
Threat Research - Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
I
InfoQ
雷峰网
雷峰网
C
Check Point Blog

博客园 - 大约在冬季

如何在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)    收藏  举报

刷新页面返回顶部