print and get procedures

new topic     » topic index » view thread      » older message » newer message

The idea is to do print() as dump of a sequence and with get() do a readback of that sequence .
Oke that works as long as it is only one sequence .
But this :
print(fileout,seq1)
print(fileout,seq2)
print(fileout,seq3)
Save this three sequence's to fileout .
But how to get thim back ?
seq1=get(filein) - works
seq2=get(filein) - doesn't work
seq3=get(filein) - doesn't work

Why , because the GET() routine within get.e does a recursion which ends on a wrong character .

I changed it in this way :

function Get(integer l) --l is level counter 
-- read a Euphoria data object as a string of characters 
-- and return {error_flag, value} 
-- Note: ch is "live" at entry and exit of this routine 
    sequence s, e 
    skip_blanks() 
    if find(ch, START_NUMERIC) then 
        return get_number() 
    elsif ch = '{' then 
        -- process a sequence 
        s = {} 
        get_ch() 
        skip_blanks() 
        if ch = '}' then 
            if l then get_ch() end if  -- change into if statement 
            return {GET_SUCCESS, s} -- empty sequence 
        end if     
        while TRUE do 
            e = Get(l+1) -- read next element  add level 
            if e[1] != GET_SUCCESS then 
                return e 
            end if 
            s = append(s, e[2]) 
            skip_blanks() 
            if ch = '}' then 
                if(l) then get_ch() end if  -- change into if statement 
                return {GET_SUCCESS, s} 
            elsif ch != ',' then 
                return {GET_FAIL, 0} 
            end if 
            get_ch() -- skip comma 
        end while 
    elsif ch = '\"' then 
        return get_string() 
    elsif ch = '\'' then 
        return get_qchar() 
    elsif ch = -1 then 
        return {GET_EOF, 0} 
    else 
        return {GET_FAIL, 0} 
    end if 
end function 

change the call to GET() into GET(0)

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu