douxing1969 2012-03-27 16:53
浏览 65
已采纳

Go使用Go来解析自身?

I am starting a class project that regards adding some functionality to Go.

However, I am thoroughly confused on the structure of Go. I was under the impression that Go used flex and bison but I can't find anything familiar in the Go source code.

On the other hand, the directory go/src/pkg/go has folders with familiar names (ast, token, parser, etc.) but all they contain are .go files. I'm confused!

My request is, of anyone familiar with Go, can you give me an overview of how Go is lexed, parsed, etc. and where to find the files to edit the grammar and whatnot?

  • 写回答

3条回答 默认 最新

  • dsjpik057730 2012-03-27 22:31
    关注

    The directory structure:

    src/cmd/5*   ARM
    src/cmd/6*   amd64 (x86-64)
    src/cmd/8*   i386 (x86-32)
    
    src/cmd/cc   C compiler  (common part)
    src/cmd/gc   Go compiler (common part)
    src/cmd/ld   Linker      (common part)
    src/cmd/6c   C compiler  (amd64-specific part)
    src/cmd/6g   Go compiler (amd64-specific part)
    src/cmd/6l   Linker      (amd64-specific part)
    

    Lexer is written in pure C (no flex). Grammar is written in Bison:

    src/cmd/gc/lex.c
    src/cmd/gc/go.y
    

    Many directories under src/cmd contain a doc.go file with short description of the directory's contents.

    If you are planning to modify the grammar, it should be noted that the Bison grammar sometimes does not distinguish between expressions and types.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?