Open Nic30 opened 5 years ago
I tried to use the grammer files from them. but nono of them can success with the target Go language. It passes with Python
Hello @zhuzhzh,
if you use https://github.com/Nic30/hdlConvertor/blob/master/grammars/sv2017Parser.g4 and https://github.com/Nic30/hdlConvertor/blob/master/grammars/sv2017Lexer.g4
you have to replace c++ in "{}" blocks (semantic predicates) in sv2017Lexer.g4. It should be trivial.
However I guess you also need a preprocessor. https://github.com/Nic30/hdlConvertor/blob/master/grammars/verilogPreprocParser.g4 https://github.com/Nic30/hdlConvertor/blob/master/grammars/verilogPreprocLexer.g4
verilogPreprocLexer.g4 also contains C++ which have to be translated to Go.
Currently I do not know how write grammar which does support multiple target languages (and uses semantic predicates in target language). And it is required to use target language directly sometimes because otherwise some things would be impossible, some extremely slow.
(I would gladly make another targets for grammars mentioned, I just do not know how to do it without code replication.)
Currently I do not know how write grammar which does support multiple target languages (and uses semantic predicates in target language).
Take a took at the approach that used for javascript and php grammars. It works at least for C#, Java, and can be adapted on other runtimes.
@KvanTTT , nice I do not know how could I miss this, I was looking at grammars-v4.
@KvanTTT , do you think that it is possible to replace some existing unfinished grammar in grammars-v4 with own implementation, I would like to share some grammars, system verilog and vhdl, however some non complete version of grammar is already present in grammars-v4.
If your grammars cover more syntax than I think yes, it makes sense to replace existing unfinished grammars.
@Nic30 , do you know what's the best sv2017 grammer for ANTLR? just for syntax, it seems sv-parser(https://github.com/dalance/sv-parser) written in RUST is more complete.
@zhuzhzh As far as I know only sv-parser and hdlConvertor have complete sv grammar https://symbiflow.github.io/sv-tests/
@Nic30 in the compariosn result, I think sv-parser, veriable and surelog have the best coverage. From the public doc, they just generate CST instead of AST. I want to confirm hdlConvertor can generate CST.
Besides, I just have a glance at the grammer file in hdlConvertor. The line number of sv2017Parser.g4 is 2282. The line number of 658. The line number of verilogPreprocLexer.g4 is 338. The line number of verilogPreprocParser.g4 is 190. The sum is 3468. It's great that It's less than I thought.
@zhuzhzh This is a tricky question because lower layer antrl4 parser produces a CST, however the convertor layer which translates this low level CST to hdlAst generates AST. The AST representation is there because it is more easy to work with.
So the response is probably hdlConvertor can generate both.
Thanks for your patient answer, @Nic30
Hello,
I am looking for up-to-date complete System Verilog grammar.
I know about:
Do you know about any other System Verilog grammars?
I would like to have 2017 grammar which works exactly as standard describes, but it quite lot of time to extract it and fix it in order to make it work with ANTL4 as the grammar is very large and complex.