/* * 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 "parser.h" #include #include #define YY_INPUT(buf, result, max_size) { \ result = yyextra.behavior->pull_char (yyextra.behavior->data, * (yyextra.prompt_type), buf); \ } #define YY_USER_ACTION { \ * (yyextra.prompt_type) = 2; \ yyextra.behavior->before_token (yyextra.behavior->data, yytext); \ } #define YYSTYPE _MARCHANDE_STYPE %} %option extra-type="marchande_lexer_extra" %option bison-bridge %option prefix="_marchande_" %option reentrant %% %{ int ret; if (yyextra.behavior->prologue (yyextra.behavior->data, &ret, yylval)) { return ret; } %} 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; } %% void marchande_parse (marchande_parser_behavior *behavior) { int prompt_type = 1; marchande_lexer_extra extra; yyscan_t scanner; extra.prompt_type = &prompt_type; extra.behavior = behavior; _marchande_lex_init_extra (extra, &scanner); _marchande_parse (behavior, &prompt_type, scanner); _marchande_lex_destroy (scanner); }