|
@@ -3,6 +3,7 @@
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <cjson/cJSON.h>
|
|
|
|
|
|
|
|
|
extern int yylex();
|
|
@@ -13,6 +14,8 @@ extern char* yytext;
|
|
|
int yydebug=1;
|
|
|
|
|
|
void yyerror(const char* s);
|
|
|
+
|
|
|
+char* catstr(char* s1, char* s2);
|
|
|
%}
|
|
|
|
|
|
%union {
|
|
@@ -31,32 +34,58 @@ void yyerror(const char* s);
|
|
|
|
|
|
%token QUIT NEWLINE
|
|
|
|
|
|
+%type <sv> IDENTIFIER data_type create_definition
|
|
|
+
|
|
|
%start statement
|
|
|
|
|
|
%%
|
|
|
|
|
|
statement: NEWLINE
|
|
|
| QUIT {printf("bye!\n"); exit(0); }
|
|
|
- | sql_statement { printf("%s\n", yytext); exit(0);}
|
|
|
+ | sql_statement
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
-sql_statement: create_statement
|
|
|
+sql_statement: create_table_stmt
|
|
|
+
|
|
|
+create_table_stmt: CREATE TABLE IDENTIFIER NEWLINE
|
|
|
+ {
|
|
|
+ printf("CREATE TABLE %s\n", $3);
|
|
|
+ }
|
|
|
|
|
|
-create_statement: CREATE TABLE IDENTIFIER '(' ')' NEWLINE
|
|
|
+create_table_stmt: CREATE TABLE IDENTIFIER '(' create_definition ')' NEWLINE
|
|
|
{
|
|
|
- printf("CREATE TABLE %s\n", yytext);
|
|
|
+ printf("CREATE TABLE %s %s\n", $3, $5);
|
|
|
}
|
|
|
|
|
|
+create_col_list: create_definition
|
|
|
+ | create_col_list ',' create_definition
|
|
|
+ ;
|
|
|
+
|
|
|
+create_definition: IDENTIFIER data_type;
|
|
|
+
|
|
|
+
|
|
|
+data_type: INT
|
|
|
+ | FLOAT
|
|
|
+ | STRING
|
|
|
+;
|
|
|
%%
|
|
|
|
|
|
int main(int ac, char** av) {
|
|
|
+ cJSON *monitor = cJSON_CreateObject();
|
|
|
+ char* name = cJSON_CreateString("Awesome 4K");
|
|
|
+ cJSON_AddItemToObject(monitor, "name", name);
|
|
|
+
|
|
|
+ cJSON* resolutions = cJSON_CreateArray();
|
|
|
+ cJSON_AddItemToObject(monitor, "resolutions", resolutions);
|
|
|
+ printf("%s\n", cJSON_Print(monitor));
|
|
|
+
|
|
|
if (ac != 2) {
|
|
|
printf("Usage: %s <sql>\n", av[0]);
|
|
|
exit(1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// yyin = av[1];
|
|
|
yy_scan_string(av[1]);
|
|
|
|
|
@@ -69,3 +98,10 @@ void yyerror(const char *s) {
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
+char* catstr(char* s1, char* s2) {
|
|
|
+ char* s = malloc(strlen(s1)+strlen(s2)+1);
|
|
|
+ strcpy(s, s1);
|
|
|
+ strcat(s, s2);
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|