Antlr4 grammars for ElmerSolver

43 views
Skip to first unread message

F. S. Farimani

unread,
Mar 29, 2021, 11:56:15 AM3/29/21
to antlr-discussion

Hello everyone,

I have been looking into the ANTLR4 project for the last couple of days and I opened this issue On Elmer's repository recently. Now I want to start writing the EBNF syntax for ElmerSolver myself.

I was wondering if you could give me an example close to ElmerSpolver .sif files (chapter 2 of this PDF). The first step for me is to learn how I can create the lexer/parser grammars for blocks that start with keywords such as

  • Header
  • Simulation
  • Constants
  • Body <integer>
  • Material<integer>
  • Body Force <integer>
  • Equation <integer>
  • Solver <integer>
  • Boundary Condition <integer>
  • Initial Condition <integer>
  • Component <integer>
and end with an "End" keyword.

Thanks for your support in advance and looking forward to hearing back.

Best,
F.

Susan Jolly

unread,
Mar 29, 2021, 2:43:44 PM3/29/21
to antlr-di...@googlegroups.com
When I started using ANTLR I was retired from a career as a computational
scientist, had extensive experience with programming in Java, and was very
familiar with the domain in which I wanted to take advantage of ANTLR.
However I had no experience with parsing. Looking back there is no way I
would have succeeded in achieving my goal without a careful and
time-consuming study of Terence Parr's "The Definitive ANTLR 4 Reference."
For me the key conceptual breakthrough was figuring out how to take
advantage of the information about annotating parse-tree nodes which is at
the bottom of page 123. YMMV of course.

Best wishes.

rtm...@googlemail.com

unread,
Mar 30, 2021, 10:35:09 AM3/30/21
to antlr-discussion
Agreed with this. Grab the book and start reading.

For a grammar like yours it seems simple. Here are a lot of sample grammars <https://github.com/antlr/grammars-v4>, pick a language you're familiar with then look at the corresponding grammar and note how the grammar closely follows the language. Antlr is very flexible with its input.

Unfortunately I can't suggest something that looks like what you want, the Elmer stuff, but if you're familiar with eg. java, look at the java grammar. But read the book also.

cheers

jan
Reply all
Reply to author
Forward
0 new messages