6

I was using the solidity grammar specification https://github.com/ethereum/solidity/blob/develop/docs/grammar.txt to write a parser in Smalltalk. After coding a first version of the parser, I started to test examples from the solidity documentation https://media.readthedocs.org/pdf/solidity/develop/solidity.pdf. I was surprised that many examples did not work, mostly because the documentation is not consistent with the grammar specification.

I am just going to show one simple example of these inconsistencies. In the grammar, string literals are written by double quotes only (line 125). On the other hand, the documentation specifies that string literals are written with either double or single quotes (page 41). This is just one of many inconsistencies I found by a quick look at the documentation.

So, my question is which one is the most correct? The grammar or the documentation? I need to know which one I must take into account to write a parser that can handle solidity.

Edit: Here is the current Pharo/Smalltalk Solidity Parser, in case anyone wants to see. https://github.com/hscrocha/SmaCC-Solidity

Edit 2: I saw that a few days ago the Solidity grammar was updated on github. This update did not fix the inconsistencies I found between the grammar and documentation.

Thanks and best regards,

  • Henrique
  • I would read the source code for the [solidity compiler] and use that as a source of truth. [solidity compiler]: github.com/ethereum/solidity – 0xcaff Jul 27 '17 at 2:43
1

Sorry for the inconsistencies. Not many people are using grammar.txt to write parsers. It would be great if you could report any inconsistencies you find by opening an issue on github!

As far as your question is concerned: I would say that the code is most correct, but all three of them, docs, code and grammar can have bugs.

  • Thanks for the answer. Any idea if the official compiler code is manually implemented or if it is created (auto or semi-auto) by a parser generator tool? If it uses a generator, then it should have some form of grammar specification to feed the generator. – Henrique Rocha Sep 5 '17 at 14:56
  • @HenriqueRocha it is a manually implemented top down parser with some limited lookahead. – chriseth Sep 5 '17 at 14:58

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.