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

Subversion Repositories sc2v

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

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

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

powered by: WebSVN 2.1.0

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