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))
> > > > >
> > > >
> > >
> >
>