GithubHelp home page GithubHelp logo

klcz / yaccgo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acekingke/yaccgo

0.0 0.0 0.0 882 KB

YaccGo is an unstantable and debugable Yacc in Go

License: MIT License

Go 96.03% Makefile 1.27% HTML 2.70%

yaccgo's Introduction

logo

YaccGo

License

Through Google has tool about yacc named goyacc, But it generate go code can not debug! see the issue

golang/vscode-go#1674 (comment)

I tried to modify the codes, It is not good readable, and I have no patient to do it, So I write a YaccGo

YaccGo is an understandable and debugable Yacc in Go. . It is written in Go and generates parsers written in Go ,typescript, rust ...

Quick Start

clone the code

make all
# generate the typescript parser code
bin/yaccgo generate typescript examples/exprts.y expts.ts

at your y file You should do as follower more in manual

Trace

After generate the parse code, modify the var IsTrace bool = false to var IsTrace bool = true , then you can see the trace of the parser. feature completed for go, other are WIP. for example:

bin/yaccgo generate go examples/ladd.y out/ladd.go

then you modify the ladd.go file, change code var IsTrace bool = false to var IsTrace bool = true, then

go run out/ladd.go

You can see trace information

look ahead NUM, use Reduce:PROG -> , go to state 1
Shift PROG, push state 1
Shift NUM, push state 3
look ahead PLUS, use Reduce:E -> NUM , go to state 2
Shift E, push state 2
Shift PLUS, push state 5
Shift NUM, push state 3
look ahead NL, use Reduce:E -> NUM , go to state 6
Shift E, push state 6
look ahead NL, use Reduce:E -> E PLUS E , go to state 2
Shift E, push state 2
Shift NL, push state 4
3
look ahead $, use Reduce:PROG -> PROG E NL , go to state 1
Shift PROG, push state 1
0

parser with context

if you want build several parser in one app, you should use generate parser with context. Now it is just supported in Go add -o option in generate command, for example:

 bin/yaccgo generate go  -o examples/e.y  out/e.go 

then, you should make context before using the parser, for example like this:

func main() {
	c := MakeParserContext()
	v := c.Parser("nnn")
	fmt.Println(v)
}

Web Debuger

If you want to debug the parser visually, you can use yaccgo debuger in browser. debuger

1. generate http debuger parser

./bin/yaccgo generate go --httpdebug=true examples/exprhttp.y out/expr.go

2. run http debuger

go run out/expr.go

3. open the debugTool.html in browser

Design

LALR1 Algorithm Base on

https://hassan-ait-kaci.net/pdf/others/p615-deremer.pdf

Lexer inspired from

https://www.youtube.com/watch?v=HxaD_trXwRE

RoadMap

  1. support language:
  • go

  • typescript

  • rust

  1. DotGraph

    surpose your machine has got dot , or you can install it from https://graphviz.org/download/

    if you want to see the LALR DFA(deterministic finite automata) diagram. use the -g or --dotg=

    for example:

    bin/yaccgo generate go -g./expr.png -o ./examples/exprobj.y ./out/exprobj.go

you can see the diagram as follow: DFA

Project use yaccgo

see wiki and add your own project to it

Contributing

Welcome to contributing, We appreciate your help! please make sure

  • staticcheck no error
  • codes should has test

ChangeLogs

2022.5.30

  1. Optimize the packtable use action default values and goto default values
  2. use the template to generate the Code
  3. reserve the old codes but it will deprecate them in future 2022.9.22
  4. add the oop code generator 2022.11.4
  5. support dot graphviz

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.