add (incomplete) flex/bison-based parser to cvs the tokenizer is functional, but...
[platform/upstream/gstreamer.git] / gst / parse / parse.l
1 %{
2 #include <math.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include <glib.h>
6 #include <grammar.tab.h>
7
8 #define CHAR(x) printf ("char: %c\n", *yytext); return *yytext;
9 %}
10
11 _integer [[:digit:]]+
12 _float [[:digit:]]+"."*[[:digit:]]*
13 _number {_integer}|{_float}
14 _boolean "true"|"false"|"TRUE"|"FALSE"
15 _identifier [[:alpha:]][[:alnum:]\-_]*
16 _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
17
18 %x value
19 %option noyywrap
20 %%
21
22 <value>{
23     {_integer} {
24         printf ("An integer: %s (%d)\n", yytext,
25                 atoi (yytext));
26         BEGIN (INITIAL);
27         return INTEGER;
28     }
29     
30     {_float}    {
31         printf ("A float: %s (%g)\n", yytext, atof (yytext));
32         BEGIN (INITIAL);
33         return FLOAT;
34     }
35     
36     {_boolean} {
37         printf ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0);
38         BEGIN (INITIAL);
39         return BOOLEAN;
40     }
41     
42     {_string} {
43         if (*yytext == '"') {
44             yytext++;
45             *(yytext + strlen (yytext) - 1) = '\0';
46         }
47         printf ("A string: %s\n", yytext);
48         BEGIN (INITIAL);
49         return STRING;
50     }
51     
52     [[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
53     
54     . {
55         printf ("unknown: %s\n", yytext);
56     }
57 }
58
59 {_identifier} {
60     printf ("An identifier: %s\n", yytext);
61 }
62
63 "=" { BEGIN (value); CHAR ('='); }
64 "@" { CHAR ('@'); }
65 "." { CHAR ('.'); }
66 "," { CHAR (','); }
67 "{" { CHAR ('{'); }
68 "}" { CHAR ('}'); }
69 "[" { CHAR ('['); }
70 "]" { CHAR (']'); }
71 "(" { CHAR ('('); }
72 ")" { CHAR (')'); }
73 "!" { CHAR ('!'); }
74 "+" { CHAR ('+'); }
75
76 [[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
77
78 . {
79     printf ("unknown: %s\n", yytext);
80 }
81
82 %%