diff options
author | jacomi | 1999-01-25 18:35:13 +0000 |
---|---|---|
committer | jacomi | 1999-01-25 18:35:13 +0000 |
commit | ca51f6abf6debc1b6718f59129886fea04ee12b0 (patch) | |
tree | b074cbd71c73bfa0d39a28f73e19cd8d28a653f6 /gram.y | |
parent | f63e7d593f9a1ca8152ec8180ac052e75c892a60 (diff) | |
download | irbox-ca51f6abf6debc1b6718f59129886fea04ee12b0.zip irbox-ca51f6abf6debc1b6718f59129886fea04ee12b0.tar.gz irbox-ca51f6abf6debc1b6718f59129886fea04ee12b0.tar.bz2 irbox-ca51f6abf6debc1b6718f59129886fea04ee12b0.tar.xz |
new directory structure and data
Diffstat (limited to 'gram.y')
-rw-r--r-- | gram.y | 195 |
1 files changed, 0 insertions, 195 deletions
@@ -1,195 +0,0 @@ -%{ - -/* - * - * 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 <chatty@cenatoulouse.dgac.fr> - * - * $Id$ - * - * Please refer to file version.h for the - * copyright notice regarding this software - */ - - -extern const char* const ResWords; - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#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 <name> Y_ID Y_STRING -%token <integer> Y_INT - - -%type <name> 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 <stdio.h> - -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; -} - |