File: parse.y

package info (click to toggle)
gputils 0.13.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 16,620 kB
  • ctags: 3,066
  • sloc: pascal: 191,182; ansic: 18,644; sh: 3,391; makefile: 1,293; lex: 991; yacc: 917
file content (232 lines) | stat: -rw-r--r-- 3,575 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
%{
/* Parser for linker scripts
   Copyright (C) 2001, 2002, 2003, 2004, 2005
   Craig Franklin

This file is part of gputils.

gputils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

gputils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with gputils; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "stdhdr.h"

#include "libgputils.h"
#include "gplink.h"
#include "scan.h"
#include "script.h"

void yyerror(char *message)
{
  script_error(message, NULL);
}

int yylex(void);

/************************************************************************/

/* Some simple functions for building parse trees */

static struct pnode *mk_pnode(enum pnode_tag tag)
{
  struct pnode *new = malloc(sizeof(*new));
  new->tag = tag;
  return new;
}

struct pnode *mk_constant(int value)
{
  struct pnode *new = mk_pnode(constant);
  new->value.constant = value;
  return new;
}

static struct pnode *mk_symbol(char *value)
{
  struct pnode *new = mk_pnode(symbol);
  new->value.symbol = value;
  return new;
}

/*
static struct pnode *mk_string(char *value)
{
  struct pnode *new = mk_pnode(string);
  new->value.string = value;
  return new;
}

*/

struct pnode *mk_list(struct pnode *head, struct pnode *tail)
{
  struct pnode *new = mk_pnode(list);
  new->value.list.head = head;
  new->value.list.tail = tail;
  return new;
}

static struct pnode *mk_2op(int op, struct pnode *p0, struct pnode *p1)
{
  struct pnode *new = mk_pnode(binop);
  new->value.binop.op = op;
  new->value.binop.p0 = p0;
  new->value.binop.p1 = p1;
  return new;
}

/*
static struct pnode *mk_1op(int op, struct pnode *p0)
{
  struct pnode *new = mk_pnode(unop);  new->value.unop.op = op;
  new->value.unop.p0 = p0;
  return new;
}

*/

%}

/* Bison declarations */

%union {
  int i;
  char *s;
  struct pnode *p;
}

%token <s> SYMBOL
%token <s> LIBPATH
%token <s> LKRPATH
%token <s> PATH
%token <s> LEXEOF
%token <i> NUMBER
%type <i> '='
%type <i> e1op

%type <s> line
%type <p> e0
%type <p> e1
%type <p> parameter_list
%type <p> path_list 

%%
/* Grammar rules */

program:
	/* can be nothing */
	|
	program 
        { 
          /* do nothing */
        } line
	| program error '\n'
	{ 
          /* do nothing */
	}
	;

line:
	'\n'
	{
          /* do nothing */
	}
	|
	LEXEOF
	{
	  YYACCEPT;
	}
	|
	LIBPATH path_list '\n'
	{
	  add_path($2);
	}
	|
	LIBPATH path_list LEXEOF
	{
	  add_path($2);
	  YYACCEPT;
	}
	|
	LKRPATH path_list '\n'
	{
	  add_path($2);
	}
	|
	LKRPATH path_list LEXEOF
	{
	  add_path($2);
	  YYACCEPT;
	}
	|
	SYMBOL parameter_list '\n'
	{
	  execute_command($1, $2);
	}
	|
	SYMBOL parameter_list LEXEOF
	{
	  execute_command($1, $2);
	  YYACCEPT;
	}
	;

path_list:
	SYMBOL
	{
	  $$ = mk_list(mk_symbol($1), NULL);
	}
	|
	SYMBOL ';' path_list
	{
	  $$ = mk_list(mk_symbol($1), $3);
	}
	;

parameter_list:
	e1
	{
	  $$ = mk_list($1, NULL);
	}
	|
	e1  parameter_list
	{
	  $$ = mk_list($1, $2);
	}
	;

e1:
	e0
	|
	e1 e1op e0
	{
	  $$ = mk_2op($2, $1, $3);
	}
	;

e1op:	'=' ;

e0:
	SYMBOL
        {
	  $$ = mk_symbol($1);
        }
	|
	NUMBER
	{
	  $$ = mk_constant($1);
	}
	;

%%