Parenthesis And Operations Processing

From IT SPb Academy

Jump to: navigation, search

In MPS, you usually have a trouble with entering expressions with parentheses. A common editor for a parenthesized expression looks like ( %role% ), where %role% stands for editor of the expressions inside parentheses. Hence if you want to transform (2+3) into, for instance, ((2+3)*5), you usually should first cut (2+3) to the clipboard, then substitute multiplication expression to inside the parentheses and then paste clipboard contents as a first operand (and then write 5 as a second one). It's not very convenient.

Now you can write more convenient editors for parenthesized expressions. First, you create a usual familiar editor: something like ( %role% ). Then select the whole editor and set property "parseable" to true. Select each parenthesis meta cell and set cell's token kind to parenthesis token. Set parenthesis token to "left" for opening parenthesis and "right" for closing one.

After you've generated the editor, you'll be able to edit parenthesized expression more conveniently, almost like in a text editor.

For convenient editing of infix operations you should create an editor like %left% * %right% ("*" stands for operation symbol), set editor's "parseable" property to true and set token kind of meta cell with "*" to infix operation. Also set priority of your operation there.

Views