--- gforth/kernel/recognizer.fs 2011/12/28 13:39:49 1.15 +++ gforth/kernel/recognizer.fs 2012/06/23 23:20:23 1.20 @@ -1,5 +1,22 @@ \ recognizer-based interpreter 05oct2011py +\ Copyright (C) 2012 Free Software Foundation, Inc. + +\ This file is part of Gforth. + +\ Gforth is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation, either version 3 +\ of the License, or (at your option) any later version. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\ GNU General Public License for more details. + +\ You should have received a copy of the GNU General Public License +\ along with this program. If not, see http://www.gnu.org/licenses/. + \ Recognizer are words that take a string and try to figure out \ what to do with it. I want to separate the parse action from \ the interpret/compile/postpone action, so that recognizers @@ -24,25 +41,27 @@ ' no.extensions dup dup Create r:fail A, A, A, : lit, ( n -- ) postpone Literal ; -: 2lit, ( n -- ) postpone 2Literal ; : nt, ( nt -- ) name>comp execute ; - -' name>int -:noname ( ... nt -- ... xt ) ['] nt, ; -:noname ( ... nt -- xt ) ['] lit, ; +: nt-ex ( nt -- ) + [ cell 1 floats - dup [IF] ] lp+!# [ dup , [THEN] drop ] + r> >l name>int execute @local0 >r lp+ ; + +' nt-ex +' nt, +' lit, Create r:word rot A, swap A, A, : word-recognizer ( addr u -- nt r:word | addr u r:fail ) 2dup find-name [ [IFDEF] prelude-mask ] run-prelude [ [THEN] ] dup IF nip nip r:word ELSE drop r:fail THEN ; -:noname ['] noop ; -:noname ['] lit, ; +' noop +' lit, dup Create r:num rot A, swap A, A, -:noname ['] noop ; -:noname ['] 2lit, ; +' noop +:noname ( n -- ) postpone 2Literal ; dup Create r:2num rot A, swap A, A, @@ -90,12 +109,12 @@ Variable forth-recognizer \ xxx-recognizer do-recognizer ; : interpreter-r ( addr u -- ... xt ) - forth-recognizer do-recognizer r>int perform ; + forth-recognizer do-recognizer r>int @ ; ' interpreter-r IS parser1 : compiler-r ( addr u -- ... xt ) - forth-recognizer do-recognizer r>comp perform ; + forth-recognizer do-recognizer r>comp @ ; : [ ( -- ) \ core left-bracket \G Enter interpretation state. Immediate word. @@ -105,12 +124,13 @@ Variable forth-recognizer \G Enter compilation state. ['] compiler-r IS parser1 state on ; -: >int ( token table -- ) r>int perform execute ; -: >comp ( token table -- ) r>comp perform execute ; +: >int ( token table -- ) r>int perform ; +: >comp ( token table -- ) r>comp perform ; : >postpone ( token table -- ) - >r r@ r>lit perform execute r> r>comp perform compile, ; + >r r@ r>lit perform r> r>comp @ compile, ; : postpone ( "name" -- ) \ core \g Compiles the compilation semantics of @i{name}. - parse-name forth-recognizer do-recognizer >postpone ; immediate + parse-name forth-recognizer do-recognizer >postpone +; immediate restrict