Re: AST must for xlator?

"James Powell" <>
31 May 2002 23:05:43 -0400

          From comp.compilers

Related articles
AST must for xlator? (Russ Ramsey) (2002-05-12)
Re: AST must for xlator? (2002-05-17)
Re: AST must for xlator? (James Powell) (2002-05-31)
| List of all articles for this month |

From: "James Powell" <>
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" <> 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:

        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.


Post a followup to this message

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