Redian新闻
>
怎样才能用perl等东西知道c macro中的数值
avatar
怎样才能用perl等东西知道c macro中的数值# Programming - 葵花宝典
s*r
1
今天才填好的tax return,可是有个问题。
我的情况是:
employee stock: 4000 gain (long-term)
individual stock: 3000 loss (short term)
听说long-term gain的最大tax rate是15%,而short-term就要按照income tax来扣税
了。但
1040 schedule D上面是将我的loss和gain都填上,然后合起来算,这样我最后就变成
了capital gain $1000,填到1040的line 13, 最后按照income tax来扣税。这样算对吗
?我的income tax比 15%高,怎么才能得到long-term gain的15%税率呢?谢谢
avatar
r*e
2
北美山杜鹃盛开的时节,五颜六色,争奇斗艳。(华盛顿州以山杜鹃花 Rhododendron
为州花。)
avatar
k*u
3
在线/最高在线: 341/349
avatar
a*l
4
我现在有一堆的C程序,需要知道其中宏定义的数值.比如:
file1: #define pig 1
file2: #define sheep 2
file3: #define dog 5
file4: #define total dog+sheep-pig
需要用一个比如perl的脚本程序扫描过所有的文件,然后能输出total=6.问题是显然这
个计算的方法不是固定的,所以脚本程序基本上需要按照C的规定展开宏定义,找到各词
语对应的数值,再计算出最终的数字.
有谁知道perl能不能做这样的工作?如果不是perl,有什么东西能做这样的事?谢谢!
avatar
c*g
5
Though your capital gain is carried to line 13 of page 1 from your schedule
D, it doesn't mean that that part is calculated by using your income tax
rate. The capital gain should be applied by 15% rate.
For your information, the LT capital gains rates are 0%, 15%, 25% and 28%.
28% applies to gain from the sale of collectibles held more than 1 year and
gain from the sale of section 1202 stock held more than 5 years. 25% applies
to unrecaptured section 1250 gain computed on sales of property held
avatar
w*a
6
很漂亮
avatar
N*m
7
how about in java? tested a few cases and it seems to work.
Map map = new HashMap();
map.put("dog",1);
map.put("sheep",5);
map.put("cat",3);

String s = "dog-cat+dog-sheep";
List list = new LinkedList();
StringTokenizer st = new StringTokenizer(s, "+-");
while(st.hasMoreTokens()) {
String tempString = st.nextToken();
//System.out.println();
list.add(tempString);
}
Iterator it = list.iterator();
List newList = new LinkedList();
int pos = -1;
while(it.hasNext()) {
String tempString = it.next();
pos = s.indexOf(tempString,pos);
newList.add(tempString);
int delimiter = 0;
if(pos+tempString.length()delimiter = pos+tempString.length();
newList.add(s.substring(delimiter,delimiter+
1));
}
}

System.out.print("The expression after analysis is:");
it = newList.iterator();
while(it.hasNext()) {
System.out.print(it.next());
}
System.out.println();

it = newList.iterator();
int value = 0;
int sum = 0;

if(it.hasNext()) {
String ps = it.next();
sum = map.get(ps);
}
while(it.hasNext()) {
String d = it.next();
String ps = it.next();
value = map.get(ps);
if(d.equals("+"))
sum += value;
else
sum -= value;

}

System.out.println(sum);

【在 a****l 的大作中提到】
: 我现在有一堆的C程序,需要知道其中宏定义的数值.比如:
: file1: #define pig 1
: file2: #define sheep 2
: file3: #define dog 5
: file4: #define total dog+sheep-pig
: 需要用一个比如perl的脚本程序扫描过所有的文件,然后能输出total=6.问题是显然这
: 个计算的方法不是固定的,所以脚本程序基本上需要按照C的规定展开宏定义,找到各词
: 语对应的数值,再计算出最终的数字.
: 有谁知道perl能不能做这样的工作?如果不是perl,有什么东西能做这样的事?谢谢!

avatar
h*h
8
好看

Rhododendron

【在 r*********e 的大作中提到】
: 北美山杜鹃盛开的时节,五颜六色,争奇斗艳。(华盛顿州以山杜鹃花 Rhododendron
: 为州花。)

avatar
N*m
9
forget to trim the string if it has blank spaces between +/- and variables.
i.e. change to "map.get(ps.trim())".

