Ai
1 Star 8 Fork 9

sigcc/plzoofs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FunLex.fsl 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
guom 提交于 2022-05-03 09:53 +08:00 . fix
{
open FSharp.Text.Lexing
open FunPar
let lexemeAsString lexbuf =
LexBuffer<char>.LexemeString lexbuf
(* Start of outermost comment currently being scanned *)
let commentStart = ref Position.Empty;
let commentDepth = ref 0; (* Current comment nesting *)
(* Distinguish keywords from identifiers: *)
let keyword s =
match s with
| "else" -> ELSE
| "end" -> END
| "false" -> CSTBOOL false
| "if" -> IF
| "in" -> IN
| "let" -> LET
| "not" -> NOT
| "then" -> THEN
| "true" -> CSTBOOL true
| _ -> NAME s
}
rule Token = parse
| [' ' '\t' '\r'] { Token lexbuf }
| '\n' { lexbuf.EndPos <- lexbuf.EndPos.NextLine; Token lexbuf }
| ['0'-'9']+ { CSTINT (System.Int32.Parse (lexemeAsString lexbuf)) }
| ['a'-'z''A'-'Z']['a'-'z''A'-'Z''0'-'9']*
{ keyword (lexemeAsString lexbuf) }
| "(*" { commentStart.contents <- lexbuf.StartPos;
commentDepth .contents<- 1;
SkipComment lexbuf; Token lexbuf }
| '=' { EQ }
| "<>" { NE }
| '>' { GT }
| '<' { LT }
| ">=" { GE }
| "<=" { LE }
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIV }
| '%' { MOD }
| '(' { LPAR }
| ')' { RPAR }
| eof { EOF }
| _ { failwith "Lexer error: illegal symbol" }
and SkipComment = parse
"*)" { commentDepth.contents <- commentDepth.contents - 1;
if commentDepth.contents = 0 then ()
else SkipComment lexbuf
}
| "(*" { commentDepth.contents <- commentDepth.contents + 1;
SkipComment lexbuf }
| eof { failwith "Lexer error: unterminated comment" }
| _ { SkipComment lexbuf }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sigcc/plzoofs.git
git@gitee.com:sigcc/plzoofs.git
sigcc
plzoofs
plzoofs
master

搜索帮助