How to build language processors in a pure functional .ppt

上传人:赵齐羽 文档编号:376413 上传时间:2018-10-08 格式:PPT 页数:9 大小:37.50KB
下载 相关 举报
How to build language processors in a pure functional .ppt_第1页
第1页 / 共9页
How to build language processors in a pure functional .ppt_第2页
第2页 / 共9页
How to build language processors in a pure functional .ppt_第3页
第3页 / 共9页
How to build language processors in a pure functional .ppt_第4页
第4页 / 共9页
How to build language processors in a pure functional .ppt_第5页
第5页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、How to build language processors in a pure functional programming language,Recognizers for terminals,term wd (tok:toks) = toks, if tok = wd= , otherwise term x = e.g. term “one” “one”,“two”,“three”= “two”,”three”term “two” “one”,“two”,“three” = Now one = term “one” two = term “two”plus = term “+” et

2、c,Recognizers alternatives,(p $orelse q) toks = p toks + q tokse.g.one $orelse two “one”,”four” = “four”one $orelse two “two”,”six” = “six”one $orelse two “three”,”six” = num = one $orelse two $orelse three ,Recognizers sequence,(p $then q) toks = concat (map p (q toks)e.g.(one $then two) “one”,”two

3、”,”three” = “three”(one $then two) “one”,”six”,”four” = num $then num “one”,”two”,”three” = “three”,Recognizers complex,add_seq = num $orelse (num $then plus $then add_seq)e.g.add_seq “one”,”+”,”three”,”+”,“six”= “+”,”three”,“+”,”six”,“+”,”six”, add_seq “plus”,”six”,”four” = ,Interpreters for termin

4、als,term (wd,val) (tok:toks) = (val,toks), if tok = wd= , otherwise term x = e.g. term (“one”,1) “one”,“two”,“three”= (1,“two”,”three”)Now one = term (“one”,1) two = term (“two”,2)plus = term (“+”,(+) etc,Interpreters alternatives,(p $orelse q) toks = p toks + q tokse.g.one $orelse two “one”,”four”

5、= (1,“four”)one $orelse two “two”,”six” = (2,“six”)one $orelse two “three”,”six” = num = one $orelse two $orelse three ,Interpreters sequence,(p1 $then p2) toks = (v1,v2),t2) | (v1,t1) (1,2),“three”)(one $then plus $then two) “one”,”plus”,”two”.”three”= (1,(+),2),“three”),Interpreters complex,add_seq = num $orelse (num $then plus $then add_seq) $apply_rule app_op)(p $applyrule f) inp = (f v, r) | (v, r) (1,“+”,”three”,“+”,”six”),(4,“+”,”six”),(10,) ,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学课件 > 大学教育

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1