Is DYNAMIC unification possible

Discussions related to Visual Prolog
kingchris
Active Member
Posts: 47
Joined: 26 Sep 2005 9:35

Is DYNAMIC unification possible

Unread post by kingchris » 15 Mar 2010 4:24

With VP 7.x you can now embed the return value of a function into a predicate call or another function call.

Code: Select all

%Previous   Distance  = calculateDistance([34.045,45.453],[89.34,23.56]). RootValue = squareroot_calcualtion(-2). power     = powerFunction(Distance,RootValue).   %Now   power     = powerFunction(calculateDistance([34.045,45.453],[89.34,23.56]),squareroot_calcualtion(-2)).
I am writing a 'Stateful' parser that shells out to Lex some source code into a token stream which is then read as a facts database into memory.
Can unification be DYNAMIC rather than matching constants.

Code: Select all

%normally   constants   pFUNCTION   = 100.   pPROCEDURE  = 200.   pRPAREN     = 300.   pLPAREN     = 400.   pCOMMA      = 500.   pDIGITS     = 600.   pIDENTIFIER = 700.   pMINUS      = 800.   pPLUS       = 900. ...   predicates   parse:(integer,integer,integer,integer,....) multi (i,i,i,i,...).   clauses     parse(pFUNCTION,pLPAREN,pDIGITS,pRPAREN):-     stdio:write("You have found a FUNCTION\n").       parse(pPROCEDURE,pLPAREN,pDIGITS,pRPAREN):-     stdio:write("You have found a PROCEDURE\n").     % Is this possible   constants   pFUNCTION   = 100.   pPROCEDURE  = 200.   pRPAREN     = 300.   pLPAREN     = 400.   pCOMMA      = 500.   pDIGITS     = 600.   pIDENTIFIER = 700.   pMINUS      = 800.   pPLUS       = 900. ...   class facts dynfact01:(integer) single. dynfact02:(integer) single. dynfact03:(integer) single. dynfact04:(integer) single. dynfact05:(integer) single. ....   clauses dynfact01(pFUNCTION). dynfact02(pLPAREN). dynfact03(pDIGITS). dynfact04(pRPAREN). ....     predicates   parse:(integer,integer,integer,integer,....) multi (i,i,i,i,...).     return_token1: () -> integer procedure.   return_token2: () -> integer procedure.   return_token3: () -> integer procedure.   return_token4: () -> integer procedure.   return_token5: () -> integer procedure. ... clauses   return_token1() = pPROCEDURE.   return_token2() = pLPAREN.   return_token3() = pDIGITS.   return_token4() = pRPAREN.     clauses     % using facts that can be changed   parse(dynfact01(T1),dynfact01(T2),dynfact01(T3),dynfact01(T4)):-     stdio:write("You have found a FUNCTION\n").     % using functions that their return value could change   parse(return_token1(),return_token2(),return_token3(),return_token4()):-     stdio:write("You have found a PROCEDURE\n").
The 'example' code is not perfect but should give you an idea of what I trying to do.

Thanks.

User avatar
Thomas Linder Puls
VIP Member
Posts: 2407
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 15 Mar 2010 8:42

I am not completely sure I get the correct idea of what you are trying to do.

Anyway, you must do like this instead:

Code: Select all

clauses     parse(T1, T2, T3, T4) :-         dynfact01(T1),         dynfact01(T2),         dynfact01(T3),         dynfact01(T4)),         !, % necessary because there are more clauses         stdio:write("You have found a FUNCTION\n").     % using functions that their return value could change     parse(T1, T2, T3, T4) :-         T1 =return_token1(),         T2 = return_token2(),         T3 = return_token3(),         T4 = return_token4()),         !, %only necessary if there are more clauses         stdio:write("You have found a PROCEDURE\n").
Another thing, [code] and [/code] is "BBCode" so it has no effect if you choose "Disable BBCode in this post".
Regards Thomas Linder Puls
PDC

kingchris
Active Member
Posts: 47
Joined: 26 Sep 2005 9:35

Unread post by kingchris » 15 Mar 2010 17:02

Thanks for the reply. VP does not do what I would like it to. So I will have to program it like I thought, as you have suggested.


What I am doing is writing a DYNAMIC stateful parser. Instead of hand coding reams and reams of UNIFICATION code like a YACC file for all possible language contructs. I want to minimise my search state by unifying with the first token. This unification then narrows down the DYNAMIC list of possible tokens than can be unified with the next token as most computer languages have a defined syntax. Until we reach Newline or end of token sequence. Then reset the token space and process next token until end of file.

Easy peasy

Thanks

Paul Cerkez
VIP Member
Posts: 384
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 16 Mar 2010 0:20

you may want to look at the older PDC Prolog example program that creates and or parses text.

not sure if it is totally applicable but it might help. It alolwed you to define a "simple" syntax and vocabulary and then parse inputs based on it.

I'm traveling right now and don't have access to my older files and don't remember the name of the tool. I'm sure Thomas might be able to answer up. ;-)
AI Rules!
P.

kingchris
Active Member
Posts: 47
Joined: 26 Sep 2005 9:35

Unread post by kingchris » 16 Mar 2010 4:39

Will do. Have 5.2 somewhere.

User avatar
Thomas Linder Puls
VIP Member
Posts: 2407
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 16 Mar 2010 9:39

The parser generator is a demo example in Vip 7.x as well.
Regards Thomas Linder Puls
PDC

Paul Cerkez
VIP Member
Posts: 384
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 16 Mar 2010 12:55

thanks Thomas, I thought you had updated it but wasn't sure.
AI Rules!
P.

Post Reply