xref: /netbsd/usr.sbin/gspa/gspa/gsp_gram.y (revision bf9ec67e)
1 /*	$NetBSD: gsp_gram.y,v 1.3 2001/06/13 10:46:06 wiz Exp $	*/
2 /*
3  * Yacc syntax for GSP assembler
4  *
5  * Copyright (c) 1993 Paul Mackerras.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Paul Mackerras.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* declarations */
35 
36 %{
37 #include <sys/cdefs.h>
38 #ifndef lint
39 __RCSID("$NetBSD: gsp_gram.y,v 1.3 2001/06/13 10:46:06 wiz Exp $");
40 #endif
41 
42 #include <stdio.h>
43 #include "gsp_ass.h"
44 %}
45 
46 %union {
47 	long		y_int;
48 	char		*y_id;
49 	expr		y_expr;
50 	operand		y_opnd;
51 }
52 
53 %token LEFT_SHIFT, RIGHT_SHIFT
54 
55 %term <y_id>	ID, STRING
56 %term <y_int>	NUMBER, REGISTER
57 %term UMINUS
58 
59 /* operator precedences - lowest to highest */
60 %nonassoc ':'		/* concatenate y:x */
61 %left LEFT_SHIFT, RIGHT_SHIFT
62 %left '^'		/* EXCLUSIVE OR operator */
63 %left '|'		/* OR operator */
64 %left '&'		/* AND operator */
65 %left '+', '-'
66 %left '*', '/'
67 %nonassoc '~', UMINUS	/* NOT operator */
68 
69 %start line
70 
71 /* types of non-terminals */
72 %type <y_expr>		expr
73 %type <y_opnd>		operand, operands, ea
74 
75 %%
76 /* rules */
77 
78 line		: label ID operands	{ statement($2, $3); }
79 		| ID operands		{ statement($1, $2); }
80 		| label
81 		| ID '=' expr		{ do_asg($1, $3, 0); }
82 		| /* empty */
83 		| error
84 		;
85 
86 label		: ID ':'		{ set_label($1); }
87 		| NUMBER ':'		{ set_numeric_label($1); }
88 		;
89 
90 operands	: /* empty */		{ $$ = NULL; }
91 		| operand		{ $$ = $1; }
92 		| operands ',' operand	{ $$ = add_operand($1, $3); }
93 		;
94 
95 operand		: REGISTER		{ $$ = reg_op($1); }
96 		| ea			{ $$ = $1; }
97 		| expr			{ $$ = expr_op($1); }
98 		| STRING		{ $$ = string_op($1); }
99 		;
100 
101 ea		: '@' expr		{ $$ = abs_adr($2); }
102 		| '*' REGISTER		{ $$ = reg_ind($2, M_IND); }
103 		| '*' REGISTER ID	{ $$ = reg_indxy($2, $3); }
104 		| '*' REGISTER '+'	{ $$ = reg_ind($2, M_POSTINC); }
105 		| '*' '-' REGISTER	{ $$ = reg_ind($3, M_PREDEC); }
106 		| '-' '*' REGISTER	{ $$ = reg_ind($3, M_PREDEC); }
107 		| '*' REGISTER '(' expr ')'
108 					{ $$ = reg_index($2, $4); }
109 		;
110 
111 expr		: ID			{ $$ = id_expr($1); }
112 		| NUMBER		{ $$ = num_expr($1); }
113 		| '.'			{ $$ = here_expr(); }
114 		| '(' expr ')'		{ $$ = $2; }
115 		| '~' expr		{ $$ = bexpr('~', $2, NULL); }
116 		| '-' expr			%prec UMINUS
117 					{ $$ = bexpr(NEG, $2, NULL); }
118 		| expr '*' expr		{ $$ = bexpr('*', $1, $3); }
119 		| expr '/' expr		{ $$ = bexpr('/', $1, $3); }
120 		| expr '+' expr		{ $$ = bexpr('+', $1, $3); }
121 		| expr '-' expr		{ $$ = bexpr('-', $1, $3); }
122 		| expr '&' expr		{ $$ = bexpr('&', $1, $3); }
123 		| expr '|' expr		{ $$ = bexpr('|', $1, $3); }
124 		| expr '^' expr		{ $$ = bexpr('^', $1, $3); }
125 		| expr ':' expr		{ $$ = bexpr(':', $1, $3); }
126 		| expr LEFT_SHIFT expr	{ $$ = bexpr(LEFT_SHIFT, $1, $3); }
127 		| expr RIGHT_SHIFT expr	{ $$ = bexpr(RIGHT_SHIFT, $1, $3); }
128 		;
129 
130