Comments (11)
Sorry, I haven't pushed the TrashBase package to Nuget yet. I'll do that now so you can try to do a build. I think it should be able to do the convert, but I haven't tested it recently. You'd have to do something like trparse -f ANTLRv2.g2 -t antlr2 | trconvert | trprint
. I'd recommend that you just install the Dotnet tools though if you aren't customizing the code:
#version="--version 0.7.0"
version=""
dotnet tool install -g tranalyze $version
dotnet tool install -g trconvert $version
dotnet tool install -g trfold $version
dotnet tool install -g trfoldlit $version
dotnet tool install -g trgen $version
dotnet tool install -g trgroup $version
dotnet tool install -g trjson $version
dotnet tool install -g trkleene $version
dotnet tool install -g trparse $version
dotnet tool install -g trprint $version
dotnet tool install -g trrename $version
dotnet tool install -g trst $version
dotnet tool install -g trstrip $version
dotnet tool install -g trtext $version
dotnet tool install -g trtokens $version
dotnet tool install -g trtree $version
dotnet tool install -g trunfold $version
dotnet tool install -g trungroup $version
dotnet tool install -g trwdog $version
dotnet tool install -g trxgrep $version
dotnet tool install -g trxml $version
dotnet tool install -g trxml2 $version
And, since you are only interested in the conversion, just install trparse, trconvert, trprint.
Note, if you are doing it from Powershell or Cmd, then just remove the "$version", i.e., dotnet tool install -g trparse
.
from domemtech.trash.
Hello,
Thanks for the answer. I'm getting errors when trying to convert;
line 1:0 mismatched input 'options\r\n{' expecting {'lexer', 'parser', 'grammar'}
line 3:10 mismatched input '=' expecting SEMI
line 4:11 mismatched input '=' expecting {BEGIN_ARGUMENT, OPTIONS, 'returns', 'locals', 'throws', COLON, AT}
line 7:24 missing COLON at ';'
line 9:0 mismatched input 'options {' expecting {, 'mode'}
Error in parse of C:\Users\deniz.yamac\Desktop\Domemtech.Trash-main\Release\net5\Example.g4
I'm not much experienced with the antlr grammar but it throws an error in g4 file?
Command: trparse -f .\VeriParkExpressions.g -t antlr2 | trconvert
from domemtech.trash.
There's an error message related to a grammar Example.g4 that has nothing to do with the grammar you are trying to parse. The tool reads other grammars besides the grammar you specify, which is wrong for Antlr2 now that I think about it. Try creating a directory, copying the old Antlr2 grammar to that clean directory, cd to the directory, then try the trparse/trconvert without any path information, i.e., mkdir foobar; cd foobar; cp ......./VeriParkExpressions.g .; trparse -f VeriParkExpressions.g -t antlr2 | trconvert | trprint
(no .\
, and adding the required trprint
since if you don't add that, you just get parse tree data as output--completely useless for you). In the meanwhile, I'll make sure that trparse doesn't go fishing around everywhere when parsing an Antlr2/3 file.
--Ken
from domemtech.trash.
I reproduced the problem. Yes, trparse is trying to read too much. It has to because people split grammars in Antlr4 (e.g., the Java9 grammar and you say you want to parse JavaLexer.g4). Split grammars don't happen in Antlr2, but I read every grammar anyways, trying to parse Antlr4 grammars in Antlr2 syntax. The workaround is to just copy the Antlr2 grammar to a clean directory, cd to it, and run the tool.
I'll have a fix later today.
from domemtech.trash.
I'm trying to convert it manually, but if you can make any suggestion it would be great,
thank you
best regards
from domemtech.trash.
It also looks like the Antlr2 grammar I use to parse Antlr2 grammars needs work. After removing some code blocks and "< AST = ...>" code, I was finally able to get it to convert. See attached file.
xx.zip
from domemtech.trash.
Sorry, there were a number of other problems. Here is a grammar that actually gets through the Antlr4 tool. I don't have any input, so I couldn't test per se.
xx.zip
There are a number of wonderful things I don't do right with this grammar. Would you mind if I add it to the grammars-v4/antlr/antlr2/examples area, and include it in a test suite for the Trash toolchain? --Ken
from domemtech.trash.
Hello there,
Firstly, you can use it as an example, of course :)
And yes , it works now. I'm trying to implement nodes in c# for literals, like StringLiteralNode, I hope I'm doing it correctly :)
from domemtech.trash.
I could not update custom operators and nodes antlr4 correctly. I did some part but I'm confused. Can you please guide or make any suggestion for me to update BaseAST part correctly. We have nodes, operators with same base abstract class. In older implementation, opreators running in parser for example. I could not do it that way.
Old AST's are using getFirstChild(), getNextSibling() etc. I simulated that with children but it does not look right.
Thanks,
Best Regards
from domemtech.trash.
Antlr version 4 doesn't produce an AST, but I recommend that you use the CST. Add options { contextSuperClass=MyBaseClassForTreeNode; }
in the parser grammar to set the node type base class type you want to create in the tree. (I don't think Parr describes this anywhere in antlr.org very well, so you may have to try it out first on the Arithmetic example.) Of course, the CST won't be exactly a one-to-one mapping with your old AST, so you will need to rewrite some of your code, especially when accessing child nodes of the old AST, or add accessor methods to your base class to make it look like the old AST. For the CST, you can access a particular child with an index using getChild(index), or use the name of the symbol used in the RHS to get one or more children of that type, e.g., "foo -> bar bar other;" => "foo_cst_node.bar()". These are generated by the Antlr Tool.
from domemtech.trash.
I managed to work it out, thank you for your support.
from domemtech.trash.
Related Issues (20)
- I rewrote trrename, but it's much slower
- Add support for parse tree verification in tests HOT 1
- Implement full .errors verification in tests HOT 1
- Bootstrap supported_grammars in Trash
- Standardize trgen template drivers so output is tabular and can be fed to statistical programs HOT 1
- Fix trgen Cpp template so that it works on Windows HOT 1
- ll(k) to ll(1) HOT 1
- trunfold no longer works
- trparse tree output is not the same as what is reconstructed when read by deserializer
- trgen, trparse, etc., should generate target-specific name
- Add parameter to trgen so you don't need to be where pom.xml is.
- Add option to trparse to read files to parse
- Tree/token stream/char stream representation in Antlr is extremely inefficient for editing; need to change HOT 1
- Add option to all apps to output formatted JSON
- Pom.xml should be removed for all trgen except Java target
- Add new command to delete parse tree node and move children up
- Consider marking repository with Github topic 'antlr'
- Treesitter HOT 5
- Build Issues
- trperf does not output alt numbers for rules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from domemtech.trash.