Skip to search.
sas_academy · SAS Academy

Group Information

  • Members: 37
  • Category: Software
  • Founded: Dec 15, 2008
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Messages

  Messages Help
Advanced
Play with TYPE   Message List  
Reply Message #454 of 566 |
sas code scanner with c

This is the continuation of the following posts
http://tech.groups.yahoo.com/group/sas_academy/message/388
http://tech.groups.yahoo.com/group/sas_academy/message/283
http://tech.groups.yahoo.com/group/sas_academy/message/279
http://tech.groups.yahoo.com/group/sas_academy/message/170

The assumption is a simplified sas code model: no macro.
And the theoretical aspect is FSM (thank Jiangtang Hu for bringing up this concept :)

#include <stdio.h>
// FSM Def: e,b,c,d,q,i; e->c,e->b,e->d,b->i,b->q,b->e,d->e,c->e,i->b,q->b
main(int argc,char** argv){
    FILE* f=fopen(*++argv,"r");
    char c=fgetc(f); char s='e'; char buf;
    puts("#NULL{");
    while (c!=EOF){
        if (s=='e' && c=='/'){
            buf=c;c=fgetc(f);
            if (c=='*'){
                s='c';puts("}\n#Comment{");
                putchar(buf);putchar(c);c=fgetc(f);
            }
            else {
                s='b';puts("}\n#StatementFromE1{");
                putchar(buf);putchar(c);c=fgetc(f);
            }
        }
        else if (s=='e' && c=='*'){
            s='d';puts("}\n#SLComment{");
            putchar(c);c=fgetc(f);
        }
        else if (s=='e' && c!=' ' && c!='\t' && c!='\n' && c!='\r'){
            s='b';puts("}\n#StatementFromE2{");
            putchar(c);c=fgetc(f);
        }
        else if (s=='b' && c=='/'){
            buf=c;c=fgetc(f);
            if (c=='*'){
                s='i';puts("}\n#InLineComment{");
                putchar(buf);putchar(c);c=fgetc(f);
            }
            else {
                putchar(buf);putchar(c);c=fgetc(f);
            }
        }
        else if (s=='b' && (c=='"' || c=='\'')){
            s='q';puts("}\n#Literal{");
            putchar(c);c=fgetc(f);
        }
        else if (s=='b' && c==';'){
            putchar(c);c=fgetc(f);
            s='e';puts("}\n#NULL{");
        }
        else if (s=='c' && c=='*'){
            buf=c;c=fgetc(f);
            if (c=='/'){
                putchar(buf);putchar(c);c=fgetc(f);
                s='e';puts("}\n#NULL{");
            }
            else {
                putchar(buf);putchar(c);c=fgetc(f);
            }
        }
        else if (s=='i' && c=='*'){
            buf=c;c=fgetc(f);
            if (c=='/'){
                putchar(buf);putchar(c);c=fgetc(f);
                s='b';puts("}\n#StatementFromI{");
            }
            else {
                putchar(buf);putchar(c);c=fgetc(f);
            }
        }
        else if (s=='q' && (c=='"' || c=='\'')){
            putchar(c);c=fgetc(f);
            s='b';puts("}\n#StatementFromQ{");
        }
        else if (s=='d' && c==';'){
            putchar(c);c=fgetc(f);
            s='e';puts("}\n#NULL{");
        }
        else {
            putchar(c);c=fgetc(f);
        }
    }
    puts("}");
}






--- In sas_academy@yahoogroups.com, "DJ" <daij1492@...> wrote:
>
> #include <stdio.h>
> main(int argc, char **argv){
> FILE* f=fopen(*++argv,"r");
> char c;
> while ((c=fgetc(f))!=EOF) putchar(c);
> }
>
> --- In sas_academy@yahoogroups.com, "DJ" daij1492@ wrote:
> >
> > #include <stdio.h>
> > #include <time.h>
> > main(){
> > time_t x=time(NULL);
> > puts(asctime(localtime(&x)));
> > }
> >
> >
> >
> > --- In sas_academy@yahoogroups.com, "DJ" daij1492@ wrote:
> > >
> > > #include <stdio.h>
> > > typedef int (*iFi) (int);
> > > int succ(int x){return x+1;}
> > > int prec(int x){return x-1;}
> > > iFi succCall(){return succ;}
> > > iFi precCall(){return prec;}
> > > iFi reverseCall(iFi f){
> > > if (f==succ) {return prec;}
> > > else if (f==prec) {return succ;}
> > > }
> > > int Eval(iFi f,int x){return f(x);}
> > > int main(){
> > > int x=5;
> > > printf("Hi there %d.\n",succCall()(x));
> > > printf("Hi there %d.\n",precCall()(x));
> > > printf("Hi there %d.\n",Eval(succ,x));
> > > printf("Hi there %d.\n",Eval(prec,x));
> > > iFi f;
> > > f=prec;printf("Hi there %d.\n",reverseCall(f)(x));
> > > f=succ;printf("Hi there %d.\n",reverseCall(f)(x));
> > > return 0;
> > > }
> > >
> > > --- In sas_academy@yahoogroups.com, "DJ" daij1492@ wrote:
> > > >
> > > > The two typedef statements can be further shorten as
> > > > typedef int (*fp) (int);
> > > >
> > > > --- In sas_academy@yahoogroups.com, "DJ" daij1492@ wrote:
> > > > >
> > > > > C:\@Local\Coldz\c>type tstType.c
> > > > > #include <stdio.h>
> > > > > typedef int iFi (int);
> > > > > typedef iFi* fp;
> > > > > int succ(int x){return x+1;}
> > > > > int prec(int x){return x-1;}
> > > > > int main(){
> > > > > int x=5;
> > > > > fp f;
> > > > > f=succ;printf("Hi there %d.\n",f(x));
> > > > > f=prec;printf("Hi there %d.\n",f(x));
> > > > > return 0;
> > > > > }
> > > > >
> > > > > C:\@Local\Coldz\c>gcc tstType.c -o tstType.exe
> > > > >
> > > > > C:\@Local\Coldz\c>tsttype
> > > > > Hi there 6.
> > > > > Hi there 4.
> > > > >
> > > > >
> > > > > Something looks smarter
> > > > > javascript: function Eval(f,x){return
> > > > > f(x)};alert(Eval(Math.sqrt,9));alert(Eval(Math.abs,-9))
> > > > >
> > > >
> > >
> >
>


Wed Aug 10, 2011 6:21 am

daij1492
Offline Offline
Send Email Send Email

Message #454 of 566 |
Expand Messages Author Sort by Date

C:\@Local\Coldz\c>type tstType.c #include <stdio.h> typedef int iFi (int); typedef iFi* fp; int succ(int x){return x+1;} int prec(int x){return x-1;} int...
DJ
daij1492 Offline Send Email
Jul 15, 2011
12:04 am

The two typedef statements can be further shorten as typedef int (*fp) (int);...
DJ
daij1492 Offline Send Email
Jul 15, 2011
12:12 am

#include <stdio.h> typedef int (*iFi) (int); int succ(int x){return x+1;} int prec(int x){return x-1;} iFi succCall(){return succ;} iFi precCall(){return...
DJ
daij1492 Offline Send Email
Jul 15, 2011
12:27 am

#include <stdio.h> #include <time.h> main(){ time_t x=time(NULL); puts(asctime(localtime(&x))); }...
DJ
daij1492 Offline Send Email
Aug 3, 2011
8:16 am

#include <stdio.h> main(int argc, char **argv){ FILE* f=fopen(*++argv,"r"); char c; while ((c=fgetc(f))!=EOF) putchar(c); }...
DJ
daij1492 Offline Send Email
Aug 4, 2011
12:04 am

#include <stdio.h> #include <dirent.h> main(int argc,char **argv){ DIR* dir=opendir(*++argv); struct dirent* ent; while ((ent=readdir(dir))!=NULL)...
DJ
daij1492 Offline Send Email
Aug 4, 2011
10:18 pm

#include <stdio.h> #include <sys/stat.h> main(int argc,char **argv){ struct stat s; stat(*++argv,&s); if ((s.st_mode & S_IFMT) == S_IFDIR) puts("Is Dir\n"); ...
DJ
daij1492 Offline Send Email
Aug 4, 2011
11:16 pm

#include <stdio.h> #include <string.h> main (){ char* stem1="tract"; char* stem2="pact"; char* prefix="Con"; char buf1[100]; char buf2[100]; puts(prefix); ...
DJ
daij1492 Offline Send Email
Aug 5, 2011
3:29 pm

#include <stdio.h> #include <sys/stat.h> #include <dirent.h> #include <string.h> main(int argc,char **argv){ struct stat s; struct dirent* ent; char...
DJ
daij1492 Offline Send Email
Aug 5, 2011
3:45 pm

#include <stdio.h> #include <sys/stat.h> #include <dirent.h> #include <string.h> #define MAX_PATH_LENGTH 1024 void checkFolder(char* f){ struct stat s; char...
DJ
daij1492 Offline Send Email
Aug 5, 2011
9:11 pm

#include<stdio.h> main(){ char* a[]={"ok","not ok","anyway","bye"}; char** key=a; int size=4;int c=0; while(c<size){ printf("[%s]\n",*key++);c++; } }...
DJ
daij1492 Offline Send Email
Aug 17, 2011
10:28 pm

This is the continuation of the following posts http://tech.groups.yahoo.com/group/sas_academy/message/388 ...
DJ
daij1492 Offline Send Email
Aug 10, 2011
6:22 am

#include <stdio.h> typedef struct { int a,b; int (*m)(int,int); } f; int add(int x,int y){return x+y;} int subtract(int x,int y){return x-y;} main(){ f...
DJ
daij1492 Offline Send Email
Aug 13, 2011
7:27 am

Well, this is a tricky topic: #include <stdio.h> typedef struct { const int N; int p; } bnd; main(){ bnd x={100,1}; for (;x.p<x.N;x.p++)printf("%d\n",x.p); ...
DJ
daij1492 Offline Send Email
Aug 16, 2011
6:18 am

#include<stdio.h> #include<stdlib.h> main(){ for (short i=0;i<100;++i)printf("%f\n",(double)rand()/RAND_MAX); }...
DJ
daij1492 Offline Send Email
Aug 17, 2011
4:34 pm

rand() is random number generator in c/c++. It generates a random number between 0 and RAND_MAX #include<stdio.h> #include<stdlib.h> main(){ int...
DJ
daij1492 Offline Send Email
Aug 20, 2011
9:51 pm

#include<stdio.h> #include<stdlib.h> main(){ int c[32768];//RAND_MAX=32767 for (long j=0;j<=RAND_MAX;j++)c[j]=0; for (long i=0;i<1000000;i++)++c[rand()]; FILE*...
DJ
daij1492 Offline Send Email
Aug 21, 2011
2:27 am

#include<stdio.h> #include<stdlib.h> unsigned int X=RAND_MAX; double ranuni_cc(){return (double)rand()/X;} //[0,1]=>0/X..X/X double ranuni_co(){return...
DJ
daij1492 Offline Send Email
Aug 21, 2011
6:18 am
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help