【在 N***m 的大作中提到】
: how about in java? tested a few cases and it seems to work.
: Map map = new HashMap();
: map.put("dog",1);
: map.put("sheep",5);
: map.put("cat",3);
:
: String s = "dog-cat+dog-sheep";
: List list = new LinkedList();
: StringTokenizer st = new StringTokenizer(s, "+-");
: while(st.hasMoreTokens()) {

avatar
r*e
10
北美山杜鹃盛开的时节,五颜六色,争奇斗艳。(华盛顿州以山杜鹃花 Rhododendron
为州花。)
avatar
t*t
11
first of all, the value of macro is dependent on the place that macro is
expanded. for example:
#define A A1
#define A1 1
/* here A expands to 1 */
#undef A1
#define A1 2
/* here A expands to 2 */
therefore your requirement is not very strict.
second, assume that you want only the final value of every macro. you may
use gcc to do that:
gcc -dM -E xxxxxxxx.c > xxxxxx_processed.c
/* it outputs all the (final) macro definitions */
then you use a perl to process it: for every macro name in $_, (each line is
a macro definition), append a line to *_processed.c like
printf(#$_"=%d\n", $_);
add some necessary header (int main(), etc), and compile the program and run.
CPP is better processed with CPP. using perl for it is a little bit painful.

【在 a****l 的大作中提到】
: 我现在有一堆的C程序,需要知道其中宏定义的数值.比如:
: file1: #define pig 1
: file2: #define sheep 2
: file3: #define dog 5
: file4: #define total dog+sheep-pig
: 需要用一个比如perl的脚本程序扫描过所有的文件,然后能输出total=6.问题是显然这
: 个计算的方法不是固定的,所以脚本程序基本上需要按照C的规定展开宏定义,找到各词
: 语对应的数值,再计算出最终的数字.
: 有谁知道perl能不能做这样的工作?如果不是perl,有什么东西能做这样的事?谢谢!

avatar
w*a
12
很漂亮
avatar
t*t
13
you can only process + and -?
just don't use java to process text. it's not for that.

【在 N***m 的大作中提到】
: how about in java? tested a few cases and it seems to work.
: Map map = new HashMap();
: map.put("dog",1);
: map.put("sheep",5);
: map.put("cat",3);
:
: String s = "dog-cat+dog-sheep";
: List list = new LinkedList();
: StringTokenizer st = new StringTokenizer(s, "+-");
: while(st.hasMoreTokens()) {

avatar
h*h
14
好看

Rhododendron

【在 r*********e 的大作中提到】
: 北美山杜鹃盛开的时节,五颜六色,争奇斗艳。(华盛顿州以山杜鹃花 Rhododendron
: 为州花。)

avatar
N*m
15
agree:) If there are more operators, I have to do more heavy work on that
part.
Sometimes it is a bad practice of trying to put everything into java. hehe.

【在 t****t 的大作中提到】
: you can only process + and -?
: just don't use java to process text. it's not for that.

avatar
e*s
16
很好看。
avatar
t*t
17
as you said, every language has its purpose. there is no point arguing which
language is better without context.
this become clearer and clearer when you learned more than 3-4 languages.

【在 N***m 的大作中提到】
: agree:) If there are more operators, I have to do more heavy work on that
: part.
: Sometimes it is a bad practice of trying to put everything into java. hehe.

avatar
N*m
18
嗯哪。主要是今天股票大跌,心情不佳,所以多灌了两下水。
权当我没说:)

which

【在 t****t 的大作中提到】
: as you said, every language has its purpose. there is no point arguing which
: language is better without context.
: this become clearer and clearer when you learned more than 3-4 languages.

avatar
a*l
19
你说的完全正确,我就是顾忌到这种和其他的类似的复杂情况.我去试一下.

【在 t****t 的大作中提到】
: first of all, the value of macro is dependent on the place that macro is
: expanded. for example:
: #define A A1
: #define A1 1
: /* here A expands to 1 */
: #undef A1
: #define A1 2
: /* here A expands to 2 */
: therefore your requirement is not very strict.
: second, assume that you want only the final value of every macro. you may

avatar
b*e
20
To solve your problem, there are two ways:
1) Use some C/C++ preprocessor directly, such as gcc/g++. If I remember
correctly -E option will output all the macros. Mcrosoft CL tool has similar
options.
2) Write your own preprocessor, which perhaps is not that hard either since
you only need to deal with the macro definition and expansion. There are lex
/yacc files you can obtained by google, perhaps even source code directly
does this.
If you are using Ruby, rex/racc gems are your friend.
If you are using Python, Ply (Python Lex/Yacc) is the choice.
Sorry not an expert of perl any more. Stopped using it years ago.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。