Open benbrastmckie opened 4 days ago
I almost got pure_prefix
to work. It runs but has errors for complicated cases. I can't quite see what the issue is. If you have a chance to take a look I'd be curious to know if you can spot the error. Seems like it is very close.
Never mind I got it!
I made all of the syntax functions methods of the ModelSetup class. If it makes more sense, we could move some of these to a syntax module, though right now no module is imported by hidden_things.py
. I suspect elements are still missing from the syntax functions from before, in particular, I did not include the return [Const(token, AtomSort)]
though commented out where I think it should go.
I thought it might be helpful to open an issue for this. The aim is to refactor the prefix function so as not to depend on which operators the language includes, remaining agnostic about the semantics and even arity for those operators. Here is a sketch what I was thinking:
find_op_and_args(string, parens_number=0, triggered=False)
algorithm:triggered
andparens_number=0
, then returnleft_arg
parens_number =+ 1
find_op_and_args(string, parens_number, true)
left_arg
parens_number =- 1
find_op_and_args(string, parens_number, triggered)
left_arg
find_op_and_args(string, parens_number, triggered)
prefix
algorithm:infix_sentence
takes one of three forms:(left_arg \op right_arg)
in the case of a binary operator\op single_arg
in the case of a unary operator\op
in the case of a zero-place operatorleft_arg, op, right_arg = find_op_and_args(infix_sentence)
\
asleft_arg
op
right_arg
[op, prefix(left_arg), prefix(right_arg)]
There may well be ways to improve on this but thought this might help to provide a way in.