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

Subversion Repositories sc2v

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

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 31 jcastillo
 *  Provided by Universidad Rey Juan Carlos
5 4 jcastillo
 *
6
 * -----------------------------------------------------------------------------
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU Library General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 */
21
 
22
 
23
%{
24
#include 
25
#include 
26
 
27 12 jcastillo
  int module_found = 0;
28
  int concat_found = 0;
29
  int opened_pars;
30
  int *concat_par_num;
31
  int concats_found = 0;
32 16 jcastillo
  int lastsymbol=0;
33 12 jcastillo
  char *aux;
34
  void yyerror (const char *str)
35
  {
36
    fprintf (stderr, "error: %s\n", str);
37
  }
38 4 jcastillo
 
39 12 jcastillo
  int yywrap ()
40
  {
41
    return 1;
42
  }
43 4 jcastillo
 
44 12 jcastillo
  main ()
45
  {
46
    concat_par_num = (int *) malloc (16 * sizeof (int));
47
    *concat_par_num = 0;
48
    yyparse ();
49 4 jcastillo
 
50 12 jcastillo
  }
51
 
52 4 jcastillo
%}
53
 
54 16 jcastillo
%token WORD WORDCOLON
55 4 jcastillo
%token OPENPAR CLOSEPAR
56 16 jcastillo
%token MODULE SYMBOL
57 4 jcastillo
 
58 12 jcastillo
%% commands:
59
/* empty */
60
|commands command;
61 4 jcastillo
 
62
 
63
command:
64 12 jcastillo
module
65
|
66
closepar
67
|
68
concat
69 16 jcastillo
|
70
openpar
71
|
72
word
73
|
74
symbol;
75 4 jcastillo
 
76
module:
77 12 jcastillo
MODULE
78
{
79 16 jcastillo
  lastsymbol=0;
80 12 jcastillo
  module_found = 1;
81
  opened_pars++;
82
  printf ("%s", (char *) $1);
83
};
84
 
85 4 jcastillo
openpar:
86 12 jcastillo
OPENPAR
87
{
88
  printf ("(");
89
  opened_pars++;
90
};
91 4 jcastillo
 
92
closepar:
93 12 jcastillo
CLOSEPAR
94
{
95
  if (module_found)
96
    {
97
      printf (")");
98
      opened_pars--;
99
      module_found = 0;
100
    }
101
  else if (concat_found)
102
    {
103
      if (opened_pars == *(concat_par_num + concats_found))
104 4 jcastillo
        {
105 12 jcastillo
          printf ("}");
106
          concats_found--;
107
          if (concats_found == 0)
108
            {
109
              concat_found = 0;
110
            }
111
        }
112
      else
113
        {
114
          printf (")");
115
        }
116
      opened_pars--;
117
    }
118
  else
119
    {
120
      opened_pars--;
121
      printf (")");
122
    }
123
};
124 4 jcastillo
 
125
concat:
126 16 jcastillo
WORDCOLON
127 12 jcastillo
{
128 16 jcastillo
 if(lastsymbol==1){
129 12 jcastillo
  aux = (char *) $1;
130
  aux++;
131
  printf ("{%s", aux);
132
  concat_found = 1;
133
  opened_pars++;
134
  concats_found++;
135
  *(concat_par_num + concats_found) = opened_pars;
136 16 jcastillo
 }else{
137
   printf ("%s", (char *)$1);
138
 }
139
 lastsymbol=0;
140 12 jcastillo
};
141 16 jcastillo
 
142
symbol:
143
SYMBOL
144
{
145
  lastsymbol=1;
146
  printf("%c",*((char *)$1));
147
};
148
 
149
word:
150
WORD
151
{
152
  lastsymbol=0;
153
  printf("%s",(char *)$1);
154
};

powered by: WebSVN 2.1.0

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