由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 请教大牛们一个问题
相关主题
java and javascript 问题请教,有包子Re: XML help?
java ee新手求教eclipse问题JavaCC/SableCC/otherCC ?
分享下多年积累的对JAVA程序员成长之路的总结zthelp! XML parse problem
有什么用java写的C parser/lexer吗?java 1.4 直接处理 http?
Heh, Spring's own application serverJava XML parser的问题
新手请教怎样在Java里读文本文件中的内容parse Date in DateFormat
在一个文本文件后面添加行怎么做?Anybody here used apache Lucene?
Applet读取加密的文件一个问题Java HTMLEditorKit 中取得html的text?
相关话题的讨论汇总
话题: block话题: comments话题: after话题: comment话题: line
进入Java版参与讨论
1 (共1页)
X******w
发帖数: 159
1
想用java实现一个comments converter,就是把java程序 (文本文件)里的line
comments和block comments能实现互换,不能影响程序的可运行性。
具体把block换成line的时候如何在行头插入"/*"?
如果line comments正好是满一行,后边没有空插入"/*"怎么办?
g*****g
发帖数: 34805
2
Fixed width is required? Otherwise I don't get why you can't do that.
If fixed width, break the comment into 2 lines.

【在 X******w 的大作中提到】
: 想用java实现一个comments converter,就是把java程序 (文本文件)里的line
: comments和block comments能实现互换,不能影响程序的可运行性。
: 具体把block换成line的时候如何在行头插入"/*"?
: 如果line comments正好是满一行,后边没有空插入"/*"怎么办?

X******w
发帖数: 159
3
txt文本文件的行宽怎么定义呢?或者怎么知道是不是fixed呢?
谢谢谢谢

【在 g*****g 的大作中提到】
: Fixed width is required? Otherwise I don't get why you can't do that.
: If fixed width, break the comment into 2 lines.

g*****g
发帖数: 34805
4
It's not defined, some code convention will define a width,
it's not biggie if you don't follow it in comment.

【在 X******w 的大作中提到】
: txt文本文件的行宽怎么定义呢?或者怎么知道是不是fixed呢?
: 谢谢谢谢

X******w
发帖数: 159
5
谢谢,有啥好的建议把block换成line的?
我想逐行读近,然后判断开头是不是"/*",如果是,我就换成“//”,block有很多行的
话,只有最后一行的结尾是“*/”,中间的行用什么来判定呢?
谢谢

【在 g*****g 的大作中提到】
: It's not defined, some code convention will define a width,
: it's not biggie if you don't follow it in comment.

k****u
发帖数: 133
6
After you read the beginning /*, keep reading the following lines, for each
line, see if it has the ending */, if not, keep reading, if it does, then
this is the end of the block comment; then, all the lines in between are
part of the block comments and should be converted to //.
c*****t
发帖数: 1879
7
Trivial.
Learn to use lex / yacc. Then you can use CookCC easily write one
under 10 minutes.

【在 X******w 的大作中提到】
: 想用java实现一个comments converter,就是把java程序 (文本文件)里的line
: comments和block comments能实现互换,不能影响程序的可运行性。
: 具体把block换成line的时候如何在行头插入"/*"?
: 如果line comments正好是满一行,后边没有空插入"/*"怎么办?

k****u
发帖数: 133
8
he may have to spend 10 days on lex/yacc before that 10 min, :-)

【在 c*****t 的大作中提到】
: Trivial.
: Learn to use lex / yacc. Then you can use CookCC easily write one
: under 10 minutes.

X******w
发帖数: 159
9
thanks a lot.
是不是可以把整个block读成一个string?在 */之前看到\n 就在后面插入//?

each

【在 k****u 的大作中提到】
: After you read the beginning /*, keep reading the following lines, for each
: line, see if it has the ending */, if not, keep reading, if it does, then
: this is the end of the block comment; then, all the lines in between are
: part of the block comments and should be converted to //.

X******w
发帖数: 159
10
真是惭愧,刚开始学,还没有接触到lex/yacc. 多谢

