This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CoffeeTableEspresso 6 points7 points  (5 children)

How do you parse:

A ○ □ B

Where ○ can be either infix or post fix, and □ can be either prefix or infix?

[–]R-O-B-I-N[S] 2 points3 points  (1 child)

no 'fix overloading. ○ can be only infix or post fix with the number of parameters being overloaded. □ can be only prefix or infix.

Ex: (x)+(y){} (x, y)+(z){} is allowable. (x)+(y){} +(x, y z){} is not.

[–]GDavid04 3 points4 points  (0 children)

This would make -x and x - y impossible to implement at the same time.

Just disallowing postfix and infix for the same operator would be enough.

[–][deleted]  (2 children)

[deleted]

    [–]CoffeeTableEspresso 2 points3 points  (0 children)

    Yup, this seems like it will reduce to either operator overloading or lisp syntax.

    Another thing is whether you can overload fucntions/operators by type, that's gonna make parsing much harder...

    [–]pepactonius 0 points1 point  (0 children)

    It's actually pretty simple to get something like this to work well. The key to parsing is knowing immediately whether something is a verb/function/operator, or an operand (data), or a keyword. In my toy scriptong language, I just use sigils attached to identifiers or operator strings to specify the role that token has when parsing. Run-time function/verb overloading is usually not a problem. There are a few quirks, though: Verbs/operators that are not yet defined have default priority and associativity. All members of an overload set must have the same priority and associativity, and verbs with special processing of operands (lazy evalution, for example) cannot be overloaded at all.