/* * 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 * . */ %{ #include #include #include #include "parser.h" #define YY_INPUT(buf, result, max_size) { result = get_input (buf, max_size); } #define YY_USER_ACTION { prompt_type = 2; } int prompt_type = 1; int get_input (char *buf, int max_size) { int c; static int need_prompt = 1; (void) max_size; if (need_prompt) { if (prompt_type == 1) { printf ("%s", marchande_main_prompt ()); } else { printf ("%s", marchande_secondary_prompt ()); } need_prompt = 0; } c = getchar (); if (c == '\n') { need_prompt = 1; } if (c == EOF) { return YY_NULL; } buf[0] = c; return 1; } %} %% that { return THAT; } will { return WILL; } be { return BE; } all { return ALL; } [0-9]+ { yylval.INTEGER = (unsigned int) strtoul (yytext, NULL, 10); return INTEGER; } [0-9]+\.[0-9]* { yylval.DECIMAL = strtod (yytext, NULL); return DECIMAL; } of { return OF; } kg { return KG; } a { return A; } bunch { return BUNCH; } bunches { return BUNCHES; } potatoes { return POTATOES; } radishes { return RADISHES; } [ \t\n]+ /* do nothing */ [^ \t\n.,?!0-9]+ { yylval.UNKNOWN_WORD = strdup (yytext); return UNKNOWN_WORD; } [.,?!] { return END_OF_PHRASE; }