Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/ml-yacc/src/yacc.lex.sml
ViewVC logotype

Diff of /sml/trunk/src/ml-yacc/src/yacc.lex.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 514, Thu Dec 16 08:32:57 1999 UTC revision 515, Sun Jan 9 09:59:14 2000 UTC
# Line 45  Line 45 
45                 ("%verbose",VERBOSE), ("%nodefault",NODEFAULT),                 ("%verbose",VERBOSE), ("%nodefault",NODEFAULT),
46                 ("%value",VALUE), ("%noshift",NOSHIFT),                 ("%value",VALUE), ("%noshift",NOSHIFT),
47                 ("%header",PERCENT_HEADER),("%pure",PERCENT_PURE),                 ("%header",PERCENT_HEADER),("%pure",PERCENT_PURE),
48                   ("%token_sig_info",PERCENT_TOKEN_SIG_INFO),
49                 ("%arg",PERCENT_ARG),                 ("%arg",PERCENT_ARG),
50                 ("%pos",PERCENT_POS)]                 ("%pos",PERCENT_POS)]
51  in val lookup =  in val lookup =
# Line 589  Line 590 
590  fun f x = x  fun f x = x
591  val s = map f (rev (tl (rev s)))  val s = map f (rev (tl (rev s)))
592  exception LexHackingError  exception LexHackingError
593  fun look ((j,x)::r, i) = if i = j then x else look(r, i)  fun look ((j,x)::r, i: int) = if i = j then x else look(r, i)
594    | look ([], i) = raise LexHackingError    | look ([], i) = raise LexHackingError
595  fun g {fin=x, trans=i} = {fin=x, trans=look(s,i)}  fun g {fin=x, trans=i} = {fin=x, trans=look(s,i)}
596  in Vector.fromList(map g  in Vector.fromList(map g
# Line 709  Line 710 
710  end  end
711    
712  fun makeLexer yyinput =  fun makeLexer yyinput =
713  let  let     val yygone0=1
714          val yyb = ref "\n"              (* buffer *)          val yyb = ref "\n"              (* buffer *)
715          val yybl = ref 1                (*buffer length *)          val yybl = ref 1                (*buffer length *)
716          val yybufpos = ref 1            (* location of next character to use *)          val yybufpos = ref 1            (* location of next character to use *)
717          val yygone = ref 1              (* position in file of beginning of buffer *)          val yygone = ref yygone0        (* position in file of beginning of buffer *)
718          val yydone = ref false          (* eof found yet? *)          val yydone = ref false          (* eof found yet? *)
719          val yybegin = ref 1             (*Current 'start state' for lexer *)          val yybegin = ref 1             (*Current 'start state' for lexer *)
720    
# Line 728  Line 729 
729          | action (i,(node::acts)::l) =          | action (i,(node::acts)::l) =
730                  case node of                  case node of
731                      Internal.N yyk =>                      Internal.N yyk =>
732                          (let val yytext = substring(!yyb,i0,i-i0)                          (let fun yymktext() = substring(!yyb,i0,i-i0)
733                               val yypos = i0+ !yygone                               val yypos = i0+ !yygone
734                          open UserDeclarations Internal.StartStates                          open UserDeclarations Internal.StartStates
735   in (yybufpos := i; case yyk of   in (yybufpos := i; case yyk of
736    
737                          (* Application actions *)                          (* Application actions *)
738    
739    100 => (Add yytext; YYBEGIN STRING; continue())    100 => let val yytext=yymktext() in Add yytext; YYBEGIN STRING; continue() end
740  | 103 => (Add yytext; continue())  | 103 => let val yytext=yymktext() in Add yytext; continue() end
741  | 105 => (Add yytext; continue())  | 105 => let val yytext=yymktext() in Add yytext; continue() end
742  | 108 => (Add yytext; dec commentLevel;  | 108 => let val yytext=yymktext() in Add yytext; dec commentLevel;
743                      if !commentLevel=0                      if !commentLevel=0
744                           then BOGUS_VALUE(!lineno,!lineno)                           then BOGUS_VALUE(!lineno,!lineno)
745                           else continue()                           else continue()
746                     )                      end
747  | 11 => (Add yytext; continue())  | 11 => let val yytext=yymktext() in Add yytext; continue() end
748  | 111 => (Add yytext; inc commentLevel; continue())  | 111 => let val yytext=yymktext() in Add yytext; inc commentLevel; continue() end
749  | 114 => (Add yytext; continue())  | 114 => let val yytext=yymktext() in Add yytext; continue() end
750  | 116 => (continue())  | 116 => (continue())
751  | 119 => (dec commentLevel;  | 119 => (dec commentLevel;
752                            if !commentLevel=0 then YYBEGIN A else ();                            if !commentLevel=0 then YYBEGIN A else ();
753                            continue ())                            continue ())
754  | 122 => (inc commentLevel; continue())  | 122 => (inc commentLevel; continue())
755  | 125 => (continue())  | 125 => (continue())
756  | 127 => (Add yytext; YYBEGIN CODE; continue())  | 127 => let val yytext=yymktext() in Add yytext; YYBEGIN CODE; continue() end
757  | 129 => (Add yytext; continue())  | 129 => let val yytext=yymktext() in Add yytext; continue() end
758  | 131 => (Add yytext; error inputSource (!lineno) "unclosed string";  | 131 => let val yytext=yymktext() in Add yytext; error inputSource (!lineno) "unclosed string";
759                      inc lineno; YYBEGIN CODE; continue())                      inc lineno; YYBEGIN CODE; continue() end
760  | 134 => (Add yytext; continue())  | 134 => let val yytext=yymktext() in Add yytext; continue() end
761  | 137 => (Add yytext; continue())  | 137 => let val yytext=yymktext() in Add yytext; continue() end
762  | 14 => (YYBEGIN A; HEADER (concat (rev (!text)),!lineno,!lineno))  | 14 => (YYBEGIN A; HEADER (concat (rev (!text)),!lineno,!lineno))
763  | 140 => (Add yytext;  | 140 => let val yytext=yymktext() in Add yytext;
764                          if substring(yytext,1,1)="\n" then inc lineno else ();                          if substring(yytext,1,1)="\n" then inc lineno else ();
765                          YYBEGIN F; continue())                          YYBEGIN F; continue() end
766  | 143 => (Add yytext; continue())  | 143 => let val yytext=yymktext() in Add yytext; continue() end
767  | 145 => (Add yytext; YYBEGIN STRING; continue())  | 145 => let val yytext=yymktext() in Add yytext; YYBEGIN STRING; continue() end
768  | 147 => (Add yytext; error inputSource (!lineno) "unclosed string";  | 147 => let val yytext=yymktext() in Add yytext; error inputSource (!lineno) "unclosed string";
769                      YYBEGIN CODE; continue())                      YYBEGIN CODE; continue() end
770  | 16 => (Add yytext; inc lineno; continue())  | 16 => let val yytext=yymktext() in Add yytext; inc lineno; continue() end
771  | 18 => (Add yytext; continue())  | 18 => let val yytext=yymktext() in Add yytext; continue() end
772  | 2 => (Add yytext; YYBEGIN COMMENT; commentLevel := 1;  | 2 => let val yytext=yymktext() in Add yytext; YYBEGIN COMMENT; commentLevel := 1;
773                      continue() before YYBEGIN INITIAL)                      continue() before YYBEGIN INITIAL end
774  | 20 => (inc lineno; continue ())  | 20 => (inc lineno; continue ())
775  | 25 => (continue())  | 25 => (continue())
776  | 28 => (OF(!lineno,!lineno))  | 28 => (OF(!lineno,!lineno))
# Line 783  Line 784 
784  | 5 => (YYBEGIN EMPTYCOMMENT; commentLevel := 1; continue())  | 5 => (YYBEGIN EMPTYCOMMENT; commentLevel := 1; continue())
785  | 56 => (PREC(Hdr.RIGHT,!lineno,!lineno))  | 56 => (PREC(Hdr.RIGHT,!lineno,!lineno))
786  | 66 => (PREC(Hdr.NONASSOC,!lineno,!lineno))  | 66 => (PREC(Hdr.NONASSOC,!lineno,!lineno))
787  | 70 => (lookup(yytext,!lineno,!lineno))  | 70 => let val yytext=yymktext() in lookup(yytext,!lineno,!lineno) end
788  | 73 => (TYVAR(yytext,!lineno,!lineno))  | 73 => let val yytext=yymktext() in TYVAR(yytext,!lineno,!lineno) end
789  | 77 => (IDDOT(yytext,!lineno,!lineno))  | 77 => let val yytext=yymktext() in IDDOT(yytext,!lineno,!lineno) end
790  | 8 => (Add yytext; YYBEGIN COMMENT; commentLevel := 1;  | 8 => let val yytext=yymktext() in Add yytext; YYBEGIN COMMENT; commentLevel := 1;
791                      continue() before YYBEGIN CODE)                      continue() before YYBEGIN CODE end
792  | 80 => (INT (yytext,!lineno,!lineno))  | 80 => let val yytext=yymktext() in INT (yytext,!lineno,!lineno) end
793  | 83 => (DELIMITER(!lineno,!lineno))  | 83 => (DELIMITER(!lineno,!lineno))
794  | 85 => (COLON(!lineno,!lineno))  | 85 => (COLON(!lineno,!lineno))
795  | 87 => (BAR(!lineno,!lineno))  | 87 => (BAR(!lineno,!lineno))
796  | 90 => (ID ((yytext,!lineno),!lineno,!lineno))  | 90 => let val yytext=yymktext() in ID ((yytext,!lineno),!lineno,!lineno) end
797  | 92 => (pcount := 1; actionstart := (!lineno);  | 92 => (pcount := 1; actionstart := (!lineno);
798                      text := nil; YYBEGIN CODE; continue() before YYBEGIN A)                      text := nil; YYBEGIN CODE; continue() before YYBEGIN A)
799  | 94 => (UNKNOWN(yytext,!lineno,!lineno))  | 94 => let val yytext=yymktext() in UNKNOWN(yytext,!lineno,!lineno) end
800  | 96 => (inc pcount; Add yytext; continue())  | 96 => let val yytext=yymktext() in inc pcount; Add yytext; continue() end
801  | 98 => (dec pcount;  | 98 => let val yytext=yymktext() in dec pcount;
802                      if !pcount = 0 then                      if !pcount = 0 then
803                           PROG (concat (rev (!text)),!lineno,!lineno)                           PROG (concat (rev (!text)),!lineno,!lineno)
804                      else (Add yytext; continue()))                      else (Add yytext; continue()) end
805  | _ => raise Internal.LexerError  | _ => raise Internal.LexerError
806    
807                  ) end )                  ) end )
808    
809          val {fin,trans} = Vector.sub(Internal.tab, s)          val {fin,trans} = Unsafe.Vector.sub(Internal.tab, s)
810          val NewAcceptingLeaves = fin::AcceptingLeaves          val NewAcceptingLeaves = fin::AcceptingLeaves
811          in if l = !yybl then          in if l = !yybl then
812               if trans = #trans(Vector.sub(Internal.tab,0))               if trans = #trans(Vector.sub(Internal.tab,0))
# Line 821  Line 822 
822                       yybl := size (!yyb);                       yybl := size (!yyb);
823                       scan (s,AcceptingLeaves,l-i0,0))                       scan (s,AcceptingLeaves,l-i0,0))
824              end              end
825            else let val NewChar = Char.ord(String.sub(!yyb,l))            else let val NewChar = Char.ord(Unsafe.CharVector.sub(!yyb,l))
826                  val NewState = if NewChar<128 then Char.ord(String.sub(trans,NewChar)) else Char.ord(String.sub(trans,128))                  val NewChar = if NewChar<128 then NewChar else 128
827                    val NewState = Char.ord(Unsafe.CharVector.sub(trans,NewChar))
828                  in if NewState=0 then action(l,NewAcceptingLeaves)                  in if NewState=0 then action(l,NewAcceptingLeaves)
829                  else scan(NewState,NewAcceptingLeaves,l+1,i0)                  else scan(NewState,NewAcceptingLeaves,l+1,i0)
830          end          end

Legend:
Removed from v.514  
changed lines
  Added in v.515

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0