/* * --- GSMP-COPYRIGHT-NOTE-BEGIN --- * * This copyright note is auto-generated by ./scripts/Create-CopyPatch. * Please add additional copyright information _after_ the line containing * the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by * the ./scripts/Create-CopyPatch script. Do not edit this copyright text! * * GSMP: dam/utility/regtester/TestParser.y * General Sound Manipulation Program is Copyright (C) 2000 - 2004 * Valentin Ziegler and René Rebe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2. A copy of the GNU General * Public License can be found in the file LICENSE. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT- * ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * --- GSMP-COPYRIGHT-NOTE-END --- */ /* * */ %{ #include "Utils.h" #include "TestParserActions.h" #include extern int bool_val; extern int int_val; extern char* id; %} %union{ declaration_list declarations; declaration_struct declaration; assigment_list assigments; assigment_struct assigment; param_list parameters; param_struct parameter; bool_func func_b; int_func func_i; int i_value; int b_value; char* text; }; %token C_BLOCK %token PRELUDE %token MULTIPLE %token STARTUP %token ACTION %token EQ %token LEQ %token GEQ %token NEQ %token BOOL_CONST %token INT_CONST %token ID %token GLOBAL %% input_list: input input_list | ; input: prelude | startup | global | multiple | action ; prelude: PRELUDE c_block { PreludeAppend ($2); } ; startup: STARTUP c_block { StartupAppend ($2); } ; global: GLOBAL '{' decl_list '}' { GlobalInsert ($3); } ; multiple: MULTIPLE int_const id c_block '{' decl_list '}' { CreateLocal ( $3, $2, $6, $4); } ; action: ACTION id '(' param_list ')' { DefineScopes ($4); } '{' bool_expr '}' c_block '{' assigment_list '}' { CreateAction ($2, $4, $7, $11, $9 ) } ; decl_list: decl decl_list { $$ = ChainDeclaration ($1, $2 );} | { $$ = DeclListEnd (); } ; decl: id bool_expr c_block { $$ = CreateDeclaration ($1, $2, $3); } | id bool_expr { $$ = CreateDeclaration ($1, $2, "" ); } ; assigment_list: assigment assigment_list { $$ = ChainAssigment ($1, $2 );} | { $$ = AssigmentListEnd (); } ; assigment: id bool_expr c_block { $$ = CreateSimpleAssigment ($1, $2, $3); } | id bool_expr { $$ = CreateSimpleAssigment ($1, $2, ""); } | id '.' id bool_expr c_block { $$ = CreateScopedAssigment ($1, $3, $4, $5); } | id '.' id bool_expr { $$ = CreateScopedAssigment ($1, $3, $4, ""); } ; param_list: param { $$ = ParameterListEnd ($1);} | param ',' param_list { $$ = ChainParameter ($1, $3 );} | ; param: id id { $$ = CreateParameter ($1, $2);} ; bool_expr: bool_term { $$ = $1; } | bool_expr '|' bool_term { $$ = BOP_or ($1, $2);} | bool_expr '^' bool_term { $$ = BOP_xor ($1, $2);} ; bool_term: bool_factor { $$ = $1; } | bool_term '&' bool_factor { $$ = BOP_and ($1, $3); } ; bool_factor: trivial_bool { $$ = $1; } | '!' trivial_bool { $$ = BOP_neg ($2); } ; trivial_bool: '(' bool_expr ')' { $$ = $2; } | '$' compare '$' { $$ = $2; } | id { $$ = BOP_ref ($1);} | id '.' id { $$ = BOP_scoped_ref ($1, $3);} | bool_const { $$ = BOP_const ($1);} ; compare: int_expr '<' int_expr { $$ = CMP_le($1, $3);} | int_expr '>' int_expr { $$ = CMP_ge($1, $3);} | int_expr EQ int_expr { $$ = CMP_eq($1, $3);} | int_expr LEQ int_expr { $$ = CMP_leq($1, $3);} | int_expr GEQ int_expr { $$ = CMP_geq($1, $3);} | int_expr NEQ int_expr { $$ = CMP_neq($1, $3);} ; int_expr: int_term {$$ = $1;} | int_expr '+' int_term {$$ = IOP_add ($1, $3);} | int_expr '-' int_term {$$ = IOP_sub ($1, $3);} ; int_term: int_factor {$$ = $1;} | int_term '*' int_factor {$$ = IOP_mul ($1, $3);} | int_term '/' int_factor {$$ = IOP_div ($1, $3);} | int_term '%' int_factor {$$ = IOP_mod ($1, $3);} ; int_factor: trivial_int {$$ = $1;} | '-' trivial_int {$$ = IOP_neg($2);} ; trivial_int: '(' int_expr ')' {$$ = $2;} | int_const {$$ = IOP_const($1);} | '#' {$$ = IOP_self_id ();} | id '.' '#' {$$ = IOP_scoped_id ($1);} ; id: ID { $$ = strdup (id); } ; c_block: C_BLOCK { $$ = strdup (TextGet ());} ; int_const: INT_CONST { $$ = int_val; } ; bool_const: BOOL_CONST { $$ = bool_val; } ;