first commit - working example - needs pointer type recognition (actualy more than...
[CppToLua.git] / cpptolua.l~
blob89620aec2e55b7ff886ee50003e2108804656dc6
1 %{
2 #include "y.tab.h"
3 #include <stdlib.h>
4         void yyerror(char *);
5         int idf(char *s);
6 %}
8 %%
10 "class" { return CLASS; }
11 [{};()] { 
12         yylval.name = strdup(yytext);
13 #ifdef DEBUG
14         printf("read: %c\n", *yytext);
15 #endif
16         return *yytext; 
20         /* identifiers */
21 [a-zA-Z_0-9]+ {
22         yylval.name = strdup(yytext);
23 #ifdef DEBUG
24         printf("read: %s\n", yytext);
25         printf("idf: %i\n", idf(yytext));
26 #endif
27         return idf(yytext);
30         /* skip whitespace */
31 [ \t\n]+ ;
33         /* skip comments */
34 \/\/.* ;
35 \/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ ;
37         /* anything else is an error */
38 . { 
39         printf("read: '%c'\n", *yytext);
40         yyerror((char *)"invalid character");
45 int yywrap(void) {
46         return 1;
49 int idf(char *s)
51         char types[][99] = {"int", "float", ""};
52         int i;
53         for(i = 0; types[i][0]; i++) {
54                 if(!strcmp(types[i], s)) {
55                         return TYPE;
56                 }
57         }
58         return IDF;