Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / f2c / gram.exp
1 funarglist:
2                 { $$ = 0; }
3         | funargs
4         ;
5
6 funargs:  expr
7                 { $$ = mkchain((char *)$1, CHNULL); }
8         | funargs SCOMMA expr
9                 { $$ = hookup($1, mkchain((char *)$3,CHNULL) ); }
10         ;
11
12
13 expr:     uexpr
14         | SLPAR expr SRPAR      { $$ = $2; }
15         | complex_const
16         ;
17
18 uexpr:    lhs
19         | simple_const
20         | expr addop expr   %prec SPLUS
21                 { $$ = mkexpr($2, $1, $3); }
22         | expr SSTAR expr
23                 { $$ = mkexpr(OPSTAR, $1, $3); }
24         | expr SSLASH expr
25                 { $$ = mkexpr(OPSLASH, $1, $3); }
26         | expr SPOWER expr
27                 { $$ = mkexpr(OPPOWER, $1, $3); }
28         | addop expr  %prec SSTAR
29                 { if($1 == OPMINUS)
30                         $$ = mkexpr(OPNEG, $2, ENULL);
31                   else  $$ = $2;
32                 }
33         | expr relop expr  %prec SEQ
34                 { $$ = mkexpr($2, $1, $3); }
35         | expr SEQV expr
36                 { NO66(".EQV. operator");
37                   $$ = mkexpr(OPEQV, $1,$3); }
38         | expr SNEQV expr
39                 { NO66(".NEQV. operator");
40                   $$ = mkexpr(OPNEQV, $1, $3); }
41         | expr SOR expr
42                 { $$ = mkexpr(OPOR, $1, $3); }
43         | expr SAND expr
44                 { $$ = mkexpr(OPAND, $1, $3); }
45         | SNOT expr
46                 { $$ = mkexpr(OPNOT, $2, ENULL); }
47         | expr SCONCAT expr
48                 { NO66("concatenation operator //");
49                   $$ = mkexpr(OPCONCAT, $1, $3); }
50         ;
51
52 addop:    SPLUS         { $$ = OPPLUS; }
53         | SMINUS        { $$ = OPMINUS; }
54         ;
55
56 relop:    SEQ   { $$ = OPEQ; }
57         | SGT   { $$ = OPGT; }
58         | SLT   { $$ = OPLT; }
59         | SGE   { $$ = OPGE; }
60         | SLE   { $$ = OPLE; }
61         | SNE   { $$ = OPNE; }
62         ;
63
64 lhs:     name
65                 { $$ = mkprim($1, LBNULL, CHNULL); }
66         | name substring
67                 { NO66("substring operator :");
68                   $$ = mkprim($1, LBNULL, $2); }
69         | name SLPAR funarglist SRPAR
70                 { $$ = mkprim($1, mklist($3), CHNULL); }
71         | name SLPAR funarglist SRPAR substring
72                 { NO66("substring operator :");
73                   $$ = mkprim($1, mklist($3), $5); }
74         ;
75
76 substring:  SLPAR opt_expr SCOLON opt_expr SRPAR
77                 { $$ = mkchain((char *)$2, mkchain((char *)$4,CHNULL)); }
78         ;
79
80 opt_expr:
81                 { $$ = 0; }
82         | expr
83         ;
84
85 simple:   name
86                 { if($1->vclass == CLPARAM)
87                         $$ = (expptr) cpexpr(
88                                 ( (struct Paramblock *) ($1) ) -> paramval);
89                 }
90         | simple_const
91         ;
92
93 simple_const:   STRUE   { $$ = mklogcon(1); }
94         | SFALSE        { $$ = mklogcon(0); }
95         | SHOLLERITH  { $$ = mkstrcon(toklen, token); }
96         | SICON = { $$ = mkintcon( convci(toklen, token) ); }
97         | SRCON = { $$ = mkrealcon(tyreal, token); }
98         | SDCON = { $$ = mkrealcon(TYDREAL, token); }
99         | bit_const
100         ;
101
102 complex_const:  SLPAR uexpr SCOMMA uexpr SRPAR
103                 { $$ = mkcxcon($2,$4); }
104         ;
105
106 bit_const:  SHEXCON
107                 { NOEXT("hex constant");
108                   $$ = mkbitcon(4, toklen, token); }
109         | SOCTCON
110                 { NOEXT("octal constant");
111                   $$ = mkbitcon(3, toklen, token); }
112         | SBITCON
113                 { NOEXT("binary constant");
114                   $$ = mkbitcon(1, toklen, token); }
115         ;
116
117 fexpr:    unpar_fexpr
118         | SLPAR fexpr SRPAR
119                 { $$ = $2; }
120         ;
121
122 unpar_fexpr:      lhs
123         | simple_const
124         | fexpr addop fexpr   %prec SPLUS
125                 { $$ = mkexpr($2, $1, $3); }
126         | fexpr SSTAR fexpr
127                 { $$ = mkexpr(OPSTAR, $1, $3); }
128         | fexpr SSLASH fexpr
129                 { $$ = mkexpr(OPSLASH, $1, $3); }
130         | fexpr SPOWER fexpr
131                 { $$ = mkexpr(OPPOWER, $1, $3); }
132         | addop fexpr  %prec SSTAR
133                 { if($1 == OPMINUS)
134                         $$ = mkexpr(OPNEG, $2, ENULL);
135                   else  $$ = $2;
136                 }
137         | fexpr SCONCAT fexpr
138                 { NO66("concatenation operator //");
139                   $$ = mkexpr(OPCONCAT, $1, $3); }
140         ;