This is a case where I have to ask "why". The typical Lisp compiler (not interpreter) is a Lisp to C translator with some additional glue. You can probably even find support for translating CLOS to C++ if you look around.
--Loring > >From: Richard Lewis <[email protected]> >To: [email protected] >Sent: Sunday, September 27, 2009 6:32:19 PM >Subject: [antlr-interest] Parsing Lisp into C++ > > > > > >> >I've started looking into translating a large amount of >legacy Lisp code into C++ using Antlr. I put together a simple grammar that >generates an AST. My question is: Where is the best place to attach semantic >information? >It seems to me that I should have a 2 pass parser, starting with the AST as >shown below and then making an additional pass to generate another AST >that contains semantics. Unfortunately I'm not that familiar with Lisp but it >seems to be difficult to parse in a single pass without resorting to an ugly >grammar definition since everything in Lisp seems to be an expression of some >sort. This is ironic since Lisp already seems to be "parsed". > >Input: > >(defun foo (x y) (progn (+ x 1) (+ y 1))) > >Grammar: > >program: (sexpr)* -> ^(PROGRAM sexpr*); >sexpr: QT?(list|atom) ; >list: '(' ')' | >'(' members ')' -> ^(LIST members); >members: (sexpr)+; >atom: OPERATOR | ID | num | STRING ; >num : (n=INT|n=FLOAT) >-> ^(NUM $n); > >AST Output: > >PROGRAM > LIST > defun > foo > LIST > x > y > LIST > progn > LIST > + > x > 1 > LIST > + > y > 1 > >Desired Output: > >PROGRAM > FUNCTION > foo > ARGS > x > y > BLOCK > + > x > 1 > + > > y > 1 > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
