%{ #include #include "xmc.h" /* interface to the prototipe */ #define show_st libxmevalstr("(pp C)") #define ins_mark(st,co,mk) evf3("InsMark",strsexp(st),strsexp(co), intsexp(mk)) #define def_cour(co) evf1("DefineCourse",strsexp(co)) #define ins_stud(st,co) evf2("InsStu",strsexp(st),strsexp(co)) %} STU ([A-Za-z]+) COU ([A-Za-z][A-Za-z0-9]*) MAR ([0-9]+) %% char st[20], co[20]; SEXP x,y,r,aux; int mk; {STU}" got "{MAR}" in "{COU} {sscanf(yytext,"%s got %d in %s",st,&mk,co); x=ins_mark(st,co,mk); if(x->n_type == STR) printf("%s\n",x->n_str); show_st;} {COU}" is a new course" {sscanf(yytext,"%s is a new course",co); def_cour(co);} {STU}" studies "{COU} {sscanf(yytext,"%s studies %s",st,co); ins_stud(st,co);} "list the marks available at "{COU} {sscanf(yytext ,"list the marks available at %s",co); r=evf2("ap",symsexp("C"),strsexp(co)); /* evf1("pp",r); pretty print de r*/ printf("in the course %s,\n",co); forallpair(aux,x,y,r) if(y != NULL) printf("student %s got %d\n", x->n_str,y->n_int) ;} . ; \n ; %% char *argv[]={"enroll2.met"}; main() { SEXP N,aux,x,y; libxminit(1,argv); yylex(); }