2

私の fsyacc コードは、変数が見つからないというコンパイラ エラーを出していますが、その理由がわかりません。誰かが問題を指摘してくれることを望んでいました。

%{
open Ast
%}


// The start token becomes a parser function in the compiled code:
%start start

// These are the terminal tokens of the grammar along with the types of
// the data carried by each token:
%token NAME
%token ARROW TICK VOID
%token LPAREN RPAREN
%token EOF

// This is the type of the data produced by a successful reduction of the 'start'
// symbol:
%type < Query > start

%%

// These are the rules of the grammar along with the F# code of the 
// actions executed as rules are reduced.  In this case the actions 
// produce data using F# data construction terms.
start: Query { Terms($1) }

Query:
    | Term EOF                  { $1 }

Term: 
    | VOID                      { Void }
    | NAME                      { Conc($1) }
    | TICK NAME                 { Abst($2) }
    | LPAREN Term RPAREN        { Lmda($2) }
    | Term ARROW Term           { TermList($1, $3) }

ライン | NAME {Conc($1)} と次の行の両方でこのエラーが発生します。

  error FS0039: The value or constructor '_1' is not defined

構文の問題は理解できましたが、yacc 入力の何が問題なのですか?

それが役立つ場合は、Ast の定義を次に示します。

namespace Ast
open System

type Query =
    | Terms   of Term

and Term =
    | Void
    | Conc of String
    | Abst of String
    | Lmda of Term
    | TermList of Term * Term

そして fslex 入力:

{
module Lexer
open System
open Parser
open Microsoft.FSharp.Text.Lexing

let lexeme lexbuf =
    LexBuffer<char>.LexemeString lexbuf
}

// These are some regular expression definitions
let name = ['a'-'z' 'A'-'Z' '0'-'9']
let whitespace = [' ' '\t' ]
let newline = ('\n' | '\r' '\n')

rule tokenize = parse
| whitespace    { tokenize lexbuf }
| newline       { tokenize lexbuf }
// Operators
| "->"          { ARROW }
| "'"           { TICK }
| "void"        { VOID }
// Misc
| "("           { LPAREN }
| ")"           { RPAREN }
// Numberic constants
| name+                                 { NAME }
// EOF
| eof   { EOF }
4

1 に答える 1

4

これは FsYacc のせいではありません。NAME価値のないトークンです。

これらの修正を行う必要があります。

%token NAME%token <string> NAME

| name+ { NAME }| name+ { NAME (lexeme lexbuf) }

すべてがコンパイルされるはずです。

于 2011-11-03T17:24:24.557 に答える