KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
vyacc
★ 20
Open GitHub ↗
YACC for V
Download README (.md)
Explore Similar Repositories
Project64-1.6-Plus
:
No description available.
fast-ai-cold-calling
:
No description available.
wild
:
Server framework for RedM
sbitxhat
:
Raspberry Pi HAT for SDR experimenters
In-context_Learning_for_Automated_Driving
:
No description available.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
vyacc
?
Download (.md)
# vyacc [yacc](https://en.wikipedia.org/wiki/Yacc) for V. It was adapted from https://pkg.go.dev/golang.org/x/tools/cmd/goyacc. See [vyacc.v](https://github.com/elliotchance/vyacc/blob/main/vyacc.v) for full license and credits. # Example ``` v run vyacc.v examples/calc.y ``` Will generate a `y.v` from the grammar. Then compiler/run as usual: ``` v run y.v ``` # Documentation Any existing docs for yacc should be relevant. Read below for some specifics of this implementation. ## Tokens All tokens in the grammar are converted to lower-case with a `token_` prefix to work with V language rules. So `KEYWORD_ABS` is referenced in code as `token_keyword_abs`. You will need to provide an implementation for `YYSymType` (this is what is used for all `$` tokens): ``` struct YYSymType { mut: // Your custom fields here. yys int } ``` ## Lexer You will need to provide your own lexer that implements: ```v interface YYLexer { mut: lex(mut lval YYSymType) int error(s string) } ``` ## Parser The original (and Go version) of yacc depend on global/module variables for parser output. Since that is not allowed in V, you have to assign `yyrcvr.lval` in the grammar: ``` root_rule: subrule { yyrcvr.lval = $1 } ``` Then cast the parser to get access to it: ```v mut parser := yy_new_parser() parser.parse(mut lex) result := (parser as YYParserImpl).lval ```