[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Oops! DAG creation in versions 1.18.1 and 3.0.0-beta



I forgot to attach the Java program and SableCC sepcification files. Sorry
about that. They are attached to this message instead.

-- 
Jon Shapcott <eden@xibalba.demon.co.uk>
"This is the Space Age, and we are Here To Go" - Wlliam S. Burroughs
import analysis.*;
import lexer.*;
import node.*;
import parser.*;
import parser.*;

import java.io.*;
import java.util.*;

public class TestListDAG {

     public static void main ( String[] arguments ) throws Exception {
	StringReader   stringReader   = new StringReader("foo bar baz");
	PushbackReader pushbackReader = new PushbackReader(stringReader);
	Lexer          lexer          = new Lexer(pushbackReader);
	Parser         parser         = new Parser(lexer);
	ANames         originalNode   = (ANames) parser.parse().getPNames();
	ANames         bogusParent    = new ANames();
	printNames(originalNode);
	/* Created an print a directed acyclic graph */
	originalNode.getNames().addFirst(originalNode.getNames().getFirst());
	printNames(originalNode);
	/* Only the first instance of the name is removed from the
	 * original node */
	bogusParent.getNames().add(originalNode.getNames().getFirst());
	/* Get the first name in the original node and its parent */
	Node parent = ( (Node) originalNode.getNames().getFirst() ).parent();
	/* Find out if the parent is correct or bogus */
	if ( parent == originalNode ) {
	    System.out.println("parent == originalNode");
	} else if ( parent == bogusParent ) {
	    System.out.println("parent == bogusParent");

	}
     }


     public static void printNames ( ANames names ) {
	for ( Iterator i = names.getNames().iterator() ; i.hasNext(); ) {
	    System.out.print(identity(i.next()));
	}
	System.out.println();
     }

     public static String identity ( Object object ) {
	String       className  = object.getClass().getName();
	StringBuffer buffer     = new StringBuffer();
	buffer.append(className.substring(className.lastIndexOf('.') + 1));
	buffer.append('@');
	buffer.append(Integer.toHexString(System.identityHashCode(object)));
	buffer.append(':');
	buffer.append(object.toString());
	return buffer.toString();
     }



}
Helpers
	ht    = 0x0009;
	lf    = 0x000a;
	ff    = 0x000c;
	cr    = 0x000d;

	blankspace = [ht + [lf + [ff + [cr + ' ']]]]+;

	name_head = [['a' .. 'z'] + ['A' .. 'Z']];
	name_tail = [name_head + ['0'..'9']];

	name = name_head name_tail*;

Tokens
         blankspace = blankspace;
	name       = name;

Ignored Tokens
	blankspace;

Productions
	names = [names]:name*;