Changeset 220
- Timestamp:
- Nov 2, 2002, 11:43:08 PM (18 years ago)
- Location:
- to-imperative/branches/pragma/compiler
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/branches/pragma/compiler/rfp_asail.rf
r219 r220 4 4 5 5 $use Apply Box Class Convert StdIO Table; 6 $use "rfpc"; 6 7 $use "rfp_helper"; 7 8 8 // Constructs legal C++ name from e.Name and stores it in the &RFP-CPP-Names table 9 $box Func-Names; 10 $table Func-Table; 11 $box Var-Names; 12 $table Var-Table; 13 14 $func ASAIL-To-CPP e.body = e.cpp-code; 15 16 // Constructs legal C++ name from e.Name and stores it in the appropriate box 17 // and table 9 18 $func Name-To-CPP t.Name = e.legal-cpp-name; 10 19 … … 39 48 $func Op-Arg-To-CPP s.op = s.func-for-converting-args-to-cpp; 40 49 41 RFP-ASAIL-To-CPP e.asail, { 50 RFP-ASAIL-To-CPP e.asail = 51 <Store &Func-Names /*empty*/>, 52 <RFP-Clear-Table &Func-Table>, 53 <ASAIL-To-CPP e.asail>; 54 55 ASAIL-To-CPP e.asail, { 42 56 e.asail : t.item e.rest, t.item : { 43 57 (FUNC t.name (e.args) (e.ress) e.body) = 44 // { 45 // /* 46 // * Insert an empty line between functions. 47 // */ 48 // e.rest : v = (); 49 // /*empty*/; 50 // } :: e.space, 58 <Store &Var-Names /*empty*/>, 59 <RFP-Clear-Table &Var-Table>, 51 60 ('RF_FUNC (' <Name-To-CPP t.name> ', ' 52 61 '(' <Args-To-CPP ('RF_ARG ') Vars e.args> '), ' 53 62 '(' <Args-To-CPP ('RF_RES ') Vars e.ress> '))' 54 (< RFP-ASAIL-To-CPP e.body>)63 (<ASAIL-To-CPP e.body>) 55 64 'RF_END'); 56 65 (IF (e.cond) e.body) = 57 66 ('if (' <Cond-To-CPP e.cond> ')') 58 ('{' (< RFP-ASAIL-To-CPP e.body>) '}');67 ('{' (<ASAIL-To-CPP e.body>) '}'); 59 68 (FOR (e.label) (e.cond) (e.step) e.body) = 60 69 { … … 62 71 } :: e.label, 63 72 ('for ( ; ' <Cond-To-CPP e.cond> '; ' <Step-To-CPP e.step> ')') 64 ('{' (< RFP-ASAIL-To-CPP e.body>) e.label '}');73 ('{' (<ASAIL-To-CPP e.body>) e.label '}'); 65 74 (LABEL t.label e.body) = 66 ('{' (< RFP-ASAIL-To-CPP e.body>) '}')75 ('{' (<ASAIL-To-CPP e.body>) '}') 67 76 (LABEL <Name-To-CPP (LABEL t.label)> ': {}'); 68 77 (TRY e.body) = 69 ('try {' (< RFP-ASAIL-To-CPP e.body>) '}');78 ('try {' (<ASAIL-To-CPP e.body>) '}'); 70 79 (CATCH-ERROR e.body) = 71 ('with {' (< RFP-ASAIL-To-CPP e.body>) '}');80 ('with {' (<ASAIL-To-CPP e.body>) '}'); 72 81 RETURN = ('return true;'); 73 82 RETFAIL = ('retfail;'); … … 111 120 '(' <Args-To-CPP () Exprs e.exprs> '), (' <Args-To-CPP () Vars e.ress> '));'); 112 121 } :: e.cpp-item, 113 e.cpp-item < RFP-ASAIL-To-CPP e.rest>;122 e.cpp-item <ASAIL-To-CPP e.rest>; 114 123 /*empty*/; 115 124 }; … … 144 153 t.item : { 145 154 s.ObjectSymbol = <Symbol-To-CPP s.ObjectSymbol>; 146 (PAREN e.expr) = '(' <Expr-Ref-To-CPP 0 e.expr> ')()';155 (PAREN e.expr) = <Expr-Ref-To-CPP 0 e.expr> ' ()'; 147 156 (EXPR e.expr) = 148 157 'Expr (' <Chars-To-CPP e.expr> ')'; … … 177 186 }; 178 187 (LENGTH e.expr) = 179 '(int) (' <Expr-Ref-To-CPP 0 e.expr> ').get_len ()';188 '(int) ' <Expr-Ref-To-CPP 0 e.expr> '.get_len ()'; 180 189 (MAX e.args) = 181 190 'max (' <Args-To-CPP () Ints e.args> ')'; … … 204 213 '(' <Args-To-CPP () Vars e.ress> '))'; 205 214 (SYMBOL? e.expr (e.pos)) = 206 '(' <Expr-Ref-To-CPP 0 e.expr> ').symbol_at (' <Expr-Int-To-CPP e.pos> ')';215 <Expr-Ref-To-CPP 0 e.expr> '.symbol_at (' <Expr-Int-To-CPP e.pos> ')'; 207 216 (FLAT-SUBEXPR? e.expr (e.pos) (e.len)) = 208 '(' <Expr-Ref-To-CPP 0 e.expr> ').flat_at ('217 <Expr-Ref-To-CPP 0 e.expr> '.flat_at (' 209 218 <Expr-Int-To-CPP e.pos> ', ' <Expr-Int-To-CPP e.len> ')'; 210 219 /* … … 224 233 <Expr-Int-To-CPP e.len> ')'; 225 234 (NOT e.cond) = 226 '! (' <Cond-To-CPP e.cond> ')';235 '!' <Cond-To-CPP e.cond>; 227 236 (INFIX s.op e.args) = 228 237 '(' <Infix-To-CPP <Op-Arg-To-CPP s.op> s.op e.args> ')'; … … 237 246 /*empty*/; 238 247 } :: e.cpp-op, 239 '(' <Apply s.arg2cpp e.arg> ')'e.cpp-op <Infix-To-CPP s.arg2cpp s.op e.rest>;;248 <Apply s.arg2cpp e.arg> e.cpp-op <Infix-To-CPP s.arg2cpp s.op e.rest>;; 240 249 }; 241 250 … … 278 287 }; 279 288 280 $box Used-Names;281 282 289 /* 283 290 * Gets function name or variable and returns legal C++ name corresponding to 284 291 * it. If is called with such parameter at the first time then stores C++ name 285 * in the &RFP-CPP-Names table for further using. 292 * in the appropriate table for further using. Also put new name in the 293 * appropriate box. Box and table for variables is updated for each new 294 * function and box and table for functions is updated for each new module. 286 295 */ 287 296 Name-To-CPP term = 288 297 term : { 289 (VAR (e.QualifiedName)) = e.QualifiedName ;290 (LABEL (e.QualifiedName)) = e.QualifiedName ;291 (e.QualifiedName) = e.QualifiedName ; // function name292 } :: e.QualifiedName ,298 (VAR (e.QualifiedName)) = e.QualifiedName &Var-Names &Var-Table; 299 (LABEL (e.QualifiedName)) = e.QualifiedName &Var-Names &Var-Table; 300 (e.QualifiedName) = e.QualifiedName &Func-Names &Func-Table; // function name 301 } :: e.QualifiedName s.used-names s.table, 293 302 { 294 <Lookup &RFP-CPP-Namese.QualifiedName>;303 <Lookup s.table e.QualifiedName>; 295 304 e.QualifiedName : s.first e.last, 296 305 <Word-To-CPP-Chars s.first> :: e.first, … … 302 311 } :: (e.first) e.last, 303 312 e.first <Build-CPP-Name e.last> :: e.name, 304 <Find-Unused-Name (<? &Used-Names>) e.name> :: e.name,305 <Put &Used-Names (e.name)>,306 <Bind &RFP-CPP-Names(e.QualifiedName) (e.name)>,313 <Find-Unused-Name (<? s.used-names>) e.name> :: e.name, 314 <Put s.used-names (e.name)>, 315 <Bind s.table (e.QualifiedName) (e.name)>, 307 316 e.name; 308 317 }; -
to-imperative/branches/pragma/compiler/rfp_asail.rfi
r219 r220 3 3 // $Date$ 4 4 5 /*6 * Table for storing legal C++ names of functions and variables. Only functions7 * names will appear in result program as are. For variables they are obtained8 * from indexes and to be preceded by some prefix. For e.Key e.QualifiedName is9 * used.10 */11 $table RFP-CPP-Names;12 13 5 $func RFP-ASAIL-To-CPP e.asail = e.cpp; 14 6 -
to-imperative/branches/pragma/compiler/rfpc.rf
r219 r220 132 132 <Channel> :: s.channel, 133 133 <Open-File s.channel e.file R>, 134 AS-AIL <Read! s.channel>;134 AS-AIL (AS-AIL AS-AIL <Read! s.channel> <Read! s.channel>); 135 135 <PrintLN! &StdErr "Error: unknown extension" e.ext " in " e.file> = $fail; 136 136 } : s.type (s.tag t.ModuleName e.Items),
Note: See TracChangeset
for help on using the changeset viewer.