Skip to content
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

Adding A New Language (Ada) #207

Open
sanyaade-mobiledev opened this issue Jan 7, 2019 · 2 comments
Open

Adding A New Language (Ada) #207

sanyaade-mobiledev opened this issue Jan 7, 2019 · 2 comments

Comments

@sanyaade-mobiledev
Copy link

Hello Everybody,

First thank you for making Droplet. I have been studying and learning it for about a week now.
I am adding Ada language to droplet. So far so good I have been following the instructions from https://github.com/cacticouncil/droplet/blob/master/docs/AddingLanguages.docx and been able to run Antlr to generate required files (parser, lexer, listener, etc..)

But I have hit a block on how to modify the grammar file to add _DropletFile and EOF and which section/part of the anltlr4 Ada.g4 grammar should I modify/Duplicate? Is there a script file to run on the grammar file?

I have looked at c.g4 and java.g4 but I need more help and tips. Many thanks!
Is there a document that I could follow more on this? many thanks!

Once again many thanks for your support!

Hear from you soon!

God blesses!!!

Best regards,
Sanyaade

@doctorjei
Copy link

Hey Sanyaade!

When I built the new Java version (basically from the ground up), I pretty much duplicated everything. There is no script that I'm aware of (though I'm a relative newcomer!)

We also have a C# branch in the cacticouncil repo - might be worth a look.

Regards,
Jeremiah

@sanyaade-mobiledev
Copy link
Author

@misterjei

Many thanks for your quick reply!

My Dilemma is that I am working on Ada language so it difficult for me to know where to start the modification from. I just need a pointer on what I should look for? or pointer on which part to modify.

Do I need to make this modification before running the antlr command on the grammar file or after? Many thanks!

Oh I see! when I went through those grammars in the repository, there are section with e.g. for the CSharpParser.g4 extract below. Thos only starts from line 1297 to the end of the file
// droplet - Duplicate grammar rules
// entry point
compilationUnit_DropletFile
: BYTE_ORDER_MARK? extern_alias_directives? using_directives?
global_attribute_section* namespace_member_declarations? EOF
;

Also on the C grammar (C.g4) on the repository and from line 583, to the end of the file, we have the modification:

/* Droplet: ANTLR has trouble parsing a string when a rule doesn't
contain an EOF token at the end of it. To do live reparsing, we
have to define new duplicate rules for each intermediate node plus EOF
so that we can parse small parts of the program independently.
*/
primaryExpression_DropletFile
: Identifier EOF
| Constant EOF
| StringLiteral+ EOF
| '(' expression ')' EOF
| genericSelection EOF
| 'extension'? '(' compoundStatement ')' EOF // Blocks (GCC extension)
| '__builtin_va_arg' '(' unaryExpression ',' typeName ')' EOF
| '__builtin_offsetof' '(' typeName ',' unaryExpression ')' EOF
;

I have attached the Ada.g4 file here

Ada.txt

Also noted (extracted form the guide line on adding a language document:
antlr4 -Dlanguage=JavaScript NewLanguage.g4
This will generate several files that can then be used for Droplet. NOTE: the grammar file must be modified / updated so that it can be handled properly by Droplet in some cases by duplicating grammar nodes and adding _DropletFile in order to handle EOF elements. This may be language-dependent; I’m still exploring whether any language do not need this. Your mileage may vary.

Please help me! Many thanks!

Your time is much appreciated!!!

God blesses!!!

Best regards,
Sanyaade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants