14 enum yytokentype keytoks;
17 static struct keys kwds[] =
25 void __attribute__ ((noreturn))
31 vfprintf(stderr, msg, args);
42 if (!(ret = malloc(size)))
48 static void __attribute__ ((noreturn))
49 parse_err(char* msg, ...)
54 fprintf(stderr, "Line %d: ", line);
55 vfprintf(stderr, msg, args);
66 if (!(ret = strdup(s)))
73 get_string_out(int delim)
80 while ((c = getchar()) != delim || last == '\\'){
81 if (last=='\\' && c != delim)
89 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
99 return (c >= '0' && c <= '9' ) ||
100 (c >= 'a' && c <= 'z') ||
101 (c >= 'A' && c <= 'Z') ||
109 return (c >= 'a' && c <= 'z') ||
110 (c >= 'A' && c <= 'Z');
118 while ((c = getchar ()) == ' ' || c == '\t' || c =='\n'){
126 #define CC(a,b) ((a<<8)|b)
130 case CC('!','='): yylval.n = CC('!','='); return NEQ;
131 case CC('!','~'): yylval.n = CC('!','='); return NRE;
132 case CC('<','='): yylval.n = CC('<','='); return LE;
133 case CC('>','='): yylval.n = CC('>','='); return GE;
134 case CC('=','='): yylval.n = CC('=','='); return EQ;
135 case CC('~','~'): yylval.n = CC('~','~'); return RE;
136 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
161 yylval.str = get_string_out(c);
165 if (c >= '0' && c <= '9'){
167 scanf("%d",&yylval.n);
175 while (is_var_id(c = getchar())){
179 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
183 yylval.str = xstrdup(buf);
193 while (is_alpha(c = getchar())){
196 parse_err("Keyword too long");
201 n = (sizeof(kwds)/sizeof(struct keys));
202 for (i = 0; i < n; i++){
203 if (!strcmp(buf,kwds[i].keywords))
204 return kwds[i].keytoks;
207 parse_err("Unknown keyword %s", buf);
210 parse_err("Unknown character %c", c);