Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To put it briefly, a program matches /rule*input/
- A rule is composed of regexp, -> sign and something I call a segexp (just because S goes after R)
- A regexp is a string enclosed in double quotes. *, + (instead of |) and parentheses work as you'd expect them. There is an additional element - a name prefix. This is a string enclosed in [] followed by a regexp. This name is going to be used by segexp. Name prefix has precedence between * and +. To use symbols ", *, +, (, ), [, ], \ in a regexp as normal characters, prefix them with a \.
- Example: "[x](0+1)*1"
- This matches all binary strings that end with 1. All characters but the last one are given a name [x].
- A segexp is a string enclosed in double quotes. It is composed of symbols and names. A name is the same as in regexp. Whatever was assigned to it will be inserted here. If that name was not used, nothing is inserted (no error either). Symbols ", [, ], \ may need a \ prefix.
- Example: "[x]0[x][y]"
- If used with the regexp of last example and a string 101, it will produce a string 10010
- An input is again a string in ". It only has characters. only " and \ need a \.
- The input is matched to each rule in the order they are written in the file. If a match occurs, input is replaced with whatever segexp built and matching starts from the top of the list again.
- When no rule matches, the current string is printed.
Advertisement
Add Comment
Please, Sign In to add comment