5

I ran across the SPECS alternate grammar for C++, and while I'm not sure I like some of the more gratuitous syntax changes they made (changing pointers from * to ^, for instance), it turned me on to the idea of tweaking and implementing the new syntax. SPECS claims to be semantically identical to C++, and Clang is pretty modular, so I figured it shouldn't be too hard to write to Clang's AST, and take advantage of all the preexisting code.

That being said, I'm not really sure how easy it would be to modify Clang's current Lexer and Parser to accept different tokens and orderings (thereby taking advantage of their great error messages), or whether it would be easier to do that instead of writing a separate parser that just makes calls to Clang's AST. I've been poking around with the documentation over the past couple days, but I was wondering if someone out here with more experience with the codebase could give me some input on whether I should be searching for

  • APIs to change the lexing/parsing functionality
  • classes to outright change/subclass for my desired functionality
  • the best ways to write my own parsing to interface with the ASTs instead.
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
matthias
  • 2,419
  • 1
  • 18
  • 27
  • Clang, unfortunately, is not that modular: semantic analysis is too tightly coupled with its parsing front-end, there's no intermediate AST that you can feed to the semantic analysis independently. Of course it is still possible to plug your syntax in, but you'd have to modify the existing parser. – SK-logic Aug 19 '11 at 10:30
  • 1
    Adding to SK-logic: the problem is that C++ require tighing Parsing and Semantic Analysis, because the parser needs to act relatively differently depending on the semantic context. The gratuitous changes would probably be easy (though disambiguation can be tough), however reordering might be much more tricky :/ – Matthieu M. Aug 19 '11 at 16:29
  • I'm honestly not worried about the ordering too much, as the only changes are within the same declaration; it shouldn't matter to a parser whether the type is declared before or after the variable name, as long as it gets everything it needs from the declaration; this is especially true with the added keywords for obj, func, and type declarations that preface every decl in SPECS. – matthias Aug 19 '11 at 18:10
  • Microsoft did it and extended to parser to be able to input HLSL. https://github.com/Microsoft/DirectXShaderCompiler still in the process to check how they did it – v.oddou Oct 01 '18 at 09:14

0 Answers0