Re: Dragon Book question

cgbatema@undergrad.math.uwaterloo.ca (Cameron Bateman)
1 Apr 2000 14:07:50 -0500

          From comp.compilers

Related articles
Compiler project needed pel@realtime.dk (Per Olesen) (2000-02-22)
Dragon Book question lojedaortiz@interlink.com.ar (Nicolás) (2000-03-23)
Re: Dragon Book question rkrayhawk@aol.com (2000-03-23)
Re: Dragon Book question thp@roam-thp2.cs.ucr.edu (Tom Payne) (2000-03-23)
Re: Dragon Book question cgbatema@undergrad.math.uwaterloo.ca (2000-04-01)
| List of all articles for this month |

From: cgbatema@undergrad.math.uwaterloo.ca (Cameron Bateman)
Newsgroups: comp.compilers
Date: 1 Apr 2000 14:07:50 -0500
Organization: University of Waterloo
References: 00-02-112 00-03-095
Keywords: books

<snip>


>using syntax-directed diagrams (ie after this rule is reduced, the
>
>Can I assume that the actions can be "executed" in a postorder traversal
>of the parse tree, instead that when I am actually parsing the source




The shorter answer is "yes". The longer answer is that depending on
the size and complexity of the language you are compiling and the
goals you hope achieve with your compiler (i.e fast code, good error
reporting/recovering, fast compiler) one method might be better than
another.


In general, direct syntax-reduce driven parsing is less rigourous and
for large projects can result in "great big hacks". However, if you
are writing your first compiler or just want to write a quick little
tool, the syntax directed method is simpler, more comprehensible to
the novice and is moreover encouraged by many YACC-like tools which
allow you to execute fragments of C code on each reduction with
operations on real parse-stack objects.


Usually, if you are going to the trouble of constructing a parse tree
in memory, and the necessary tree-walk algorithm to analyze it, it is
because you want to exploit the ability to have things like inherited
attributes or multiple passes without a reparse. Keep in mind though
that there is resulting overhead incurred in doing so, which may or
may not be worth your time if you problem is small.




Regards,


Cam
--
/ Cameron Bateman She is eternal, long before \
/ 4B MATH/CS Nation's lines were drawn, \
/ University of Waterloo When no flags flew, \


Post a followup to this message

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