antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

ANLTR4 Pascal target for parsing Pascal Object Notation

Open coderextreme opened this issue 1 year ago • 1 comments

I am looking for a Pascal ANTLR4 target for loading “Pascal Object Notation” into a running Pascal program, similar to how XML or JSON can be loaded into a Pascal program as DOM or a JavaScript object The plan is to provide a limited version of Pascal, and perhaps domain-specific namespaces that derive from a generic grammar.

I have found the Pascal Grammar, but now, how do I process Pascal Object Notation in Pascal? This requires a limited, domain specifiable parser written in Pascal.

coderextreme avatar May 24 '24 23:05 coderextreme

The only think Google tells me about Pascal Object Notation is that this issue was opened :)

I think that you would need to expand on what you mean by that. But it sounds like a job for a hand crafted parser to be honest. If it is like JSON then it is fairly trivial. You may be able to adapt: https://www.getlazarus.org/json/

The chances of anyone writing a Pascal target for ANTLR are slim I am sorry to say.

If you don't wish to write a hand crafted parser, then you can use the Pascal version of lex and yacc, which I dare say will be perfectly adequate for your needs. https://wiki.freepascal.org/Plex_and_Pyacc

This isn't really an issue though, so perhaps you can close it?

jimidle avatar May 25 '24 15:05 jimidle

I’ve already written an ANTLR4 grammar for C++ Object Notation (CPPON), https://github.com/coderextreme/CPPON , so something for a Pascal Object Notation is not too different. I will look into Plex and Pyacc.

There’s also the possibility that I write my own Pascal target for ANTLR4, but I realize Plex And Pyacc are better for Pascal. I’m thinking of the wider problem of developing Pascal Object Notation parsers for many languages.

coderextreme avatar May 25 '24 19:05 coderextreme

Maybe an ANTLR4 grammar to Pyacc/Plex grammar translator would be more feasible?

coderextreme avatar May 25 '24 20:05 coderextreme

For example, writing a Listener/Visitor for this grammar https://github.com/antlr/grammars-v4/tree/master/antlr/antlr4 to produce Plex/Pyacc grammar!

coderextreme avatar May 25 '24 20:05 coderextreme

And thus, if there's an ANTLR4 grammar for Plex/Pyacc, how hard would it be to do a grammar to grammar translator, possibly using something like IntelliJ-MPS/VSCode/MapForce?

coderextreme avatar May 25 '24 21:05 coderextreme

Here's an example of Pascal Object Notation (no loops, recursion or if/then): https://github.com/coderextreme/pascalsai/blob/main/code/JoeSkinTexcoordDisplacerKickUpdate2.inc

coderextreme avatar May 25 '24 21:05 coderextreme

I found that chatgpt appears to convert ANTLR4 grammars to plex/pyacc grammars quite well, but I haven’t written any actions yet. At least it converted the ANTLR4 Grammar to some form of Pascal. I still need to download pyacc/plex, but I’ll do that tonight

coderextreme avatar May 26 '24 07:05 coderextreme

Here's an example of Pascal Object Notation (no loops, recursion or if/then): https://github.com/coderextreme/pascalsai/blob/main/code/JoeSkinTexcoordDisplacerKickUpdate2.inc

If that is typical, then this is a trivial problem that would actually be made more complicated by using ANTLR. You just need a Readln and a few conditions.

jimidle avatar May 27 '24 00:05 jimidle

It’s typically of HAnim. There are other aspects of X3D. Ideally, I could do a Pascal-based DSL. There’s around 300-400 classes to cover.

coderextreme avatar Dec 15 '24 16:12 coderextreme