Topic: 请教一个有难度的问题

  Print this page

1.请教一个有难度的问题 Copy to clipboard
Posted by: ysheng
Posted on: 2004-09-23 08:47

如果自己要写一个能解释一个简单的javascript命令的类

比如
<script language=javascript>
var title = "<title>hello</title>";
var body = "welcome";
document.write(title);
document.write(body);
</script>
希望有个类可以通过上面的文本,生成一个html网页,网页标题是hello,内容是welcome

大概的思路是什么
应该参考哪些方面的知识
这属于什么范畴的问题

2.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: 九佰
Posted on: 2004-09-23 08:54

看上去有点像 xslt ,你看看xslt的介绍吧

3.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: shuikun
Posted on: 2004-09-23 19:46

我不知道你想问的是什么,不过如果保存为hello.html直截打开就可以了,能否说的更清楚一点,

4.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: ysheng
Posted on: 2004-09-24 01:57

<script language=javascript>
var title = "<title>hello</title>";
var body = "welcome";
document.write(title);
document.write(body);
</script>

要通过java存成这样的html,不带javascript的
<title>hello</title>
welcome

也就是用java把这个javascript代码解释出来,得到javascript执行后的结果

5.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: ysheng
Posted on: 2004-09-24 02:00

简单的说就是怎么样用java做一个javascript的解释器
能说说思路吗?
从何下手

希望有人能讲讲大致的方向
应该参考哪些方面的知识
这属于什么范畴的问题

6.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: yipsilon
Posted on: 2004-09-29 23:58

使用JavaCC吧。

7.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: aleel_008
Posted on: 2004-09-30 01:14

看看编译原理吧!做一个编译器可是很复杂的,不过只是解释你的那段语句
难度应该不是很大吧!
首先建立一个HashTable,
遇到var就把后面的变量和值分别作为关键词和内容存进去
遇到docoument.write就根据后面的引用把内容调出来.
然后输入生成到一个html文件

8.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: elysium922
Posted on: 2004-10-02 01:26

Why would you want to do this anyway? There are plenty of java-based javascript parsers out there, and many are open-sourced. Check out Rhino (a Mozilla incubator project).

9.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: aleel_008
Posted on: 2004-10-03 10:22

it is indeed unnecessary,it is worth to think a method to parse javascript based on java by yourself out, it is valuable to anything by yourself if you can't

10.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: elysium922
Posted on: 2004-10-03 12:08

aleel_008, I'm not sure I understand you correctly, but if you're interested in what's going on behind the scenes, just look into the source code. That way even if you still don't understand much, at least you'll know how to get started.

11.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: chengbd
Posted on: 2004-10-03 12:19

sourceforge.net有有开源项目是关于这方面的,你可以去那上面找找,如果有好的代码,也向我推荐一下哟,多谢。

12.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: aleel_008
Posted on: 2004-10-03 12:34

elysium922,thank you for your advice,however,I can't understand what you said.I don't think I want to do anything about this subject.thank you all the same

13.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: ysheng
Posted on: 2004-10-08 15:39

因为那些源代码都很“庞大”
而我目前需要处理的 javascript 类型比较简单,所以想自己写看看

14.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: alexlex
Posted on: 2004-10-08 15:48

誠如aleel_008所言

遇見var就是數據,存起來
遇見write就是輸出,寫到到html文件
如果是其他js function,做些處理什麽的,可以存到臨時變量之類

如果是需要處理循環,條件等控制語句,就要用到編譯原理的知識了,這個就難了

15.Re:请教一个有难度的问题 [Re: ysheng] Copy to clipboard
Posted by: ysheng
Posted on: 2004-10-12 15:13

谢谢各位,我得花一段时间看代码学习了


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923