| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 20103 人关注过本帖, 2 人收藏
标题:★☆发布简易语法高亮(第9版0719更新,通用免费版本,附部分源代码)☆★
只看楼主 加入收藏
chenclok
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-15
收藏
得分:0 
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include <stdio.h>
#include <stdarg.h>  /*最主要的就是这个头文件了*/
#include <stdlib.h>  /*这个和变参函数一点关系也没有,这个是我为了防止
                    屏幕一闪而过调用system("pause")用的*/


#define _max_args 31  /*定义参数的最大值*/

int sum(int n_param,...)
{
   
va_list ap;  /*定义一个参数列表*/
   
int i;
    int s=0;
    if (n_param>_max_args)
        n_param=_max_args;
    va_start(ap,n_param);  /*开始读取变量,n_param表示从变量n_param后面开始读取*/
   
for (i=0;i<n_param;i++)
        s=s+va_arg(ap,int); /*va_arg表示从...里面读取一个int类型变量,然后把ap指向
                            下一个变量*/
   
va_end(ap); /*不要忘记这个哦*/
   
return s;
}

int main()
{
   
printf("%d",sum(5,1,2,3,4,5));
    system("pause");
    return 0;
}
2008-06-15 15:57
雨中飛燕
Rank: 1
等 级:新手上路
帖 子:765
专家分:0
注 册:2007-10-13
收藏
得分:0 
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#define keyword_test:

auto enum restrict unsigned break extern return
void case float short volatile char for signed
while const goto sizeof _Bool continue if static
_Complex default inline struct _Imaginary do  int
switch double long typedef else register  union

int
test()
{
   
int a=10L;
    int b=0x2efd+0X0001+0x98ga+22h;

    double f1=0.2e3+5.4E5+5E-3+5E+3+5.+.5;

    char *string="hello\n";     /*hello world*/   
   
wchar_t a=L"hello";    // 你好
   
return 0;
}


版本更新,添加了更多的关键字,添加了部分特殊处理


[color=white]

[[it] 本帖最后由 雨中飛燕 于 2008-6-15 23:09 编辑 [/it]]
2008-06-15 23:00
菜鸟选手
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2008-5-5
收藏
得分:0 
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include <iostream.h>
void main()
{
int N, i, j=1, count=0, countTemp=0;  //line 1
cin >>N;
for(i=N; i>=-N; i--, j=1, count +=((countTemp-1)*2+1), countTemp=0)
            //line 2
{
while(countTemp++, (j*(j++)+i*i)<=N*N);  //line 3
}
double output = double(count)/double(N*N);  //line 4
cout.precision(15);
cout <<output<<endl;
}



...~ 我这个貌似是老的!

[[it] 本帖最后由 菜鸟选手 于 2008-6-15 23:26 编辑 [/it]]

算法学习群57909089
2008-06-15 23:25
菜鸟选手
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2008-5-5
收藏
得分:0 
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define N 5

int main(void) {
   
int arr1[N][N] = {
        {
1, 2, 3,  4,   5},
        {0, 6, 7,  8,   9},
        {0, 0, 10, 11, 12},
        {0, 0, 0,  13, 14},
        {0, 0, 0,  0,  15}};

    int arr2[N*(1+N)/2] = {0};

    int i, j, loc = 0;

    printf("原二维资料:\n");
    for(i = 0; i < N; i++) {
        
for(j = 0; j < N; j++) {
            
printf("%4d", arr1[i][j]);
        }
        
printf("\n");
    }

   
printf("\n以列为主:");
    for(i = 0; i < N; i++) {
        
for(j = 0; j < N; j++) {
            
if(arr1[i][j] != 0)
                arr2[loc++] = arr1[i][j];
        }
    }
   
for(i = 0; i < N*(1+N)/2; i++)
        printf("%d ", arr2[i]);

    printf("\n输入索引(i, j):");
    scanf("%d, %d", &i, &j);
    loc = N*i - i*(i+1)/2 + j;
    printf("(%d, %d) = %d", i, j, arr2[loc]);

    printf("\n");
    return 0;
}


试试新的有什么区别?

算法学习群57909089
2008-06-15 23:30
kyln
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-4-21
收藏
得分:0 
我感觉对程序代码进行正则搜索,匹配到关键字就对其进行正则替换就可能实现这个软件的功能吧
有空也搞个玩玩
2008-06-16 00:35
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#define keyword_test:

auto enum restrict unsigned break extern return
void case float short volatile char for signed
while const goto sizeof _Bool continue if static
_Complex default inline struct _Imaginary do  int
switch double long typedef else register  union

int
test()
{
   
int a=10L;
    int b=0x2efd+0X0001+0x98ga+22h;

    double f1=0.2e3+5.4E5+5E-3+5E+3+5.+.5;

    char *string="hello\n";     /*hello world*/   
   
wchar_t a=L"hello";    // 你好
   
return 0;
}


不错,很不错~~~!

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-06-16 04:17
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
额……小数点和指数的符号还是没有正确处理啊……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-06-16 04:17
jass2072
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-06-16 08:39
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
忙了一天,只改了关键字和宏,在浮点常量上还有问题。
再和偶的标准着色方案对比一下:
#define keyword_test:

auto enum restrict unsigned break extern return
void case float short volatile char for signed
while const goto sizeof _Bool continue if static
_Complex default inline struct _Imaginary do  int
switch double long typedef else register  union

int test()
{
        int a=10L;
        int b=0x2efd+0X0001+0x98ga+22h;

        double f1=0.2e3+5.4E5+5E-3+5E+3+5.+.5;

        char *string="hello\n";         /*hello world*/        
        wchar_t a=L"hello";        // 你好
        return 0;
}


/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#define keyword_test:

auto enum restrict unsigned break extern return
void case float short volatile char for signed
while const goto sizeof _Bool continue if static
_Complex default inline struct _Imaginary do  int
switch double long typedef else register  union

int
test()
{
   
int a=10L;
    int b=0x2efd+0X0001+0x98ga+22h;

    double f1=0.2e3+5.4E5+5E-3+5E+3+5.+.5;

    char *string="hello\n";     /*hello world*/    
   
wchar_t a=L"hello";    // 你好
   
return 0;
}





可以下载我fish源码包,用文本编辑器打开fish.lex,看看C99的词法是怎么定义的:
D            [0-9]
L            [a-zA-Z_]
H            [a-fA-F0-9]
E            [Ee][+-]?{D}+
FS            (f|F|l|L)
IS            (u|U|l|L)*

%%
"/*"               { comment(MUTILINE); }
"//"           { comment(SINGLELINE);}

^#[^ <]+            { preprecess();}

"auto"            |
"_Bool"            |
"break"            |
"case"            |
"char"            |
"_Complex"        |
"const"            |
"continue"        |
"default"        |
"do"            |
"double"        |
"else"            |
"enum"            |
"extern"        |
"float"            |
"for"            |
"goto"            |
"if"            |
"_Imaginary"        |
"inline"        |
"int"            |
"long"            |
"register"        |
"restrict"        |
"return"        |
"short"            |
"signed"        |
"sizeof"        |
"static"        |
"struct"        |
"switch"        |
"typedef"        |
"union"            |
"unsigned"        |
"void"            |
"volatile"        |
"while"            { output_tag(KEYWORD); }

{L}({L}|{D})*        { output_tag(IDENTIFIER); }

0[xX]{H}+{IS}?        |
0{D}+{IS}?        |
{D}+{IS}?        |
L?'(\\.|[^\\'])+'    |
{D}+{E}{FS}?        |
{D}*"."{D}+({E})?{FS}?    |
{D}+"."{D}*({E})?{FS}?    { output_tag(CONSTANT); }

L?\"(\\.|[^\\"])*\"    { output_tag(CONSTANT); }

[[it] 本帖最后由 VxWorks 于 2008-6-16 09:48 编辑 [/it]]

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-06-16 09:40
雨中飛燕
Rank: 1
等 级:新手上路
帖 子:765
专家分:0
注 册:2007-10-13
收藏
得分:0 
嗯嗯,因为一开始时我本来只考虑字符串注释和关键字的高亮,所以结构的布局也简单
所以才叫“简易”,不过后来做的时候把越来越多的语法也加了进去。
不过主体结构没有变
其实前几个版本把数字给高亮了只是巧合。。原本偶没打算高亮数字的
有空再改改吧



[color=white]
2008-06-16 13:20
快速回复:★☆发布简易语法高亮(第9版0719更新,通用免费版本,附部分源代码) ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021238 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved