Re: AST must for xlator?

"James Powell" <jamesp_spam_me_not@silver-future.com>
31 May 2002 23:05:43 -0400

          From comp.compilers

Related articles
AST must for xlator? rramsey500NOSPAM@earthlink.net (Russ Ramsey) (2002-05-12)
Re: AST must for xlator? rkrayhawk@aol.com (2002-05-17)
Re: AST must for xlator? jamesp_spam_me_not@silver-future.com (James Powell) (2002-05-31)
| List of all articles for this month |

From: "James Powell" <jamesp_spam_me_not@silver-future.com>
Newsgroups: comp.compilers
Date: 31 May 2002 23:05:43 -0400
Organization: Compilers Central
References: 02-05-057
Keywords: parse, practice
Posted-Date: 31 May 2002 23:05:42 EDT

"Russ Ramsey" <rramsey500NOSPAM@earthlink.net> writes:
> I wrote Lex & Yacc code to parse SAS; now how do I output the
> symbols into COBOL?
> ...
> Any examples out there of the simplest data structure for this purpose?


I have found that using a C library for building linked lists of typed
strings works well for translating output from Lex & Yacc. The %type
of all of your grammatical constructs is of the String type. You
ultimately output the translation by calling PrintString() in your
input production:


input:
        CompilationUnit { PrintString($1); }


CompilationUnit: /* empty */ { $$ = MAKE_EMPTY_STRING(); }
    | TypeDeclaration TypeDeclarations { $$ = OUTPUT($1); APPEND($$, $2); }
;


$1 after the parse contains any number of strings strung into a linked list.
The PrintString function is free to reinterpret the string-of-strings,
making multiple passes over it if necessary, and rewriting parts of it.


Cheers,
    James


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.