/* .Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y */ /* .YT 3 2 0 0 3 3 1 / / / */ /* .H!a!0:io#092/disk#092/mediaAccess#092/grammar#092/cpp#092/MediaInfo.y!0.!c */ /*************************************************************************** io disk mediaAccess grammar MediaInfo.y +++++++++++++++++++++++++++++++++++++++ purpose : specifies the bison-grammar-part for the grammar of a "mediaAccess"-media-info-structure (/-text) begin : Wed Apr 12 15:48:12 CEST 2017 changes : copyright : (C) 2017 by Thomas Bruecker email : public@thomas-r-bruecker.ch version : -0.0.0 ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU L E S S E R General Public License * * as published by the Free Software Foundation; either Version 2 of the * * License, or (at your option) any later Version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * L E S S E R General Public License for more details. * * * * You should have received a copy of the GNU L E S S E R General * * Public License along with this program; if not, write to the Free * * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * * MA 02110-1301 USA. * * * ***************************************************************************/ %{ #include #include #include "MediaInfo.h" // #define DebugPrintF(...) printf(__VA_ARGS__) #define DebugPrintF(...) // #define LocationPrintF(...) printf(__VA_ARGS__) #define LocationPrintF(...) #define YYDEBUG 1 #define EXIT_NO_MEMORY 2 struct MediaInfoParameterTP* pInput; char pLine[4096]; int NestingIndex; int Nesting = 2; char pParameterIdentifier[4096]; struct list_head* p; %} %code requires { #define YY_DECL int _yylex \ (YYSTYPE * yylval_param, YYLTYPE * yylloc_param ) } %define api.value.type {void*} %define parse.error verbose %define parse.lac full %defines /* create a parser header-file. */ %initial-action { NestingIndex = -1; pParameterIdentifier[0] = 0; yylloc.first_line = yylloc.last_line = 1; yylloc.first_column = yylloc.last_column = 0; } %locations %token COMMENT %token CONSTANT %token LF %token ParameterName %token STRING %token UUID %token WhiteSpace %% input: /* start symbol; must be first. */ %empty { DebugPrintF("y: input: %%empty\n"); pInput = NULL; } | media_info { DebugPrintF("y: input: media_info\n"); pInput = NewMediaInfoParameter( (struct MediaInfoTP*)$1, "" ); }; comment: COMMENT | LF COMMENT | comment COMMENT | comment LF COMMENT ; media_info: method_identifier '(' comment ')' { DebugPrintF("y: media_info: %%empty, comments\n"); $$ = NewMediaInfo( (char*)$1, NewEmptyParameterList() ); } | method_identifier '(' comment parameter_list ')' { /* 1 2 3 4 5 */ DebugPrintF("y: media_info: comments\n"); $$ = NewMediaInfo( (char*)$1, (struct ParameterListTP*)$4 ); } | method_identifier '(' comment parameter_list WhiteSpace ')' { /* 1 2 3 4 5 6 */ DebugPrintF("y: media_info: comments, WhiteSpace\n"); $$ = NewMediaInfo( (char*)$1, (struct ParameterListTP*)$4 ); } | method_identifier '(' LF ')' { DebugPrintF("y: media_info: %%empty\n"); $$ = NewMediaInfo( (char*)$1, NewEmptyParameterList() ); } | method_identifier '(' LF WhiteSpace ')' { DebugPrintF("y: media_info: %%empty, WhiteSpace\n"); $$ = NewMediaInfo( (char*)$1, NewEmptyParameterList() ); } | method_identifier '(' LF parameter_list ')' { /* 1 2 3 4 5 */ DebugPrintF("y: media_info:\n"); $$ = NewMediaInfo( (char*)$1, (struct ParameterListTP*)$4 ); } | method_identifier '(' LF parameter_list WhiteSpace ')' { /* 1 2 3 4 5 6 */ DebugPrintF("y: media_info: WhiteSpace:\n"); $$ = NewMediaInfo( (char*)$1, (struct ParameterListTP*)$4 ); } | media_info LF { DebugPrintF("y: media_info: media_info LF\n"); $$ = $1; }; media_info_value: '\'' media_info '\'' { /* 1 2 3 */ DebugPrintF("y: value: media_info\n"); $$ = $2; }; method_identifier: '{' UUID '}' { /* 1 2 3 */ DebugPrintF("y: method_identifier: {%s}, %d\n", $2, NestingIndex); LocationPrintF("y: method_identifier: %d,%d,%d,%d\n", @1.first_line, @1.first_column, @3.last_line, @3.last_column); $$ = strdup($2); free($2); }; media_info_parameter_declaration: _media_info_parameter_declaration LF { $$ = $1; } | _media_info_parameter_declaration comment { DebugPrintF("y: media_info_parameter_declaration comment LF\n"); $$ = $1; }; | _media_info_parameter_declaration comment LF { DebugPrintF("y: media_info_parameter_declaration comment LF\n"); $$ = $1; }; parameter_declaration: _parameter_declaration LF { $$ = $1; } | _parameter_declaration comment { DebugPrintF("y: parameter_declaration comment \n"); $$ = $1; }; | _parameter_declaration comment LF { DebugPrintF("y: parameter_declaration comment LF\n"); $$ = $1; }; parameter_identifier: ParameterName { DebugPrintF("y: parameter_identifier: ParameterName: %s\n", $1); LocationPrintF("y: parameter_identifier: %d,%d,%d,%d\n", @1.first_line, @1.first_column, @1.last_line, @1.last_column); strcpy(pParameterIdentifier, $1); free($1); $$ = strdup(pParameterIdentifier); pParameterIdentifier[0] = 0; } | ParameterName '[' CONSTANT ']' { /* 1 2 3 4 */ DebugPrintF("y: parameter_identifier: CONSTANT %s[%s]\n", $1, $3); LocationPrintF("y: parameter_identifier: %d,%d,%d,%d\n", @1.first_line, @1.first_column, @4.last_line, @4.last_column); strcpy(pParameterIdentifier, $1); free($1); strcat(pParameterIdentifier, "["); strcat(pParameterIdentifier, $3); free($3); strcat(pParameterIdentifier, "]"); $$ = strdup(pParameterIdentifier); pParameterIdentifier[0] = 0; }; parameter_list: media_info_parameter_declaration { DebugPrintF("y: parameter_list: media_info_parameter_declaration\n"); $$ = NewParameterListMediaInfo( (struct MediaInfoParameterTP*)$1 ); } | parameter_declaration { DebugPrintF("y: parameter_list: parameter_declaration\n"); $$ = NewParameterListParameter( (struct ParameterTP*)$1 ); } | parameter_list media_info_parameter_declaration { DebugPrintF("y: parameter_list: media_info_parameter_list\n"); $$ = AddParameterListMediaInfo( (struct MediaInfoParameterTP*)$2, (struct ParameterListTP*)$1 ); }; | parameter_list parameter_declaration { DebugPrintF("y: parameter_list: parameter_list\n"); $$ = AddParameterListParameter( (struct ParameterTP*)$2, (struct ParameterListTP*)$1 ); }; value: STRING { DebugPrintF("y: value: STRING = %s\n", $1); $$ = strdup($1); free($1); }; _media_info_parameter_declaration: WhiteSpace parameter_identifier '=' media_info_value { /* 1 2 3 4 */ DebugPrintF( "y: parameter_declaration: %s = %s\n", $2, ((struct MediaInfoTP*)$4)->pMethodIdentifier ); $$ = NewMediaInfoParameter( (struct MediaInfoTP*)$4, (char*)$2 ); }; _parameter_declaration: WhiteSpace parameter_identifier '=' value { /* 1 2 3 4 */ DebugPrintF("y: parameter_declaration: %s = %s\n", $2, $4); $$ = NewParameter( (char*)$2, (char*)$4 ); }; %% YY_DECL; int yylex() { yylloc.first_line = yylloc.last_line; yylloc.first_column = yylloc.last_column; return _yylex(&yylval, &yylloc); }