%{ #include #include #include #include "CLISupport.h" /* * To prevent bison redefining malloc with bison 2.1. */ #define YYINCLUDED_STDLIB_H 1 extern int CLICurrentLine, CLICurrentColumn; int clilex(void); void yyerror(const char *str) { fprintf(stderr, "Error: %s (line %d, column %d)\n", str, CLICurrentLine, CLICurrentColumn); } %} %error-verbose %output="CLIParser.cpp" %name-prefix="cli" %defines %locations %debug %token NUMBER STRING MACADDR OUI_VAL COMMAND IPADDR %token '\n' CMD_DEBUG CMD_DEVICE CMD_LIST CMD_THREAD CMD_STATUS CMD_QUEUE %token CMD_SCAN CMD_SIZE CMD_DETAIL CMD_CONFIG CMD_CLASSIFY CMD_QUIT CMD_HELP CMD_SNIFFER CMD_DEFERRED CMD_PACKET %token CMD_SUBMIT %type NUMBER %type STRING %type MACADDR OUI_VAL %type COMMAND %type IPADDR /* * Note that we must use pointers to objects here because unions can't hold * objects directly. */ %union { char *StrVal; int IntVal; TMacAddress *MacVal; unsigned char OuiVal[3]; TIPAddress *IPVal; } %% input : { printf("> "); } | input line { printf("> "); } | input '\n' { printf("> "); } | input error '\n' { printf("> "); } ; line : COMMAND '\n' { printf("Unknown command: %s\n", $1); } | device_command | thread_command | queue_command | config_command | CMD_QUIT '\n' { CLIQuit(); YYABORT; } | help_command | sniffer_command | deferred_command | packet_command | debug_command ; device_command : CMD_DEVICE CMD_LIST '\n' { CLIListDevices(); } | CMD_DEVICE CMD_LIST CMD_SIZE '\n' { CLIDeviceListSize(); } | CMD_DEVICE CMD_DETAIL '\n' { printf("A device must be specified by IP address or MAC address\n"); } | CMD_DEVICE CMD_DETAIL IPADDR '\n' { CLIDeviceDetail(*$3); } | CMD_DEVICE CMD_DETAIL MACADDR '\n' { CLIDeviceDetail(*$3); } | CMD_CLASSIFY IPADDR '\n' { CLIClassifyDevice(*$2); } | CMD_CLASSIFY MACADDR '\n' { CLIClassifyDevice(*$2); } | CMD_SCAN CMD_DEVICE IPADDR '\n' { CLIScanDevice(*$3); } | CMD_SUBMIT CMD_DEVICE IPADDR '\n' { CLISubmitDevice(*$3); } | CMD_SUBMIT CMD_DEVICE MACADDR '\n' { CLISubmitDevice(*$3); } ; thread_command : CMD_THREAD CMD_STATUS '\n' { CLIThreadStatus(); } ; queue_command : CMD_SCAN CMD_QUEUE CMD_LIST '\n' { CLIListScanQueue(); } | CMD_SCAN CMD_QUEUE CMD_SIZE '\n' { CLIScanQueueSize(); } ; config_command : CMD_CONFIG '\n' { CLIShowConfig(); } ; help_command : CMD_HELP '\n' { CLIHelp(); } ; sniffer_command : CMD_SNIFFER CMD_STATUS '\n' { CLISnifferStatus(); } ; deferred_command : CMD_DEFERRED CMD_LIST '\n' { CLIListDeferred(); } | CMD_DEFERRED CMD_SIZE '\n' { CLIDeferredSize(); } ; packet_command : CMD_PACKET CMD_QUEUE CMD_SIZE '\n' { CLIPktQueueSize(); } ; debug_command: CMD_DEBUG NUMBER '\n' { CLIDebug($2); } ;