ForthHub / fep-recognizer

Proposal: Recognizer — development and evolving
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

naming: methods to recognize various lexemes #17

Open ruv opened 4 years ago

ruv commented 4 years ago

Recognizer v4 API suggests to use the prefix rec- for names of recognizers. E.g. rec-num or rec-nt.

A disadvantage is that it's a truncated English word, and it appears as a noun at the first glance — due to association to "record" or "recognizer". And also due to "rectype" term that is noun. But by convention, it should be a verb for such a Forth word (or an abbreviation to a verb at least).

I would suggest to use the complete English word and the prefix recognize- for such words. E.g. recognize-nt.

Concerning the second part, it's better if it is either a complete English noun, or an appropriate data type symbol from the standard types.

E.g. recognize-number, recognize-double, recognize-float, recognize-xt, recognize-word.

If we need to recognize the different lexeme formats for the same token, we can use the third part. E.g. recognize-float-e to recognize a float from a literal representation (lexeme) contains e symbol only, recognize-double-dot to recognize double-cell number from a literal that has a trailing dot only, etc.


recognize-word can be a compound recognizer that can return ( xt td-xt ), or ( xt td-xt-imm ), or ( xt1 xt2 td-xt-dual ) or ( nt td-nt ).

ruv commented 4 years ago

If a recognizer is just a kind of transformation for the perceptor, a better name is perceive-{something}. E.g.

: perceive-xt ( c-addr u -- xt td-xt | 0 )
  'perceive execute-balance2 2>r token>xt? 2r>
  2 pick if 2drop exit then nfdrop 3 + ndrop 0
;

This recognizer recognizes the only lexemes which are recognized by the perceptor as ordinary words.

Such recognizer cannot be included into the perceptor directly (due to unlimited recursion). It can be only used in another recognizers to be applied to the different lexeme. And the different name pattern also indicates this different semantics.