diff options
author | 2024-07-22 17:02:03 +0200 | |
---|---|---|
committer | 2024-07-22 17:02:03 +0200 | |
commit | e79c6f67ff9276fc2f5a4ab79cd4678aaaa4eb17 (patch) | |
tree | 2781a5cc7d066b044ed08e4942e6d962d9f4f805 /properties.l | |
download | properties-e79c6f67ff9276fc2f5a4ab79cd4678aaaa4eb17.tar.gz properties-e79c6f67ff9276fc2f5a4ab79cd4678aaaa4eb17.zip |
Initial commit
Diffstat (limited to 'properties.l')
-rw-r--r-- | properties.l | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/properties.l b/properties.l new file mode 100644 index 0000000..653c358 --- /dev/null +++ b/properties.l @@ -0,0 +1,67 @@ +%{ +enum { + KEY = 1, + DIV, + VALUE +}; +%} + +%% + +=|: return DIV; +^[ \t]*[a-zA-Z0-9\.]* return KEY; +[ \t]* ; +. return VALUE; + +%% + +struct Properties { + char *key; + char *value; + struct Properties *next; +}; + +int +main(void) +{ + int token; + int next_token = KEY; + struct Properties properties; + properties.next = NULL; + + char *key; + char *value = calloc(2048, sizeof(char)); + int v = 0; + + do { + v = 0; + value = calloc(2048, sizeof(char)); + + token = yylex(); + + if (next_token == VALUE) { + if (token == VALUE) { + do { + *(value + v) = *yytext; + v++; + } while ((token = yylex()) == VALUE); + } + + next_token = KEY; + printf("%s --> %s|\n", key, value); + } + + if (token == KEY && next_token == KEY) { + next_token = DIV; + key = strdup(yytext); + } else if (token == DIV && next_token == DIV) { + next_token = VALUE; + } + } while (token != 0); + + while (properties.next != NULL) { + printf("%s ---> %s\n", properties.key, properties.value); + } + + return EXIT_SUCCESS; +} |