9

I scoured the Mix and Solidity repos for something like a formal definition of the language's grammar, so that one may generate parsers using tools like GrammarKit, but couldn't find anything.

Any pointers?

9

There's a file called grammar.txt in the Solidity repo:

https://github.com/ethereum/solidity/blob/develop/docs/grammar.txt

That's probably what you're looking for?

  • Thanks! I searched for "grammar" in the same repo, and the only thing GitHub was able to find was "Scanner.cpp"... Too bad they're not using BNF, I might raise an issue for that. Should be easy to convert though. – Matthias Jun 15 '16 at 15:02
  • @Matthias could you explain how to convert that file to BNF? – Sri Aug 14 '16 at 20:07
  • 2
    NOTE: This has now moved to github.com/ethereum/solidity/blob/develop/docs/grammar.txt – Richard Horrocks Jan 5 '17 at 15:07
7

I wrote an ANTLR4 grammar for Solidity that you may find useful:

https://github.com/solidityj/solidity-antlr4

It can generate parsers in any of the ANTLR supported targets and it has full support for the Solidity language as of today.

2

Here's yet another link pointing to the solidity documentation:

http://solidity.readthedocs.io/en/develop/miscellaneous.html#language-grammar

0

There is also a grammar based on javascript grammar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.