由买买提看人间百态

topics

全部话题 - 话题: lexer
1 (共1页)
e*****r
发帖数: 379
1
有编过lexer/parser generator 的大牛没有?帮忙看看cmake的lexer.没看懂。脸红中
。 跟java/C#比起来,C++/C 真是稀奇古怪的恐龙级别的语言。
g******a
发帖数: 730
2
3x a lot.:P
But as far as I see, it's a parser/lexer for java
I need a parser/lexer for C, but written in Java.
Is there any such tool?
c*****t
发帖数: 1879
3
来自主题: Programming版 - any lexer/parser enthusiasts here?
还是小意思。我个人 3-4 星期的工作量。主要加一个 target language 比较费
神。毕竟又快又好的 lexer/parser 里面可以 optimize 的地方很多。
刚刚弄出个 0.3 release 。有个比较 unique 的写 lexer/parser 的办法。可
惜,有人 98 年就在 Python 上弄了个类似的(虽然差了点)。遗憾的是,好像
没人注意到。我是写完才发现。现在 Antlr/JavaCC 等还是用比较古老的办法写。
g******a
发帖数: 730
4
好像有点怪:)
我以前的lexer使用Python写的
不想重新写了
如果能在java里用python的模块也行
多谢
c*****t
发帖数: 1879
5
来自主题: Programming版 - any lexer/parser enthusiasts here?
Ha, good.
I created a new project called CookCC (hosted on google code) which
contains both lexer and parser generator (lalr (1) only). It's
written in Java. It basically replaces my yoolex and yooparse projects
I wrote N years ago, since Java is much easier to maintain and extend.
Right now I am working on the Java code generation using FreeMarker
template. I am wondering if anyone wants to join me on this project
to work on code generation for other languages, or assist in testing.
The perf
t**r
发帖数: 3428
6
作paser,lexer就用antlr把,别折腾yacc,bison了 累
c****x
发帖数: 6601
7
发信人: MoneyPort (MoneyPort), 信区: Programming
标 题: 王垠:我为什么不在乎人工智能
发信站: BBS 未名空间站 (Thu Apr 27 18:20:23 2017, 美东)
来源:王垠
www.yinwang.org/blog-cn/2017/04/23/ai
如有好文章投稿,请点击 → 这里了解详情
有人听说我想创业,给我提出了一些“忽悠”的办法。他们说,既然你是程序语言专家
,而现在人工智能(AI)又非常热,那你其实可以搞一个“自动编程系统”,号称可以
自动生成程序,取代程序员的工作,节省许许多多的人力支出,这样就可以趁着“AI
热”拉到投资。
有人甚至把名字都给我想好了,叫“深度程序员”(DeepCoder = Deep Learning +
Coder)。口号是:“有了 DeepCoder,不用 Top Coder!” 还有人给我指出了这方向
最新的,吹得神乎其神的研究,比如微软的 Robust Fill……
我谢谢这些人的关心,然而其实我并不在乎,也不看好人工智能。现在我简单的讲一下
我的看法。
机器一样的心
很多人喜欢鼓吹人工... 阅读全帖
c*****t
发帖数: 1879
8
I want to introduce a new way of dealing with file pattern matching.
This is using a project called CookCC which I started.
Basically, instead of writing complicated lexer patterns using Pattern
for non-trivial text files, it is actually easier to write a lexer/parser
using CookCC. However, the traditional way of writing lexer/parser
(such as using Antlr / JavaCC) is that you are writing code in a
proprietary file format that doesn't have good Java editing.
So here is how CookCC does it. I am
M*******t
发帖数: 189
9
来自主题: Programming版 - 王垠:我为什么不在乎人工智能
来源:王垠
www.yinwang.org/blog-cn/2017/04/23/ai
如有好文章投稿,请点击 → 这里了解详情
有人听说我想创业,给我提出了一些“忽悠”的办法。他们说,既然你是程序语言专家
,而现在人工智能(AI)又非常热,那你其实可以搞一个“自动编程系统”,号称可以
自动生成程序,取代程序员的工作,节省许许多多的人力支出,这样就可以趁着“AI
热”拉到投资。
有人甚至把名字都给我想好了,叫“深度程序员”(DeepCoder = Deep Learning +
Coder)。口号是:“有了 DeepCoder,不用 Top Coder!” 还有人给我指出了这方向
最新的,吹得神乎其神的研究,比如微软的 Robust Fill……
我谢谢这些人的关心,然而其实我并不在乎,也不看好人工智能。现在我简单的讲一下
我的看法。
机器一样的心
很多人喜欢鼓吹人工智能,自动车,机器人等技术,然而如果你仔细观察,就会发现这
些人不但不理解人类智能是什么,不理解人工智能有什么局限性,而且这些“AI 狂人
”们的心,已经严重的机械化了。他们或多或少的失去了人性,仿佛忘记了自己是一个
人,... 阅读全帖
h*h
发帖数: 27852
10
http://www.yinwang.org/blog-cn/2015/03/18/yin-lang-secret
我为什么不再公开开发Yin语言
有些人可能知道我在设计一个程序语言,叫做Yin语言。最开头宣布要做这个语言的时
候,很多人热血沸腾,可是过了不久,我发现自己很不喜欢这样的气氛,越来越厌倦跟
人讨论,所以后来悄悄地丢掉这些人,淡出了。我现在想告诉你我是怎么想的。
我从来没有想让Yin语言流行起来。我对程序语言的认识,其实超乎所有人的想象。我
默默地看着各种新语言扯着各种幌子进行推广,可是它们的设计没有吸取历史教训,所
以继续犯一些古老的错误,或者犯一些我根本不会犯的新错误,或者解决一些根本不需
要解决的问题。其实程序语言已经不缺很多新的功能了,这些语言缺少的不是功能,而
是简单和优雅。要达到简单和优雅,必须要有品位,而品位就像一个艺术家的心,是非
常难得到的。没有经过Indiana式教育的人,是几乎不可能达到这种品位的。就算
Friedman培养出来的那么多学生,也极少有人可以达到我这种地步。
我清楚的知道,其它语言设计者是完全没法达到我的一些精华思想的。我其实很懒,我
希... 阅读全帖
S*A
发帖数: 7142
11
来自主题: SanFrancisco版 - 我对Google的ex CEO Eric Schmidt一点评价

