Very simple functional parser
I made a super simple functional parser in Python. It can parse strings like this foo(x,blah(y,z)) and turn it to ["foo","x",["blah","y","z"]]. I named it simple-fol-parser because It’ll be used to parse FOL terms. The grammar will be context-free and very simlar to TPTP style.
Here’s few pieces of info about the parser.
It’s not new, nothing new at all My goal is trying to create a simple-enough parser for my own. And the only goal is to parse strings I need, in functional form. In the future, I might add few rules for quantifier, connectives, equality and few common binary operators. But they’re not mandatory.
The parser is not new, not optimized (of course while it’s using Lark and written in Python, not C) and not production-ready. I’ll keep a simple test directory for pytest while developing it, however It’s far from production-ready. Also, It won’t be developed for production ready while I believe nltk has similar one and any for anyone who needs a parser can use Lark instead. The whole point of this parser is, It’s a quick working parser that allows you to use immediately to write and test FOL-style terms.
What it can and can’t do?
Here’s how we represent a formula x + 1 = 2 in code: eq(add(x,1),2). Here’s the python code:
s = "eq(add(x,1),2)"
x = parser( s )
print( x ) # [ "eq", [ "add", "x", "1" ], "2" ]
For complicated formulas like , here’s the string:
all(
implies(
in( z, COMPLX ),
eq(
mul(
z,
conjugate(z)
),
pow(
abs( z ),
2
)
)
)
)