fsyacc

Is it possible to define types that depend on each other and are defined in separated files?

独自空忆成欢 提交于 2019-12-22 08:18:54
问题 I am trying to implement a library with extended parsing capabilities. I decided that I will use fsyacc because I knew it from the university. Unfortunately I encountered following problem. I defined a class for the head of my grammar ( Head ) and place its implementation in a single file. Then I defined parser as: ... %start head %type <Head> head ... Fsyacc generates seeparated module ( Parser ). In order to succeed it has to be compiled in following order: Head.fs Parser.fs In order to

Using FsLex/Yacc in Vs2013

时间秒杀一切 提交于 2019-12-22 07:48:31
问题 I'm trying to resurrect an old f# parser project I had working in vs 2008 to work with vs 2013. It uses FsLexYacc. I got it building ok by using a prebuild step as thus: fslex --unicode "$(ProjectDir)XpathLexer.fsl" fsyacc --module XpathParser "$(ProjectDir)XpathParser.fsy" But this is less than ideal, as it always executes whether or not the inputs have changed. I then tried just using the old MsBuild actions: <FsYacc Include="XpathParser.fsy"> <FsLex Include="XpathLexer.fsl"> but these

How to add and use custom context parameters during parsing with F# FsYacc?

十年热恋 提交于 2019-12-21 06:21:47
问题 I'm using FsLex and FsYacc for string parsing in F# application. During Abstract Syntax Tree (AST) creation parser has to do a decision how to create the AST (make different trees, throw an exception, etc). The parser behaviour must depend on several parameters. Here I've found that it is allowed to declare something like: %type < (context -> context) > toplevel But I could not find how to use this construction and during project compilation have "fsyacc.exe" exited with code 1." error The

Meaningful errors during parsing with FSyacc

佐手、 提交于 2019-12-18 17:36:29
问题 I'm using fsyacc/fslex from F# Power Pack to parse some source code. To detect errors I use the following code: use inputChannel = new StreamReader(File.OpenRead tempFileName) let lexbuf = Lexing.LexBuffer<_>.FromTextReader inputChannel let ast = try Parser.start Lexer.tokenize lexbuf with e -> let pos = lexbuf.EndPos let line = pos.Line let column = pos.Column let message = e.Message let lastToken = new System.String(lexbuf.Lexeme) printf "Parse failed at line %d, column %d:\n" line column

Parsing a sequence of expressions using yacc

坚强是说给别人听的谎言 提交于 2019-12-11 08:55:57
问题 I am trying to parse a sequence of expressions without delimiters in order to be able to parse ML/F# style function invocations: myfunc expr1 expr2 expr3 However, the sequence of expressions is giving me a list of shift/reduce conflicts. My guess is that the conflicts are caused by the recursive nature of my grammar, but I don't know how to fix these conflicts. My (simplified) precedence rules and grammar looks like this: /* Lowest precedence */ %left PLUS %left TIMES %left LPAR /* Highest

Error in example grammar for Fsyacc?

强颜欢笑 提交于 2019-12-08 07:21:04
问题 So I am trying to write a compiler in F# and have been looking at the Fslex and Fsyacc tools that come with the F# powerpack. There is a sample project that takes care of the external build tools that I have been trying to understand. It can be downloaded here. The example compiles and runs for me, but I think there is a subtle error in the grammar. I say subtle, because the grammar looks similar to what I have seen in the Dragon book for parsing expressions and I don't have the experience to

Is it possible to define types that depend on each other and are defined in separated files?

扶醉桌前 提交于 2019-12-05 14:23:24
I am trying to implement a library with extended parsing capabilities. I decided that I will use fsyacc because I knew it from the university. Unfortunately I encountered following problem. I defined a class for the head of my grammar ( Head ) and place its implementation in a single file. Then I defined parser as: ... %start head %type <Head> head ... Fsyacc generates seeparated module ( Parser ). In order to succeed it has to be compiled in following order: Head.fs Parser.fs In order to make this library similar to what you can find in .NET I would like to add a static Parse method to Head .

How to add and use custom context parameters during parsing with F# FsYacc?

醉酒当歌 提交于 2019-12-03 21:20:09
I'm using FsLex and FsYacc for string parsing in F# application. During Abstract Syntax Tree (AST) creation parser has to do a decision how to create the AST (make different trees, throw an exception, etc). The parser behaviour must depend on several parameters. Here I've found that it is allowed to declare something like: %type < (context -> context) > toplevel But I could not find how to use this construction and during project compilation have "fsyacc.exe" exited with code 1." error The Question is: is it possible and how to use context parameters during parsing with FsYacc? Example of what

Meaningful errors during parsing with FSyacc

瘦欲@ 提交于 2019-11-30 15:40:26
I'm using fsyacc/fslex from F# Power Pack to parse some source code. To detect errors I use the following code: use inputChannel = new StreamReader(File.OpenRead tempFileName) let lexbuf = Lexing.LexBuffer<_>.FromTextReader inputChannel let ast = try Parser.start Lexer.tokenize lexbuf with e -> let pos = lexbuf.EndPos let line = pos.Line let column = pos.Column let message = e.Message let lastToken = new System.String(lexbuf.Lexeme) printf "Parse failed at line %d, column %d:\n" line column printf "Last loken: %s" lastToken printf "\n" exit 1 But when this code throws the error message on