Files
harbour-core/harbour/samples/cccppc/prtreepr.prg
1999-11-09 01:37:27 +00:00

102 lines
2.6 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* $Id$
*/
//*******************************************************************
// prtreepr.prg: A PRTREEPR oszt ly implement ci¢ja.
// 1999, Csisz r Levente
//*******************************************************************
#include "objgen.ch"
#include "prtree.och"
//*******************************************************************
#define _PRTREEPR_PRG_
#define _IMPLEMENT_ONEW_
#include "prtreepr.och"
//*******************************************************************
implement oinit(eprtree)
super:oinit()
this:eprtree:=eprtree
this:start()
return this
//*******************************************************************
implement start()
if (this:eprtree!=nil)
this:subtree :=PRTREE.(this:eprtree):tree
else
this:subtree :={}
endif
this:result :=nil
this:itemArray :={}
this:wordLen :=0
this:lastStopWordLen :=0
// this:lastStopResult :=nil // Ez igaz b¢l nem kell, elg a result is.
return nil
//*******************************************************************
implement put(item)
/*
Egy item-el tov bb megy az elemz“ f ban.
Az itemeket gyjti az itemArray-ban.
Ret: nil, ha nincs vge.
.t., ha vge van s elfogadta,
.f., ha vge van s nem fogadta el.
*/
local tptree,nRds
local str,lastStop,i
aadd(this:itemArray,item)
if (0==(i:=ascan(this:subtree,{|x| x[1]==item})))
// Nincs tov bb, viszont a lastStop-ban van olyan token,
// ami illeszkedik ennek az elejhez.
this:wordLen:=this:lastStopWordLen
// this:result:=this:lastStopResult
return this:wordLen!=0
endif
// Van ilyen item, megy<67>nk lejjebb a f ban
this:wordLen++
this:subtree:=this:subtree[i][2]
// El“sz”r megnzz<7A>k, hogy a vgre rt<72>nk-e.
if (len(this:subtree)==0)
// Hiba, vagy <20>res a fa, vissza a lastStop-hoz.
this:wordLen:=this:lastStopWordLen
// this:result:=this:lastStopResult
return this:wordLen!=0
endif
if (this:subtree[1][1]==nil)
// Itt meg lehet  llni, pl. ha a k”vetkez“ keress nem hoz
// eredmnyt.
if (len(this:subtree)==1)
// Nem lehet tov bb menni, de visszalpni sem kell.
// id:=this:subtree[1][2]
this:result:=this:subtree[1][2]
return this:wordLen!=0
endif
// Lehet mg tov bb, de ha elakad, akkor ez j¢!
this:lastStopWordLen:=this:wordLen
// this:lastStopResult:=this:subtree[1][2]
this:result:=this:subtree[1][2]
endif
// Mg nincs eredmny, megy<67>nk tov bb.
return nil
//*******************************************************************