%{ #include #include #include #include #include char *yy_private_error_guess = ""; %} %token NAME STRING NUMBER EQUAL SEMICOLON REPLICATION LEFTBRACE RIGHTBRACE SOURCE TARGET RIGHTBRACKET COMMA LEFTBRACKET %% replication_declarations : | replication_declarations replication_declaration ; replication_declaration : {yy_private_error_guess = "Expecting keyword 'replication'";} REPLICATION {yy_private_error_guess = "Expecting string";} STRING {yy_private_error_guess = "Expecting '{'";} LEFTBRACE {yy_private_error_guess = "Expecting variable declarations";} variable_declarations {yy_private_error_guess = "Expecting source declaration";} source_declaration {yy_private_error_guess = "Expecting target declaration";} target_declaration {yy_private_error_guess = "Expecting '}'";} RIGHTBRACE ; variable_declarations : | variable_declarations simple_declaration ; source_declaration : {yy_private_error_guess = "Expecting keyword 'source'";} SOURCE {yy_private_error_guess = "Expecting keyword quoted string";} STRING {yy_private_error_guess = "Expecting '{'";} LEFTBRACE {yy_private_error_guess = "Expecting variable declarations";} variable_declarations {yy_private_error_guess = "Expecting '{'";} RIGHTBRACE ; target_declaration : {yy_private_error_guess = "Expecting keyword 'target'";} TARGET {yy_private_error_guess = "Expecting keyword quoted string";} STRING {yy_private_error_guess = "Expecting '{'";} LEFTBRACE {yy_private_error_guess = "Expecting variable declarations";} variable_declarations {yy_private_error_guess = "Expecting '{'";} RIGHTBRACE ; simple_declaration : {yy_private_error_guess = "Expecting unquoted name\n";} NAME {yy_private_error_guess = "Expecting '='\n";} EQUAL {yy_private_error_guess = "Expecting value\n";} value {yy_private_error_guess = "Expecting semicolon\n";} SEMICOLON ; value : STRING | NAME | NUMBER | list ; list : LEFTBRACKET elements RIGHTBRACKET ; elements : element additional ; additional : | element additional ; element : STRING | NAME ; %% char *configuration_file = "replication.conf"; int main(int argc, char **argv) { printf("Found %d arguments...\n",argc); // parse config file char opt; extern char *optarg; while((opt = getopt(argc,argv,"c:C:")) != -1) { switch(opt) { case 'c': case 'C': configuration_file = optarg; break; } } // read in configuration FILE *f = fopen(configuration_file,"r"); if(f) { yyrestart(f); yyparse(); printf("Parsed!\n"); } else { printf("Couldn't open %s!\n",configuration_file); exit(1); } }