【在 k****u 的大作中提到】
: he may have to spend 10 days on lex/yacc before that 10 min, :-)
相关主题
新手请教怎样在Java里读文本文件中的内容Re: XML help?
在一个文本文件后面添加行怎么做?JavaCC/SableCC/otherCC ?
Applet读取加密的文件一个问题help! XML parse problem
进入Java版参与讨论
g*****g
发帖数: 34805
11
It takes 10 min to code one without knowing lex/yacc.

【在 c*****t 的大作中提到】
: Trivial.
: Learn to use lex / yacc. Then you can use CookCC easily write one
: under 10 minutes.

h*****0
发帖数: 4889
12
为啥要读成byte string?

【在 X******w 的大作中提到】
: thanks a lot.
: 是不是可以把整个block读成一个string?在 */之前看到\n 就在后面插入//?
:
: each

X******w
发帖数: 159
13
修改了,就是string。
谢谢

【在 h*****0 的大作中提到】
: 为啥要读成byte string?
k****u
发帖数: 133
14
After a second thought, there are some special cases that are hard to deal
with, for example:
String trickyOne = "/* this is not a block comment */";
in this case, you have to make sure /* and */ are not enclosed in double
quotes. This alone is making your logic convoluted.
You best bet is to get to the parse tree of the source code, then just
traverse the tree and look for block comments. This solution is easy, clean
and maintainable.
For getting the parse tree, JavaSE 6 introduced some

【在 X******w 的大作中提到】
: thanks a lot.
: 是不是可以把整个block读成一个string?在 */之前看到\n 就在后面插入//?
:
: each

X******w
发帖数: 159
15
Thank you so much.
Based on a little what I have learned so far, I will first try to create a
program not designed to handle inline block comments (such as: class.method(
/* some comments */);), and the case you mentioned, which is enclosed in
double quotes.
After that I definitely will follow your guide.
Again thanks.

clean
link

【在 k****u 的大作中提到】
: After a second thought, there are some special cases that are hard to deal
: with, for example:
: String trickyOne = "/* this is not a block comment */";
: in this case, you have to make sure /* and */ are not enclosed in double
: quotes. This alone is making your logic convoluted.
: You best bet is to get to the parse tree of the source code, then just
: traverse the tree and look for block comments. This solution is easy, clean
: and maintainable.
: For getting the parse tree, JavaSE 6 introduced some

m******t
发帖数: 2416
16
Heh, this reminds me of a funny (unless you are the one troubleshooting of
course)
trick back in the C days - what's wrong with this code:
println(1.0/*fptr);

clean
link
compiler-apis.html

【在 k****u 的大作中提到】
: After a second thought, there are some special cases that are hard to deal
: with, for example:
: String trickyOne = "/* this is not a block comment */";
: in this case, you have to make sure /* and */ are not enclosed in double
: quotes. This alone is making your logic convoluted.
: You best bet is to get to the parse tree of the source code, then just
: traverse the tree and look for block comments. This solution is easy, clean
: and maintainable.
: For getting the parse tree, JavaSE 6 introduced some

k****u
发帖数: 133
17

could possibly divide by 0

【在 m******t 的大作中提到】
: Heh, this reminds me of a funny (unless you are the one troubleshooting of
: course)
: trick back in the C days - what's wrong with this code:
: println(1.0/*fptr);
:
: clean
: link
: compiler-apis.html

m******t
发帖数: 2416
18
No, hint: what is LZ trying to parse?

【在 k****u 的大作中提到】
:
: could possibly divide by 0

1 (共1页)
进入Java版参与讨论
相关主题
Java HTMLEditorKit 中取得html的text?Heh, Spring's own application server
Java menu accelerator not working新手请教怎样在Java里读文本文件中的内容
[转载] 这个是什么错误呀?在一个文本文件后面添加行怎么做?
Question about tabApplet读取加密的文件一个问题
java and javascript 问题请教,有包子Re: XML help?
java ee新手求教eclipse问题JavaCC/SableCC/otherCC ?
分享下多年积累的对JAVA程序员成长之路的总结zthelp! XML parse problem
有什么用java写的C parser/lexer吗?java 1.4 直接处理 http?
相关话题的讨论汇总
话题: block话题: comments话题: after话题: comment话题: line