~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to src/disp-vcd/config_parser.y

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
Import upstream version 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: config_parser.y,v 1.2 2002/11/17 00:29:20 troth Exp $
 
3
 *
 
4
 ****************************************************************************
 
5
 *
 
6
 * simulavr-vcd - A vcd file writer as display process for simulavr.
 
7
 * Copyright (C) 2002  Carsten Beth
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 *
 
23
 ****************************************************************************
 
24
 */
 
25
 
 
26
%{
 
27
 
 
28
#include <stdlib.h>
 
29
#include <stdio.h>
 
30
#include <string.h>
 
31
#include "vcd.h"
 
32
 
 
33
extern void config_scanner_init( FILE *infile );
 
34
extern int config_lex( void );
 
35
 
 
36
void config_error( char *s );
 
37
int parse_config( FILE *infile );
 
38
 
 
39
extern char *config_text;
 
40
int          errorFound;
 
41
 
 
42
%}
 
43
 
 
44
%token CP_FREQUENCY
 
45
%token CP_VCD_FILE
 
46
%token CP_TRACE
 
47
 
 
48
%token CP_SRAM
 
49
%token CP_EEPROM
 
50
%token CP_PROGMEM
 
51
%token CP_REG
 
52
%token CP_FREG
 
53
%token CP_IOREG
 
54
%token CP_SP
 
55
%token CP_PC
 
56
 
 
57
%token CP_NAME
 
58
%token CP_FILENAME
 
59
%token CP_NUMBER
 
60
 
 
61
%right '[' ']' ':' '=' '\n'
 
62
 
 
63
%union
 
64
{
 
65
    int  integer;
 
66
    char *string;
 
67
    struct
 
68
    {
 
69
        int from;
 
70
        int to;
 
71
    } t_range;
 
72
};
 
73
 
 
74
%type  <t_range> range
 
75
%type  <string>  name
 
76
%type  <string>  filename
 
77
%type  <integer> number
 
78
 
 
79
/* Grammar follows */
 
80
 
 
81
%%
 
82
 
 
83
conf_file:
 
84
    frequency_def vcd_file_def trace_defs;
 
85
 
 
86
 
 
87
frequency_def:
 
88
    CP_FREQUENCY '=' number '\n'
 
89
    {
 
90
        vcd_set_frequency( $3 );
 
91
    };
 
92
 
 
93
vcd_file_def:
 
94
    CP_VCD_FILE '=' name '\n'
 
95
    {
 
96
        vcd_set_file_name( $3 );
 
97
    }
 
98
    | CP_VCD_FILE '=' filename '\n'
 
99
    {
 
100
        vcd_set_file_name( $3 );
 
101
    };
 
102
 
 
103
trace_defs:
 
104
  /* empty */
 
105
  | '\n'
 
106
  | trace_defs CP_TRACE trace_def '\n'
 
107
  | error '\n' { yyerrok; };
 
108
 
 
109
trace_def:
 
110
  CP_SRAM range
 
111
    {
 
112
        int i;
 
113
        for( i = $2.from; i <= $2.to; i++ )
 
114
            vcd_trace_sram( i );
 
115
    }
 
116
  | CP_EEPROM range
 
117
  | CP_PROGMEM range
 
118
  | CP_REG range
 
119
    {
 
120
        int i;
 
121
        for( i = $2.from; i <= $2.to; i++ )
 
122
            vcd_trace_reg( i );
 
123
    }
 
124
  | CP_REG name
 
125
    {
 
126
        free( $2 );
 
127
    }
 
128
  | CP_IOREG range
 
129
    {
 
130
        int i;
 
131
        for( i = $2.from; i <= $2.to; i++ )
 
132
            vcd_trace_io_reg( NULL, i );
 
133
    }
 
134
  | CP_IOREG name
 
135
    {
 
136
        vcd_trace_io_reg( $2, -1 );
 
137
        free( $2 );
 
138
    }
 
139
  | CP_SP
 
140
    {
 
141
        vcd_trace_sp();
 
142
    }
 
143
  | CP_PC
 
144
    {
 
145
        vcd_trace_pc();
 
146
    };
 
147
 
 
148
range:
 
149
    number
 
150
    {
 
151
        $$.from = $1;
 
152
        $$.to   = $1;
 
153
    }
 
154
  | '[' number ':' number ']'
 
155
    {
 
156
        $$.from = $2;
 
157
        $$.to   = $4;
 
158
    };
 
159
 
 
160
name:
 
161
    CP_NAME
 
162
    {
 
163
        $$ = (char *)malloc( strlen( config_text ) + 1 );
 
164
        strcpy( $$, config_text );
 
165
    };
 
166
 
 
167
filename:
 
168
    CP_FILENAME
 
169
    {
 
170
        $$ = (char *)malloc( strlen( config_text ) + 1 );
 
171
        strcpy( $$, config_text );
 
172
    };
 
173
 
 
174
number:
 
175
    CP_NUMBER
 
176
    {
 
177
        $$ = atoi( config_text );
 
178
    };
 
179
 
 
180
/* End of grammar */
 
181
 
 
182
%%
 
183
 
 
184
extern int config_get_line (void);
 
185
 
 
186
/*************************************************************************
 
187
 * Funktion    : mapping_error() gibt den als Parameter �bergebenen String
 
188
 *               auf dem Standard-Fehlerkanal aus. Diese Funktion wird von 
 
189
 *               mapping_parse() aufgerufen, wenn ein ihr ein Fehler gefunden 
 
190
 *               wurde.
 
191
 * Parameter   : s - Auszugebender Fehlertext
 
192
 * Vorbeding.  : -
 
193
 * Nachbeding. : -
 
194
 * Return      : -
 
195
 *************************************************************************/
 
196
void config_error( char *s )
 
197
{
 
198
  errorFound = 1;
 
199
  fprintf( stderr, "line %i: %s\n", config_get_line(), s );
 
200
}
 
201
 
 
202
/*************************************************************************
 
203
 * Funktion    : 
 
204
 * Parameter   : 
 
205
 * Vorbeding.  : -
 
206
 * Nachbeding. : 
 
207
 * Return      : 
 
208
 *************************************************************************/
 
209
int parse_config( FILE *infile )
 
210
{
 
211
    int rv;
 
212
 
 
213
    errorFound = 0;
 
214
 
 
215
    /* Scanner iniitialization. */
 
216
    config_scanner_init( infile );
 
217
 
 
218
    /* Parse the data. */
 
219
    rv = config_parse();
 
220
    if ( errorFound || (rv != 0) )
 
221
        return( 0 );
 
222
 
 
223
    return( 1 );
 
224
}
 
225