Recognizers Why and How M. Anton Ertl TU Wien How to deal with - - PowerPoint PPT Presentation

recognizers why and how
SMART_READER_LITE
LIVE PREVIEW

Recognizers Why and How M. Anton Ertl TU Wien How to deal with - - PowerPoint PPT Presentation

Recognizers Why and How M. Anton Ertl TU Wien How to deal with literals Recognizers Parsing Words 123 s" abc" $ff H# ff a [char] a 1.2e3 No way to define new recognizers No good way to define parsing words


slide-1
SLIDE 1

Recognizers Why and How

  • M. Anton Ertl

TU Wien

slide-2
SLIDE 2

How to deal with literals

Recognizers 123 $ff ’a’ 1.2e3 Parsing Words s" abc" H# ff [char] a

  • No way to define new recognizers
  • No good way to define parsing words

non-default non-immediate compilation semantics State-smartness and the like Not just an implementation problem

  • ⇒ user-defined recognizers
slide-3
SLIDE 3

Ideal

  • Recognized literal acts like a normal word
  • : 123 123 ;
  • Interpret

Compile Postpone? ]] a 123 b [[ vs. ]] a [[ 123 ]] literal b [[ ’? find find-name name>string ?

slide-4
SLIDE 4

How to specify and implement recognizers

  • Specify interpret, compile, and postpone actions

Advantage: Optimization possible Disadvantage: Bugs can hide, especially for postpone

  • Specify parse-time, run-time, and data-shifting actions

interpret: parse-time run-time compile: parse-time shift ]] run-time [[ postpone: parse-time shift ]] shift ]] run-time [[ [[

  • Define a temporary word

Advantages: Allows ticking etc. Conceptual simplicity Disadvantage: Optimization?

slide-5
SLIDE 5

Temporary words

  • Separate dictionary pointer (like ELF section)
  • Should be inlined if compiled. But how?
  • Becomes permanent if postponed or ticked
  • Other permanent uses need explicit permanence
  • Recognized string as name?

Decompiler name>string

slide-6
SLIDE 6

Coding example

: usingle ( c-addr u -- f )

  • 0. 2over >number 0= if

drop 2drop 2drop false exit then drop drop rot rot [’] constant execute-parsing true ;

slide-7
SLIDE 7

Inline when compiled

  • Require using an intelligent compile,

Quite elegant But set-opt is unlikely to be standardized

  • Or specify parse-time and compile-time action

For compilation, perform these actions In other cases, build the word

slide-8
SLIDE 8

Performance with many recognizers

  • Linear search through recognizer stack?
  • Or fast pre-selection
  • Pre-selection may accept invalid strings

but must not reject valid strings

  • prefix pre-selectors ⇒ trie
  • regexp pre-selectors ⇒ NFA/DFA
slide-9
SLIDE 9

Conclusion

  • User-defined words are great!

Let´s also allow user-defined recognizers

  • New implementation approach:

Define temporary words How to inline?

  • Pre-Selectors for performance