3 ms·
They aren't incompatible. My own toy language which is intended to be a C replacement for myself is prototyped entirely in s-expressions. What else would you
by lelanthran 3y ago
They aren't incompatible.
My own toy language which is intended to be a C replacement for myself is prototyped entirely in s-expressions.
What else would you use to represent a syntax tree?
- muth02446 3y agoAlso with some tweaking you can push s-expr pretty far WRT readability. Here is an example of a cwerg program using "enhanced" s-exprs: https://github.com/robertmuth/Cwerg/blob/master/FrontEnd/TestData/wordcount.cw https://github.com/robertmuth/Cwerg/blob/master/FrontEnd/Tes... And here is same the same program in the tentative concrete syntax: https://github.com/robertmuth/Cwerg/blob/master/FrontEnd/ConcteteSyntax/wordcount.concrete.cw https://github.com/robertmuth/Cwerg/blob/master/FrontEnd/Con...
- lelanthran 3y agoHonestly I'm doing pretty much the same thing; been through several iterations of AST without yet deciding on a syntax, other than "Easy for C Programmers" and "Doesn't look like someone ate alphabet soup and vomited it all over the screen".
- bonki 3y agoI had skimmed through the readme and then went straight to the example folder so missed the fact that this is not supposed to be the final concrete syntax, makes much more sense now!
- bmacho 3y ago> What else would you use to represent a syntax tree? Different syntax for different concepts, easier for the eye, quicker the understanding, troubleshooting.
- kragen 3y agomyself i'm partial to rose trees rather than (set (aref a i) (+ i j)) you have set(aref(a i) +(i j)) and no difference between i and i(), and only one type of node, with a tag and zero or more kids, instead of separate node types for having kids and having tags the rose tree model feels like a slightly closer fit to the needs of abstract syntax trees, and although it isn't simpler than sexps, it isn't more complicated either another possibility is the ml approach where juxtaposition denotes function application but the functions are curried so they only ever take a single argument, which usually looks exactly the same as sexps but conceptually associates the other way set (aref a i) (+ i j) the only difference is that this is equivalent, which i think is worse in this context: set ((aref a) i) ((+ i) j) (note that ml only uses this approach for expressions to evaluate. for data, such as asts, it uses the rose tree approach) regardless, the semantics are a lot more important than the syntax
- hgs3 3y ago> What else would you use to represent a syntax tree? For unit tests I've used pretty-printed JSON. Text editors syntax highlight it plus you can leverage an off-the-shelf JSON library rather than writing your own s-expressions serializer (not that serializers are difficult to write or anything, but just as a convenience).