-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the verilog/systemverilog grammar generates parsers that behave differently when the target is java or c++ #2401
Comments
Right. Reading your main() driver, you call the lexer independently before the parser. You don't reset the lexer state before the parse. You really should try creating the CommonTokenStream and pass that to the parser without any intervening calls to "fill()" or "getTokens()". Just don't touch the token stream--let the parser deal with it. Or, you can call "reset()" on the CommonTokenStream, I think. In the driver I generate with trgen, I do something like this. |
thx thx thx!!!!
I will try it immediately
Alex
Il giorno 24 Nov 2021, 23:57, alle ore 23:57, Ken Domino ***@***.***> ha scritto:
…Right. Reading your main() driver, you call the lexer _independently_
before the parser. You don't reset the lexer state before the parse.
You really should try creating the CommonTokenStream and pass that to
the parser without any intervening calls to "fill()" or "getTokens()".
Just don't touch the token stream--let the parser deal with it. Or, you
can call "reset()" on the CommonTokenStream, I think.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2401 (comment)
|
thx, unfortunately still this code: #include <iostream>
#include <fstream>
#include "antlr4-runtime.h"
#include "SystemVerilogLexer.h"
#include "SystemVerilogParserParser.h"
using namespace antlr4;
int main(int argc, const char **args) {
std::ifstream ins;
ins.open(args[1]);
ANTLRInputStream input(ins);
SystemVerilogLexer lexer(&input);
CommonTokenStream tokens(&lexer);
// tokens.fill();
// for (auto token : tokens.getTokens()) {
// std::cout << token->toString() << std::endl;
// }
// tokens.reset();
SystemVerilogParserParser parser(&tokens);
tree::ParseTree* tree = parser.source_text();
std::cout << tree->toStringTree(&parser) << std::endl << std::endl;
return 0;
} produces :
and this code: /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
//
// main.cpp
// antlr4-cpp-demo
//
// Created by Mike Lischke on 13.03.16.
//
#include <iostream>
#include <fstream>
#include "antlr4-runtime.h"
#include "SystemVerilogLexer.h"
#include "SystemVerilogParserParser.h"
using namespace antlr4;
int main(int argc, const char **args) {
std::ifstream ins;
ins.open(args[1]);
ANTLRInputStream input(ins);
SystemVerilogLexer lexer(&input);
CommonTokenStream tokens(&lexer);
tokens.fill();
for (auto token : tokens.getTokens()) {
std::cout << token->toString() << std::endl;
}
tokens.reset();
SystemVerilogParserParser parser(&tokens);
tree::ParseTree* tree = parser.source_text();
std::cout << tree->toStringTree(&parser) << std::endl << std::endl;
return 0;
} produces:
the java one:
produces :
and the tree is seen in the snapshot, which seems much more correct to me ... |
The systemverilog grammar appears to be a split grammar but it's not done right. For example, the parse fails at the start of a |
Ah ok thx
Then I know I can forget this grammar one on GitHub
Ok no problem
Thx
Alex
Inviato da Posta per Windows
Da: Ken Domino
Inviato: giovedì 25 novembre 2021 12:21
A: antlr/grammars-v4
Cc: Alessandro Ogheri; Author
Oggetto: Re: [antlr/grammars-v4] the verilog/systemverilog grammar generatesparsers that behave differently when the target is java or c++ (Issue #2401)
The systemverilog grammar is supposed to be a split grammar but it's not done right. For example, the parse fails at the start of a #. The lexer grammar doesn't have a token type for that. Further the parser grammar isn't really a parser grammar because it doesn't have a "parser grammar" declaration, instead a combined "grammar" declaration. So, it is a combined grammar and has a lexer grammar. The grammar is messed up.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
@ogheri please strip such long messages, keep only important info. It's not informative for other users and it interrupts messages flow. |
This is a bug in the grammar; it should be fixed. I've noticed malformed split/combined grammars elsewhere in grammars-v4 that I've had to fix recently. So, it would be a good idea to add a check for this to the Antlr tool, and/or Antlr Maven plugin (which calls the tool), and/or trgen to detect and flag malformed split/combined grammars. I'll make a note in Trash to add the feature. I don't have time to fix this grammar. If someone would like to do that, excellent. I am still working on the scraping problem for ISO C++, with a diversion into converting the C grammar into Lark syntax for the Lark parser generator. |
Thx anyway for your time and your patience
I repeat, what puzzles me the most, though, is that the java created environment starting from the same set of 2 .g4 files WORKS PERFECTLY…strange…
Thx again
Alex
Da: Ken Domino
Inviato: giovedì 25 novembre 2021 12:55
A: antlr/grammars-v4
Cc: Alessandro Ogheri; Author
Oggetto: Re: [antlr/grammars-v4] the verilog/systemverilog grammar generatesparsers that behave differently when the target is java or c++ (Issue #2401)
This is a bug in the grammar, and should be fixed. I've noticed split/combined grammars elsewhere that I've had to fix recently. So, it would be good idea to add a check for this to the Antlr tool, and/or Antlr Maven plugin, and/or trgen to detect and flag malformed split/combined grammars. I'll make a note in Trash to add the feature to trgen. I don't have time to fix trgen yet, nor this grammar--I am still working on the scraping problem for ISO C++, with a diversion into converting the C grammar for the Lark parser generator.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Hi @ogheri, |
Hi @ogheri, |
this now WORKS GREAT!!!! thx a lot Mustafa and....by the way...no need to say that it is a mess! |
now for my needs and for the testing I did so far, i.e. on the 4 .sv systemverilog examples inside the "examples" directory plus just some of me I have not found errors... |
@ogheri Could you please check my PR #2402 as to whether it runs with the Cpp target? I understand that you are using a different grammar now, but the grammar here really should not be left broken. I cannot add reviewers in the GitHub system because I don't have write privileges to the repo, which is fine. Github is ineptly designed so I can't add a reviewer. |
Ok as soon as I have some time I will check that Ken…
Alex
Da: Ken Domino
Inviato: venerdì 26 novembre 2021 13:31
A: antlr/grammars-v4
Cc: Alessandro Ogheri; Mention
Oggetto: Re: [antlr/grammars-v4] the verilog/systemverilog grammar generatesparsers that behave differently when the target is java or c++ (Issue #2401)
@ogheri Could you please check my PR #2402 as to whether it runs with the Cpp target? I understand that you are using a different grammar now, but the grammar here really should not be left broken. I cannot add reviewers in the GitHub system because I don't have write privileges to the repo, which is fine. Github is ineptly designed so I can't add a reviewer.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Hi Ken and Kaby (or...ehr...is the same ? ?) (sorry if i am confused...) YES it works perfectly with the cpp target and I do not have any warning any more now, FIRST and ...SECOND.....is now SIGNIFICANTLY faster... thx again to all of you (Mustafa included, though, for the original files, too...) ! |
Hi Alex, Thank you for checking this quickly. I'm happy this is working. I have a few ideas on things to add to Trash for tranalyze. "Ken Domino" is my real name; "kaby" my user name, from a friend over 30 years ago. --Ken |
I hope to have proceeded correctly, as this is my 1st time on GitHub…and I hope to have respected all rules of conduct and netiquette
Thx again to all of you for the help!
Alex
Da: Ken Domino
Inviato: venerdì 26 novembre 2021 15:40
A: antlr/grammars-v4
Cc: Alessandro Ogheri; Mention
Oggetto: Re: [antlr/grammars-v4] the verilog/systemverilog grammar generatesparsers that behave differently when the target is java or c++ (Issue #2401)
Hi Alex, Thank you for checking this quickly. I'm happy this is working. I have a few ideas on things to add to Trash for tranalyze. "Ken Domino" is my real name; "kaby" my user name, from a friend over 30 years ago. --Ken
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Hi dear all, I was interested in the verilog/systemverilog grammar and tried to use it with the cpp (c plus plus) target.
Well , when I do
java org.antlr.v4.Tool -Dlanguage=cpp SystemVerilogLexer.g4 SystemVerilogParser.g4 and then
g++ -o antlrparser *cpp -I. -I.....Cpp/runtime/src -L ...../runtime/Cpp/dist -lantlr4-runtime
that successfully creates the executable (provided I added a main.cpp that instantiates a Lexer and a Parser (by the way, why do I get a parser that is called SystemVerilogParserParser (with 2times Parser ? ?) ?) and then starts with the parsing rule "source_text" I get that all the "examples/bla bla" systemverilog designs are not parsed correctly...
doing the same in java, creating the java parser and lexer and running the java compiled and created equivalent main java program, instead, works fine ...
Please see also the attached snapshot...
The text was updated successfully, but these errors were encountered: