...

View Full Version : Expression Parsing



dasickis
05-10-2007, 07:55 AM
I was wondering how I should write this expression parsing function:
I'm trying to create a new operator (→) that outputs:

P Q P->Q
T T T
T F F
F T T
F F T
As you may have guessed the logic is (P==Q)||Q

Another operator I'm trying to create is (↔) that outputs


P Q P->Q
T T T
T F F
F T F
F F T
As you may have guessed the logic is (P==Q)||Q
The logic here is P==Q[/CODE]

Additionally, I need to parse logical quantifiers so that:

∃x becomes names.some(function(x){...})
∀x becomes names.every(function(x){...})

For example:



∃x Dodec(x) becomes names.some(function(x){return Dodec(x)})
∃x ∃y Smaller(x,y) becomes names.some(function(x){names.some(function(y){return Smaller(x,y)})})
∃x ∃y ∀z Between(x,y,z) becomes names.some(function(x){names.some(function(y)names.some(function(x){names.some(function(z){return Between(x,y,z)})})})


For a well formed logical statement, a person needs to properly parenthesize the statement.
Valid examples:
(Dodec(a)→Dodec(b))→Dodec(c)
∃x(Dodec(x) && ∃y Smaller(x,y))

Invalid Examples:
Dodec(a)→Dodec(b)→Dodec(c)
∃x Dodec(x) && ∃ySmaller(x,y) [Valid: ∃x Dodec(x) && ∃x∃ySmaller(x,y), the quantifier does not carry through]

For more information on logic:http://en.wikipedia.org/wiki/Predicate_logic

GJay
05-10-2007, 09:14 AM
this looks a lot like homework, if not what's the use-case?
Have you done anything so far?

dasickis
05-10-2007, 09:18 PM
I'm trying to port a software we had to use for Symbolic Logic to Javascript since I couldn't use it on Linux. Now the semester is over so I have more time to get involved. Yeah it is kinda for school, but now I'm just trying to learn Javascript and I think I'll turn this into Flash soon. Since using Flash will make a lot of the 3D stuff easier I could use SVG, but that's not supported as much as Flash.

The software I'm trying to port is: http://www-csli.stanford.edu/LPL/

I'll put up what I have so far here: http://dasickis.com/jstarski

dasickis
05-11-2007, 07:38 PM
Can someone help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum