| |
| /pliant/language/compiler/expression/expression3.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
scope "/pliant/language/" "/pliant/install/" | |
| 17 |
module "/pliant/install/ring3.pli" | |
| 18 |
| |
| 19 |
| |
| 20 |
function complex_ident string -> cplx | |
| 21 |
arg Str string ; arg CBool cplx | |
| 22 |
for (var Int i) 0 string:len-1 | |
| 23 |
var Char c := string i | |
| 24 |
if not ( c>="a" and c<="z" or c>="A" and c<="Z" or c>="0" and c<="9" and i>0 or c="_") | |
| 25 |
return true | |
| 26 |
return false | |
| 27 |
| |
| 28 |
constant to_index (the_function '. to string' Universal Str -> Str):generic_index | |
| 29 |
| |
| 30 |
function to_string data options function -> string | |
| 31 |
arg Universal data ; arg Str options ; arg Function function ; arg Str string | |
| 32 |
indirect | |
| 33 |
| |
| 34 |
function to_string expr -> string | |
| 35 |
arg Expression expr ; arg Str string | |
| 36 |
var Pointer:Type type :> entry_type expr:value | |
| 37 |
var Pointer:Function function :> type get_generic_method to_index | |
| 38 |
if type=Ident | |
| 39 |
string := cast (expr:value map Ident) Str | |
| 40 |
if complex_ident:string | |
| 41 |
string := "'"+string+"'" | |
| 42 |
eif addressof:function<>null and addressof:function<>addressof:(the_function '. to string' Universal Str -> Str) | |
| 43 |
string := to_string (expr:value map Universal) "" function | |
| 44 |
else | |
| 45 |
return "!!!"+(entry_type expr:value):name+"!!!" | |
| 46 |
if expr:size=0 | |
| 47 |
return | |
| 48 |
string := "("+string | |
| 49 |
for (var Int i) 0 expr:size-1 | |
| 50 |
string += " "+(to_string expr:i) | |
| 51 |
string += ")" | |
| 52 |
| |
| 53 |
method data 'to string' options -> string | |
| 54 |
arg Expression data ; arg Str options string | |
| 55 |
string := to_string data | |
| 56 |
| |
| 57 |
| |
| 58 |
function parse string -> expr | |
| 59 |
arg Str string ; arg Link:Expression expr | |
| 60 |
var Arrow a | |
| 61 |
var Link:List program :> new List | |
| 62 |
program append addressof:(new Str "return_expressions ("+string:(cast addressof:a Int)+")") | |
| 63 |
program append addressof:(new Str " [0]left_zero_is_at [dq]"+"[dq] 0 1[0]") | |
| 64 |
program append addressof:(new Str " "+string) | |
| 65 |
var Link:Module module :> new Module | |
| 66 |
module name := string | |
| 67 |
module include the_module:"/pliant/language/basic/safe.pli" | |
| 68 |
module include the_module:"/pliant/language/parser/code_generator.pli" | |
| 69 |
module include the_module:"/pliant/language/compiler/expression3bis.pli" | |
| 70 |
compile_text program module | |
| 71 |
expr :> a map Expression | |
| 72 |
| |
| 73 |
| |
| 74 |
export parse | |
| |