?)
In Coders at Work, Ken Thompson talks to Peter Seibel about yacc and lex:
Seibel: And are there development tools that just make you happy to
program?
Thompson: I love yacc. I just love yacc. It just does exactly what you
want done. Its complement, lex, is horrible. It does nothing you want done.
Seibel: Do you use it anyway or do you write your lexers by hand?
Thompson: I write my lexers by hand. Much easier.
n******m
发帖数: 644
12
来自主题: WaterWorld版 - 写我自己的留学生活——裘法祖
【编者注:本文是裘法祖先生自传《写我自己》的节选,记录了裘老70多年前留学德国
的经历。裘法祖是中国著名外科专家、华中科技大学同济医学院教授、博士生导师,
1993年当选为中国科学院院士。裘教授从事外科医疗、教学、科研工作60余载,发表医
学论文200余篇,主持编写医学教材40余本,2008年6月病逝于武汉。】
裘法祖,中国科学院院士、著名外科学家
从上海到德国慕尼黑
二十世纪30年代要去欧洲,没有飞机,也不能乘火车经西伯利亚前去,只可走海路,即
乘船经印度洋、红海、苏伊士运河、地中海到欧洲。在轮船上我们住的是经济舱,两张
上下铺,一张小桌。海上的生活是无聊乏味的,虽然每到一个大港口,例如香港、孟买
,可以上岸去片刻观光,但这是有钱中国人的享受;我们没有钱,只好站在甲板上遥望
港口的车水马龙。那几个有钱的中国人,白天打麻将,住得好、吃得好,我们一想就来
个白天睡觉,晚上向他们借来麻将牌打麻将。就这样经过了一个多月的航行,轮船终于
抵达了目的地——意大利威尼斯。下船的那天,在早餐后看到餐厅的侍者站在餐厅门口
收小费,有钱的人给的是50或100美元;我们没有钱,谢毓晋说:只给10美元,我们... 阅读全帖
c*****t
发帖数: 1879
13
来自主题: Java版 - interesting
See this example:
http://code.google.com/p/cookcc/source/browse/#svn/trunk/tests/javaap/nestedclass
And look at WC1.java and WC1$Lexer.java.orig (added .orig for backup
purpose). This WC1$Lexer.java would be replaced by code generated
from a compiler-compiler.
It is not a good approach in general I agree, but I do see that it
makes it possible to organize files.
c*****t
发帖数: 1879
14
来自主题: Java版 - Design thought.. Sugguestions?
This is a long post...
I am trying to update CookCC (a lexer / parser generator in Java) for
a new feature.
One existing CookCC feature is that one can specify the lexer pattern
and parser grammar in Java annotations. For example:
@CookCCOption
class MyParser extends GeneratedParser
{
@Lex (pattern = "[_A-Za-z][_A-Za-z0-9]*", state = "INITIAL")
String scanIdentifier ()
{
return yyText ();
}
@Rules (rules = {
@Rule (lhs = "Expr", rhs = "Expr '+' Expr"),
c*******a
发帖数: 1879
15
/**
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
*
* @author FangYidong<[email protected]>
*/
public class JSONParser {
public static final int S_INIT=0;
public static final int S_IN_FINISHED_VALUE=1;//string,number,boolean,
null,object,array
public static final int S_IN_OBJECT=2;
public static final int S_IN_ARRAY=3;
public static final int S_PASSED_PAIR_KEY=4;
public static final int S_IN_PAIR_VALUE=5;
public static final int S_END=6;... 阅读全帖
w****l
发帖数: 535
16
来自主题: TVGame版 - 跟风说十个我的最爱PC游戏
永远的the edge, duel和tdm都是经典
q2的王者,伟大的Dennis "Thresh" Fong,万年老二makaveli
q3的一个个霸主 Fata1ity, cooller, zero4, czm
和闪耀的群星 socrates, daler, fox, polosatiy, unkind, lexer, lakerman, blue,
SteLam, prozac, python, Z4muZ

还有咱们的rb和jibo
N*****m
发帖数: 42603
17
是的,真马工都自己写lexer
b******p
发帖数: 49
18
如题所示,C++ Grandmaster
网址在这里: cppgm.org
我不是CS专业出身,没写过编译器,对编译器的了解仅限于完成了coursera上面的
CS143。
只是大概知晓了概念,对于更深的内容比如静态/动态分析/优化就不了解了。
这个C++ Grandmaster看起来并不是研究型的,而是比较工程化的一个项目,要从头写
lexer/parser/codegen,而不需优化。
网上有各种议论,有说能做出来的,有说这是个big joke的。但无论别人怎么说,楼主
已经开始蚂蚁撼大树,做了PA1。按官方网上的说法,PA1只占总共的5%左右。
我也不知道能不能做出来,应该是很可能没时间所以做不出来。但是直到做不下去那一
天我都会抽空弄这个。
我想问问有没有人对这个东西感兴趣或是也在弄的,因为我自己写code写得比较烂,碰
到一些难以谷歌搜索的问题如果能讨论将感到不胜幸运。
m***r
发帖数: 29
19
来自主题: Java版 - JavaCC/SableCC/otherCC ?
I am now trying to extend Java. In addition to lexer and parser,
I need one function that can inference the type of expression
for java. Or, better if it can give the type range during parsing.
No other requirement. Any guru know such tools?
I checked JavaCC, SableCC, and some other tools, But can not find
such capability. Is there any third implementation based on such
CC tools, such as a Compiler-Compiler based full java compiler (in
which there must be such functions)? I say CC-based because
c*****t
发帖数: 1879
20
来自主题: Java版 - JSP is rubbish!
Not being able to compile greater than 64K byte code is really a problem
in certain applications. Mainly in the lexers and parsers where large
precomputed tables is stored and could easily exceed 64K.
o**v
发帖数: 1662
o**v
发帖数: 1662
22
我看错了你的问题,呵呵
不知道.
g******a
发帖数: 730
23
hehe
3x anyway. :)
z***y
发帖数: 42
24
javacc. (like LEX/YACC)
They have C grammar available.
c*****s
发帖数: 214
25
最流行的当然是antlr: http://antlr.org , C/C++的Parser有现成的
java的python解释可以用jython http://www.jython.org 。但这个只是语言解释器,不

用来调现有的python模块。
j******r
发帖数: 201
26
javacc website has it.
c*****t
发帖数: 1879
27
SAX = a lexer that parse an XML document into tokens and generate
events on the token recieved. As you can imagine, there will
be continuous streams of events. Thus, some call SAX stream
or SAX event driven etc.
The SAX engine provided by JDK sucks. No hooks for custom entities
unless the XML document explicitly contains the DTD spec.
DOM = a generated tree of objects (think of DOM tree for html elements
in web browser, only this is for all XML documents).
Crimson/Xerc
c*****t
发帖数: 1879
28
来自主题: Java版 - Design thought.. Sugguestions?
这个问题并不是在问 compiler 的问题啊。问的是 design 类的问题。
也就是说,有 N 个 interface / impl,因为某个原因,其中的 impl 需要
call 某个 class (generated)的一系列 function (lexer functions),
问的是,如何简单有效的将这些 impl 和该 class 联系起来,尽量减少
impl 得写的部分。
c*****t
发帖数: 1879
29
来自主题: Programming版 - any lexer/parser enthusiasts here?
Just curious.
I**********s
发帖数: 441
30
来自主题: Programming版 - any lexer/parser enthusiasts here?
I work on parser generation.
What do you want to talk about?
I**********s
发帖数: 441
31
来自主题: Programming版 - any lexer/parser enthusiasts here?
I just sent an email to your mailbox.
c*****t
发帖数: 1879
32
来自主题: Programming版 - any lexer/parser enthusiasts here?
所有在这里的 test case 都是测试过的(不过 parser 部分还在 svn 里,
我现在还差将 compressed table 放进 code generator)。
http://code.google.com/p/cookcc/source/browse/trunk/tests/
code generator 现在只有 Java 。其实弄 C/C++ 也不是太难(毕竟是
template approach)。
现在用的是 xml 输入。主要是 yacc/lex 的输入文件其实很复杂。手工写
parser 太困难。至于自动 generate,俺不正在写嘛。
至于 mix 代码和 grammar 。我有个想法,不适合 C/C++,但是很适合
Java / C# / Python 。这样可以直接利用现成的 Java/C#/Python editor
(同时该 editor 的功能,比如 refactoring,context sensitive help
等)。我已经手工推出个 prototype,就差 implementation 。
z*****m
发帖数: 119
33
来自主题: Programming版 - any lexer/parser enthusiasts here?
为什么不用ANTLR? 要自己写一个?
c*****t
发帖数: 1879
34
来自主题: Programming版 - any lexer/parser enthusiasts here?
ANTLR 是 LL。另外我觉得其方法(单 Java 而言)其实并不是很理想。
还有些 engineering 方面的问题。
有些我还不能具体说,等弄出来在说吧 :)
T*****9
发帖数: 2484
35
来自主题: Programming版 - any lexer/parser enthusiasts here?
我有兴趣
T*****9
发帖数: 2484
36
来自主题: Programming版 - any lexer/parser enthusiasts here?
你这玩意规模不小啊
c*****t
发帖数: 1879
37
来自主题: Programming版 - 多次调用yyarse()的buffer flush问题。
你找错方向了。
一般来说,跟 lexer 没关系。你最多改下 input 的 source 和 dfa state (回到
initial)而已。
至于 parser,我建议你仔细读下 bison 里面的 error handling 。里面讲的比较详
细。你要做的是 clear token stack 和 lookahead / error flag 。
a*****e
发帖数: 1700
38
来自主题: Programming版 - functional programming?
你有这样的感觉没错,Python 的这些概念都来源于 FP,事实上,从 Lisp 引入 GC 开
始,非常多的 FP 的特征,已经越来越普遍地进入到其它非 FP 的语言。
我想你要问的是,既然这样,为什么要学习 Haskell 或者 FP?
我给几个 Haskell 有,但是你在 python 里面学不到的东西吧:
1. Strong type system
duck typing 看似更灵活,但是实际上它只是一个 sum of all types,没办法保证
type safty。有时候更 general 不是好事情,反而是有限制,尤其是编译器能够通过
静态检查就能确保程序遵守了这些限制,更有益处。举个例子,很多语言都有 SQL 的
库可用,但有几个能够静态检查,确保所有发出的 SQL 查询都是合法的?再比如,一
个程序需要处理平衡二叉树,你能够通过静态检查就确保不会发生不平衡的情况出现吗
?这些只有强类型的 abstract datatype 才能做到。
如果你要进一步学习 type system,那么 LYAH 这本书是不够的,需要看一些程序语言
的教科书。
2. Monad
首... 阅读全帖
a*****e
发帖数: 1700
39
来自主题: Programming版 - functional programming?
你有这样的感觉没错,Python 的这些概念都来源于 FP,事实上,从 Lisp 引入 GC 开
始,非常多的 FP 的特征,已经越来越普遍地进入到其它非 FP 的语言。
我想你要问的是,既然这样,为什么要学习 Haskell 或者 FP?
我给几个 Haskell 有,但是你在 python 里面学不到的东西吧:
1. Strong type system
duck typing 看似更灵活,但是实际上它只是一个 sum of all types,没办法保证
type safty。有时候更 general 不是好事情,反而是有限制,尤其是编译器能够通过
静态检查就能确保程序遵守了这些限制,更有益处。举个例子,很多语言都有 SQL 的
库可用,但有几个能够静态检查,确保所有发出的 SQL 查询都是合法的?再比如,一
个程序需要处理平衡二叉树,你能够通过静态检查就确保不会发生不平衡的情况出现吗
?这些只有强类型的 abstract datatype 才能做到。
如果你要进一步学习 type system,那么 LYAH 这本书是不够的,需要看一些程序语言
的教科书。
2. Monad
首... 阅读全帖
G***l
发帖数: 355
40
lz你的标题误导人了。你在标题里说文本分析,结果一堆回复perl/python的,那些做
文本处理是很好。但你这个不是文本的问题,因为你这不是单纯的文本,是有语义的。
你这个基本就是需要个compiler frontend。比如你那个c语言的问题。你要用compiler
把代码转换为abstract syntax tree。有了这个ast之后,所有的变量定义都能准确定
位到,这时候你把ast上所有变量定义后面加一个初始化,再把ast反过来写成source
code,就成了。
如果你的需求很简单,比如只是变量定义加上初始化,那用纯文本regular expression
处理就可以了,perl,python很适合,哪怕sed/awk都可以搞定。如果复杂的话就需要
parser了,你可以用antlr,yacc之类的,那些常见语言的grammar都有现成的,不过要
是你自己特定的语法的话,就要自己写lexer/parer了,用上面提到的parser
generator的工具也挺容易。
c*****t
发帖数: 1879
41
AST is nothing. You can easily create one by hand.
For example, for the following simple calculator code:
print 2 * 3 + 5 * 7;
x = 1;
while (x < 10) {
if (x < 5)
print x * x;
else
print x + x;
x = x + 1;
}
The entire code for it, include AST classes, interpreter, lexer + parser
in CookCC (which generates Java) is 310 lines.
https://code.google.com/p/cookcc/source/browse/trunk/tests/java/parser/calc/
calc.xcc
Like I said, it is trivial if y... 阅读全帖
w**z
发帖数: 8232
p***o
发帖数: 1252
d*******r
发帖数: 3299
44
不错啊,这个居然也是java的
1 (共1页)