1package aud.example.graph;
26 boolean verbose_ =
false;
39 public void parse(String input) {
71 throw new RuntimeException(
"unknown token: lexcial analysis failed at '"+
78 protected void expect(
int tokenid,String text) {
80 throw new RuntimeException(
"expected '"+text+
"' got '"+
86 protected void verbose(
int level,String message) {
88 System.err.println(
Sys.
indent(level)+message+
99 protected void graph(
int level) {
116 throw new RuntimeException(
"specified directed edge "+
117 "for undirected graph or vice versa");
150 double[] p=
pos(level+1);
158 protected double[]
pos(
int level) {
180 return new double[] { x,y };
193 double w=Double.parseDouble(scanner_.
matchedText());
204 @SuppressWarnings(
"unchecked")
205 public static
void main(String[] args) {
211 String input=(args.length>0) ?
212 Sys.
readFile(
new File(args[0])) :
"a@(1,1) -- [1] b b -- c c -- a";
214 System.out.println(
"input = '"+input+
"'");
221 System.out.println(g);
222 System.out.println(g.
toDot());
Implementation of an unordered map based on a hash table.
Value insert(Key key, Value value)
insert key-value pair
Value find(Key key)
find value for key @endiliteral
Parse text to build graph.
static void main(String[] args)
test and example for usage
int lookahead()
helper: "lookahead" is the usual phrasing
void nextToken()
helper: consume current token and advance to next token
void expect(int tokenid, String text)
helper: check token (without calling nextToken!)
void parse(String input)
parse input
AbstractNode node(int level)
parse node
void graph(int level)
parse list of nodes/edges
double[] pos(int level)
parse position
void verbose(int level, String message)
helper: print out information
void parse(File file)
parse(String) contents of file
AbstractEdge edge(int level)
parse edge
String errorNear()
helper: generate a simple error message
void setVerbose(boolean b)
set verbose mode (report state to System.err)
GraphParser(AbstractGraph< AbstractNode, AbstractEdge > g)
create new parser for graph g
Double weight(int level)
parse weight
Breaks input string into pieces ("tokens").
static final int IDENTIFIER
static final int LEFT_BRACE
static final int LEFT_PAREN
static final int RIGHT_BRACE
static final int RIGHT_PAREN
Interface to edges of a graph.
void setWeight(double w)
set weight
abstract Edge addEdge(Node source, Node destination)
Create and add new edge from source to destination.
abstract boolean isDirected()
Is graph directed?
abstract Node addNode()
create and add new node
String toDot()
Get dot representation.
Interface to nodes of a graph.
void setPosition(double x, double y)
helper for drawing the graph (if supported)
void setLabel(String label)
set label (if supported)
Graph implementation based on adjacency matrix.
Simple viewer for Graphvizable.
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
void setExitOnClose()
exit application if viewer is closed
static final int END_OF_INPUT
no more input
int next(Rule[] rules)
match remainder to table of rules @endiliteral
int matchedTokenId()
get result of last call to next()
String matchedText()
get text of last match or call to next
String remainder()
get remaining text
static final int NO_MATCH
no match (usually implies a syntax error)
System related utilities.
static String indent(int level)
get indentation string filled with spaces
static String readFile(File file)
read entire file and return contents as String
Graph data structures and algorithms.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.