OpenCores
URL https://opencores.org/ocsvn/sc2v/sc2v/trunk

Subversion Repositories sc2v

[/] [sc2v/] [trunk/] [src/] [sc2v_step3.y] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 jcastillo
/* -----------------------------------------------------------------------------
2
 *
3
 *  SystemC to Verilog Translator v0.2
4
 *  Provided by OpenSoc Design
5
 *
6
 *  www.opensocdesign.com
7
 *
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 Library 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
#include 
27
#include 
28
 
29
int module_found = 0;
30
int concat_found = 0;
31
int opened_pars;
32
int *concat_par_num;
33
int concats_found = 0;
34
char *aux;
35
void yyerror(const char *str)
36
{
37
        fprintf(stderr,"error: %s\n",str);
38
}
39
 
40
int yywrap()
41
{
42
        return 1;
43
}
44
 
45
main()
46
{
47
        concat_par_num = (int *)malloc(16*sizeof(int));
48
        *concat_par_num = 0;
49
        yyparse();
50
 
51
}
52
 
53
%}
54
 
55
%token WORD
56
%token OPENPAR CLOSEPAR
57
%token MODULE
58
 
59
%%
60
 
61
commands: /* empty */
62
        | commands command
63
        ;
64
 
65
 
66
command:
67
        module
68
        |
69
        closepar
70
        |
71
        concat
72
        |
73
        openpar
74
        ;
75
 
76
module:
77
        MODULE
78
        {
79
                module_found = 1;
80
                opened_pars++;
81
                printf("%s",(char *)$1);
82
        };
83
openpar:
84
        OPENPAR
85
        {
86
                printf("(");
87
                opened_pars++;
88
        };
89
 
90
closepar:
91
        CLOSEPAR
92
        {
93
                if(module_found)
94
                {
95
                        printf(")");
96
                        opened_pars--;
97
                        module_found = 0;
98
                }
99
                else if(concat_found)
100
                {
101
                     if(opened_pars == *(concat_par_num + concats_found))
102
                        {
103
                        printf("}");
104
                        concats_found--;
105
                        if(concats_found == 0)
106
                         {
107
                          concat_found = 0;
108
                         }
109
                        }
110
                     else
111
                        {
112
                         printf(")");
113
                        }
114
                     opened_pars--;
115
                }
116
                else
117
                {
118
                        opened_pars--;
119
                        printf(")");
120
                }
121
        };
122
 
123
concat:
124
        WORD
125
        {
126
                aux = (char *)$1;
127
                aux++;
128
                printf("{%s",aux);
129
                concat_found = 1;
130
                opened_pars++;
131
                concats_found++;
132
                *(concat_par_num + concats_found) = opened_pars;
133
        };

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.