Skip to Content.
Sympa Menu

gang-of-4-patterns - Re: [gang-of-4-patterns] Visitor: semantic analysis of a syntax tree

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

Re: [gang-of-4-patterns] Visitor: semantic analysis of a syntax tree


Chronological Thread 
  • From: "Robert Allan Schwartz" <notbob AT tessellation.com>
  • To: "Roman Neuhauser" <neuhauser AT chello.cz>, "gang-of-4-patterns" <gang-of-4-patterns AT cs.uiuc.edu>
  • Cc:
  • Subject: Re: [gang-of-4-patterns] Visitor: semantic analysis of a syntax tree
  • Date: Wed, 24 Nov 2004 12:23:37 -0500
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>
  • Organization: Tessellation Training

Parts of the grammar look like this (terminals in caps):

input
:
| input COMMENT
| input stmt
stmt
: macroassign SEMICOLON
| acl SEMICOLON
macroassign
: MACRO EQUALS namelist <<< see below
| MACRO EQUALS permlist
namelist
: WORD
| namelist COMMA WORD
| namelist COMMA MACRO

Now, if I get a Macro node for every MACRO, how does
a MacroCheckingVisitor distinguish between Macros on the left side of
a macroassign, which shouldn't be checked for existence, and Macros in
a namelist (macros need to be defined before being referenced)?

One approach is to have a boolean in the Visitor instance, which is false when checking is not required, and true when checking is required.
Who sets this boolean?
When the Visitor visits the macroassign node, it sets its boolean to false, visits the left hand side, sets its boolean to true, then visits the right hand side.
This boolean "plays the role of" Context in the pattern.

Hope this helps.

Robert





Archive powered by MHonArc 2.6.16.

Top of Page