Skip to Content.
Sympa Menu

gang-of-4-patterns - [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

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


Chronological Thread 
  • From: Roman Neuhauser <neuhauser AT chello.cz>
  • To: gang-of-4-patterns <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: [gang-of-4-patterns] Visitor: semantic analysis of a syntax tree
  • Date: Wed, 24 Nov 2004 15:16:19 +0100
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Hi there,

I'm writing a configuration file parser (as a fun/learning project), and
I thought I'd use Visitor to check different aspects of the parsed
syntax tree, but ran into a block.

Example config file:

# macro definitions
@repoadm = roman, root, karl;
@stdperm = data(add, update, delete), prop(svn:log);
@allperm = data(*), prop(*);
@users = roman, karl, gilhad, cenda, berus;

# ACLs
.+ = @users(@stdperm);
trunk/.+ = @repoadm(@allperm);
trunk/svnroot/.+ = @ANY(), @repoadm(@stdperm);
private/.* = @repoadm(data(add, update, delete), prop(svn:log));

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

input
:
| input COMMENT
| input stmt
stmt
: macroassign SEMICOLON
| acl SEMICOLON
macroassign
: MACRO EQUALS namelist
| 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)?

My confusion most probably originates in a sore lack of knowledge in the
compiler design field, and I even expect an answer like "the grammar is
flawed". In any case, if you see flaws in any part of the logic
presented above, I'd like to hear from you (perhaps in private email if
it's not DP related).

Thanks in advance,
Roman Neuhauser





Archive powered by MHonArc 2.6.16.

Top of Page