%{ /* * libiio - Library for interfacing industrial I/O (IIO) devices * * Copyright (C) 2014 Analog Devices, Inc. * Author: Paul Cercueil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * */ #include "parser.h" #include "ops.h" #include %} %option noyywrap reentrant bison-bridge nounistd nounput noinput WORD (([[:alpha:]]+,)|(iio:))?(-|_|\.|[[:alnum:]])+ %s WANT_DEVICE %s WANT_CHN_OR_ATTR %s WANT_CHN %s WANT_ATTR %s WANT_VALUE %% VERSION|version { return VERSION; } PRINT|print { return PRINT; } EXIT|exit|QUIT|quit { return EXIT; } HELP|help { return HELP; } TIMEOUT|timeout { return TIMEOUT; } OPEN|open { BEGIN(WANT_DEVICE); return OPEN; } CLOSE|close { BEGIN(WANT_DEVICE); return CLOSE; } READ|read { BEGIN(WANT_DEVICE); return READ; } READBUF|readbuf { BEGIN(WANT_DEVICE); return READBUF; } WRITEBUF|writebuf { BEGIN(WANT_DEVICE); return WRITEBUF; } WRITE|write { BEGIN(WANT_DEVICE); return WRITE; } SETTRIG|settrig { BEGIN(WANT_DEVICE); return SETTRIG; } GETTRIG|gettrig { BEGIN(WANT_DEVICE); return GETTRIG; } SET|set { BEGIN(WANT_DEVICE); return SET; } {WORD} { struct parser_pdata *pdata = yyget_extra(yyscanner); struct iio_device *dev = iio_context_find_device(pdata->ctx, yytext); yylval->dev = dev; pdata->dev = dev; BEGIN(WANT_CHN_OR_ATTR); return DEVICE; } BUFFERS_COUNT|buffers_count { BEGIN(WANT_VALUE); return BUFFERS_COUNT; } DEBUG|debug { BEGIN(WANT_ATTR); return DEBUG_ATTR; } BUFFER|buffer { BEGIN(WANT_ATTR); return BUFFER_ATTR; } INPUT|input|OUTPUT|output { struct parser_pdata *pdata = yyget_extra(yyscanner); pdata->channel_is_output = yytext[0] == 'o' || yytext[0] == 'O'; BEGIN(WANT_CHN); return IN_OUT; } {WORD} { struct parser_pdata *pdata = yyget_extra(yyscanner); struct iio_channel *chn = NULL; if (pdata->dev) chn = iio_device_find_channel(pdata->dev, yytext, pdata->channel_is_output); yylval->chn = chn; pdata->chn = chn; BEGIN(WANT_ATTR); return CHANNEL; } {WORD} { yylval->value = strtol(yytext, NULL, 10); return VALUE; } CYCLIC|cyclic { return CYCLIC; } {WORD} { yylval->word = strdup(yytext); return WORD; } [ \t]+ { return SPACE; } [ \t]*\r?\n { BEGIN(INITIAL); return END; } . { BEGIN(INITIAL); }