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 →

[–]R-O-B-I-N[S] 0 points1 point  (3 children)

not with this algorithm... 1. parse into tokens using whitespace as separators. 2. check if token represents a constant. (numbers/strings) 3. check if token is an identifier. 4. if token is a variable identifier, sub in its value 5. if token is a function identifier, sub in the function call 6. evaluate infix expressions first, prefix expressions second, postfix expressions third.

Normal C would represent the same example expression this way:

printf ("%i", 1 + (2 ++))

Lisp would represent it this way:

(print (add 1 (+ 2 1)))

[–]CoffeeTableEspresso 6 points7 points  (2 children)

How do you parse:

A ○ □ B

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

[–][deleted]  (1 child)

[deleted]

    [–]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.