From ca51f6abf6debc1b6718f59129886fea04ee12b0 Mon Sep 17 00:00:00 2001 From: jacomi Date: Mon, 25 Jan 1999 18:35:13 +0000 Subject: new directory structure and data --- src/gram.y | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/gram.y (limited to 'src/gram.y') diff --git a/src/gram.y b/src/gram.y new file mode 100644 index 0000000..fb03f5d --- /dev/null +++ b/src/gram.y @@ -0,0 +1,195 @@ +%{ + +/* + * + * IRBOX, an Ivy driver for infra-red remote controls + * + * Copyright 1998-1999 + * Centre d'Etudes de la Navigation Aerienne + * + * This is the grammar for reading tables + * + * Authors: Stephane Chatty + * + * $Id$ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + + +extern const char* const ResWords; + + +#include +#include +#include +#include "irtable.h" + +extern int yyparse (); +extern int yylex (); +extern int LineNo; + + +static char id_buf [1024]; /* Yeech */ +static char id_list_buf [4096]; /* Barf */ + +static const char* filename = 0; +static IrTable* cur_table; + +%} + +%union { + const char *name; + int integer; +} + +%token Y_NAME Y_TYPE Y_BRAND Y_EOL +%token Y_ID Y_STRING +%token Y_INT + + +%type id id_list + +%% + +instr_list: + /* empty */ + | instr_list instr + ; + +id: + Y_ID + { + strcpy (id_buf, $1); + free ((char*) $1); /* was allocated by strdup in lex file */ + $$ = id_buf; + } + | Y_INT + { + sprintf (id_buf, "%d", $1); + $$ = id_buf; + } + ; + +id_list: + id + { + strcpy (id_list_buf, $1); + $$ = $1; + } + | id_list id + { + strcat (id_list_buf, " "); + strcat (id_list_buf, $2); + $$ = id_list_buf; + } + ; + +instr: + Y_EOL + + | Y_NAME Y_ID Y_EOL + { + IrTableName (cur_table, $2); + } + + | Y_TYPE ':' Y_ID Y_EOL + { + IrTableType (cur_table, $3); + } + + | Y_BRAND ':' id_list Y_EOL + { + IrTableAddBrand (cur_table, $3); + } + + | id_list ':' Y_INT Y_INT Y_INT Y_INT Y_INT Y_INT Y_EOL + { + IrTableAddKey (cur_table, $1, $3, $4, $5, $6, $7, $8); + } + ; + + +%% +#include + +int _DoTee = 0; + +int +tee (int x) +{ + if (_DoTee) { + char *s; + switch (x) { + case ':': + s = ":"; + break; + case Y_EOL: + s = "Y_EOL\n"; + break; + case Y_STRING: + s = "STRING"; + break; + case Y_INT: + s = "INT"; + break; + case Y_ID: + s = "ID"; + break; + case Y_TYPE: + s = "TYPE"; + break; + case Y_BRAND: + s = "BRAND"; + break; +/* case Y_: + s = ""; + break; +*/ + default : + s = "???"; + break; + } + printf ("%s ", s); + } + return x; +} + + +int +yyerror (const char *s) +{ + fprintf (stderr, "%s in %s, line %d\n", s, filename, LineNo); + return (0); +} + +int +yywrap () +{ + return 1; +} + + +IrTable* +IrTableReadFile (const char* file) +{ + extern void LexInit (); + extern FILE *yyin; + int result; + + LexInit (); + filename = file; + if (!(yyin = fopen (file,"r"))) { + char err [1024]; + fprintf (stderr, "Cannot open %s\n", file); + return 0; + } + cur_table = IrCreateTable (); + if (yyparse ()) { + result = 0; + } + fclose (yyin); + return cur_table; +} + -- cgit v1.1