Giter Club home page Giter Club logo

Comments (11)

kaby76 avatar kaby76 commented on June 6, 2024

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.

ydenizyamac avatar ydenizyamac commented on June 6, 2024

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.

kaby76 avatar kaby76 commented on June 6, 2024

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.

kaby76 avatar kaby76 commented on June 6, 2024

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.

ydenizyamac avatar ydenizyamac commented on June 6, 2024

I'm trying to convert it manually, but if you can make any suggestion it would be great,

thank you

best regards

AppExpressions.zip

from domemtech.trash.

kaby76 avatar kaby76 commented on June 6, 2024

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.

kaby76 avatar kaby76 commented on June 6, 2024

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.

ydenizyamac avatar ydenizyamac commented on June 6, 2024

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.

ydenizyamac avatar ydenizyamac commented on June 6, 2024

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.

kaby76 avatar kaby76 commented on June 6, 2024

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.

ydenizyamac avatar ydenizyamac commented on June 6, 2024

I managed to work it out, thank you for your support.

from domemtech.trash.

Related Issues (20)

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.