/* * Copyright (C) 2019 Vivien Kraus * * 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, either version 3 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see * . */ %code requires { #include #include #include } %{ #include #include #include #include #include #define _(String) String int _marchande_lex (_MARCHANDE_STYPE *yylval, void *scanner); void _marchande_error (marchande_parser_behavior *behavior, int *prompt_type, void *scanner, const char *error) { (void) error; } int _marchande_wrap () { return 1; } %} %define api.pure full %parse-param {marchande_parser_behavior *behavior} %parse-param {int *prompt_type} %param {void * scanner} %define api.prefix {_marchande_} %define api.value.type union %token THAT %token WILL %token BE %token ALL %token A %token KG %token BUNCH %token BUNCHES %token OF %token POTATOES %token RADISHES %token END_OF_PHRASE %token INTEGER %token DECIMAL %token UNKNOWN_WORD %destructor { free ($$); } UNKNOWN_WORD %type bunches %type weight %% interaction: %empty | interaction command | interaction error END_OF_PHRASE { *prompt_type = 1; behavior->syntax_error (behavior->data); yyerrok; } command: THAT WILL BE ALL { YYACCEPT; } | weight OF POTATOES { behavior->buy_potatoes (behavior->data, $1); *prompt_type = 1; } | bunches OF RADISHES { behavior->buy_radishes (behavior->data, $1); *prompt_type = 1; } | weight OF UNKNOWN_WORD { behavior->value_error (behavior->data, $3); *prompt_type = 1; free ($3); } | bunches OF UNKNOWN_WORD { behavior->value_error (behavior->data, $3); *prompt_type = 1; free ($3); } weight: DECIMAL KG { $$ = $1; } | INTEGER KG { $$ = (double) $1; } ; bunches: A BUNCH { $$ = 1; } | INTEGER BUNCHES { $$ = $1; } ; %%