...
 
Commits (3)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/usr/share/ant/lib/ant.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CUP</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<project name="emugen" default ="dist" basedir=".">
<project name="cup" default ="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="etc" location="etc" />
<property name="bin" location="bin" />
<property name="lib" location="lib" />
......@@ -13,10 +13,34 @@
<!-- initialize the workspace -->
<target name="init">
<tstamp />
<available file="version.txt" property="version.present" />
<touch unless:set="version.present" file="version.txt" />
<mkdir dir="${src}" />
<mkdir dir="${java}" />
<mkdir dir="${classes}" />
<mkdir dir="${dist}" />
<mkdir dir="${dist}" />
<loadfile property="cupversion" srcFile="version.txt" failonerror="false" />
<property name="cupversion" value="custombuild" unless:set="cupversion"/>
<exec executable="git" outputproperty="gitversion">
<arg value="log"/>
<arg value="-1"/>
<arg value="--format=%h"/>
</exec>
<exec executable="git" outputproperty="changed">
<arg value="status"/>
<arg value="--porcelain"/>
<redirector>
<outputfilterchain>
<linecontainsregexp>
<regexp pattern='^M.*'/>
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern=".*" replace="modifications based on "/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<property name="svnversion">${changed}${gitversion}</property>
</target>
<property environment="env" />
......@@ -53,27 +77,82 @@
<target name="compile" depends="jflex">
<copy todir="${java}"><fileset dir="${src}"></fileset></copy>
<javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.2" target="1.2">
<replace file="${java}/java_cup/version.java"
token="+ version_str"
value='+ "v0.11b ${cupversion} (GIT ${svnversion})"'>
</replace>
<javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.8" target="1.8">
<classpath refid="libraries"/>
</javac>
</target>
<target name="dist" depends="compile">
<jar jarfile="${dist}/java-cup-11a.jar" basedir="${classes}">
<jar jarfile="${dist}/java-cup-11b.jar" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="java_cup/Main" />
<attribute name="Class-Path" value="java-cup-11a-runtime.jar" />
<attribute name="Class-Path" value="java-cup-11b-runtime.jar" />
</manifest>
</jar>
<jar jarfile="${dist}/java-cup-11a-runtime.jar" basedir="${classes}" includes="java_cup/runtime/*">
<jar jarfile="${dist}/java-cup-11b-runtime.jar" basedir="${classes}" includes="java_cup/runtime/*">
</jar>
<tar longfile="gnu" destfile="${dist}/java-cup-bin-11b-${cupversion}.tar.gz" compression="gzip">
<tarfileset dir="${dist}" username="ant" group="ant">
<depth max="0"/>
<include name="*.jar"/>
</tarfileset>
</tar>
</target>
<target name="src-dist" depends="dist">
<tar longfile="gnu" destfile="${dist}/java-cup-src-11b-${cupversion}.tar.gz" compression="gzip">
<tarfileset dir="${src}" username="ant" group="ant" prefix="src/">
<include name="**"/>
</tarfileset>
<tarfileset dir="${cup}" username="ant" group="ant" prefix="cup/">
<include name="**"/>
</tarfileset>
<tarfileset dir="${flex}" username="ant" group="ant" prefix="flex/">
<include name="**"/>
</tarfileset>
<tarfileset dir="${bin}" username="ant" group="ant" prefix="bin/">
<include name="**"/>
</tarfileset>
<tarfileset dir="${lib}" username="ant" group="ant" prefix="lib/">
<include name="**"/>
</tarfileset>
<tarfileset dir="${src}/.." username="ant" group="ant">
<depth max="0"/>
<include name="*"/>
</tarfileset>
</tar>
</target>
<target name="test" depends="dist">
<java jar="${dist}/java-cup-11a.jar" fork="true">
<java jar="${dist}/java-cup-11b.jar" fork="true">
<arg value="-interface" />
<arg value="${cup}/parser.cup" />
</java>
</target>
<target name="versionbump" depends="init">
<echo message="${DSTAMP}" file="version.txt" />
</target>
<target name="scp" depends="src-dist">
<exec executable="scp">
<arg value="${dist}/java-cup-src-11b-${cupversion}.tar.gz" />
<arg value="${dist}/java-cup-bin-11b-${cupversion}.tar.gz" />
<arg value="${dist}/../manual.html" />
<arg value="petter@www2.in.tum.de:/srv/www/htdocs/projects/cup/releases" />
</exec>
</target>
<target name="help" depends="init">
<echo message="Targets:" />
<echo message=" dist to create CUP jars" />
<echo message=" src-dist to create release packages" />
<echo message=" scp to deploy relase to homepage" />
<echo message=" versionbump to inc release" />
</target>
</project>
CUP version 0.11b 20151001 is a feature release.
Implemented a generic pre-/post DFS search with visitor support
Also added fragments of XPath 1.0 query support on parse trees
Fixed the visibility of children and the variant attribute of XMLElement
M. Petter
Technische Universität München
2015/10/01
------------------------------------------------------------------------
CUP version 0.11b 20150326 is a bugfix release.
Fixed an issue with empty productions having non-empty location information
Fixed an issue with deprecation of constructors
M. Petter
Technische Universität München
2015/02/26
------------------------------------------------------------------------
CUP version 0.11b 20150226 is a feature release.
added the means to move Locations
M. Petter
Technische Universität München
2015/02/26
------------------------------------------------------------------------
CUP version 0.11b 20140808 is a feature/bugfix release.
added expected symbols to the report_error(...) method
added an expected_token_ids() to inform about valid continuations
added parameters and code to enable automatic creation of XML parse trees
fixed a bug in the lookahead computation
M. Petter
Technische Universität München
2014/02/26
------------------------------------------------------------------------
CUP version 0.11b beta 20140226 is a feature release.
Command line flag -locations now triggers the generation of the identifiers
xleft and xright in the actions section instead of left and right.
Both are of type ComplexSymbolFactory.Location instead of plain ints.
M. Petter
Technische Universität München
2014/02/26
------------------------------------------------------------------------
CUP version 0.11b beta 20140220 is a feature release.
Main switch statement now splits the action code in bundles of 300 productions
on several different method bodies. Should fix the 65k size boundary problem
M. Petter
Technische Universität München
2014/02/20
------------------------------------------------------------------------
CUP version 0.11a beta 20060608 is a bugfix release.
......
......@@ -185,14 +185,28 @@ action code {:
}
}
}
private int cur_debug_id = 0;
public int get_new_debug_id() {
return cur_debug_id++;
}
public String attach_debug_symbol(int id, String code) {
if (!parser.debugSymbols)
return code;
return "//@@CUPDBG" + id + "\n" + code;
}
:};
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
parser code {:
/* override error routines */
protected Lexer lexer;
public boolean debugSymbols;
public void setDebugSymbols(boolean debugSymbols){
this.debugSymbols = debugSymbols;
}
public void report_fatal_error(
String message,
Object info)
......@@ -230,7 +244,7 @@ terminal
PACKAGE, IMPORT, CODE, ACTION, PARSER, TERMINAL, NON, INIT, SCAN, WITH,
START, SEMI, COMMA, STAR, DOT, COLON, COLON_COLON_EQUALS, BAR, PRECEDENCE,
LEFT, RIGHT, NONASSOC, PERCENT_PREC, LBRACK, RBRACK, NONTERMINAL, GT, LT,
QUESTION, SUPER, EXTENDS;
QUESTION, SUPER, EXTENDS, CLASS;
terminal String ID, CODE_STRING;
......@@ -242,7 +256,7 @@ non terminal
type_id, term_name_list, non_term_name_list, production, prod_part_list,
prod_part, new_term_id, new_non_term_id, rhs_list, rhs, empty,
precedence_list, preced, terminal_list, precedence_l, declares_term,
declares_non_term;
declares_non_term, class_name;
non terminal String nt_id, symbol_id, label_id, opt_label, terminal_id,
term_id, robust_id, typearglist, typearguement, wildcard;
......@@ -263,6 +277,7 @@ spec ::=
:}
package_spec
import_list
class_name
code_parts
symbol_list
precedence_list
......@@ -322,6 +337,15 @@ import_spec ::=
SEMI
;
class_name ::=
empty |
CLASS ID:id SEMI
{:
emit.parser_class_name = id;
emit.symbol_const_class_name = id + "Sym";
:}
;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
// allow any order; all parts are optional. [CSA, 23-Jul-1999]
......@@ -339,7 +363,7 @@ action_code_part ::=
if (emit.action_code!=null)
ErrorManager.getManager().emit_warning("Redundant action code (skipping)");
else /* save the user included code string */
emit.action_code = user_code;
emit.action_code = attach_debug_symbol(get_new_debug_id(),user_code);
:}
;
......@@ -351,7 +375,7 @@ parser_code_part ::=
if (emit.parser_code!=null)
ErrorManager.getManager().emit_warning("Redundant parser code (skipping)");
else /* save the user included code string */
emit.parser_code = user_code;
emit.parser_code = attach_debug_symbol(get_new_debug_id(),user_code);
:}
;
......@@ -363,7 +387,7 @@ init_code ::=
if (emit.init_code!=null)
ErrorManager.getManager().emit_warning("Redundant init code (skipping)");
else /* save the user code */
emit.init_code = user_code;
emit.init_code = attach_debug_symbol(get_new_debug_id(),user_code);
:}
;
......@@ -375,7 +399,7 @@ scan_code ::=
if (emit.scan_code!=null)
ErrorManager.getManager().emit_warning("Redundant scan code (skipping)");
else /* save the user code */
emit.scan_code = user_code;
emit.scan_code = attach_debug_symbol(get_new_debug_id(),user_code);
:}
;
......@@ -534,7 +558,7 @@ start_spec ::=
new_rhs();
add_rhs_part(add_lab(new symbol_part(start_nt), "start_val"));
add_rhs_part(new symbol_part(terminal.EOF));
add_rhs_part(new action_part("RESULT = start_val;"));
if (!emit._xmlactions) add_rhs_part(new action_part("RESULT = start_val;"));
emit.start_production =
new production(non_terminal.START_nt, rhs_parts, rhs_pos);
new_rhs();
......@@ -621,7 +645,7 @@ rhs ::=
new_rhs();
add_rhs_part(add_lab(new symbol_part(start_nt),"start_val"));
add_rhs_part(new symbol_part(terminal.EOF));
add_rhs_part(new action_part("RESULT = start_val;"));
if (!emit._xmlactions) add_rhs_part(new action_part("RESULT = start_val;"));
if ((sym!=null) && (sym instanceof terminal)) {
emit.start_production =
new production(non_terminal.START_nt, rhs_parts,
......@@ -657,7 +681,7 @@ rhs ::=
new_rhs();
add_rhs_part(add_lab(new symbol_part(start_nt),"start_val"));
add_rhs_part(new symbol_part(terminal.EOF));
add_rhs_part(new action_part("RESULT = start_val;"));
if (!emit._xmlactions) add_rhs_part(new action_part("RESULT = start_val;"));
emit.start_production =
new production(non_terminal.START_nt, rhs_parts, rhs_pos);
......@@ -699,7 +723,7 @@ prod_part ::=
CODE_STRING:code_str
{:
/* add a new production part */
add_rhs_part(new action_part(code_str));
add_rhs_part(new action_part(attach_debug_symbol(get_new_debug_id(),code_str)));
:}
;
......
#! /bin/sh
#!/bin/sh
CLASSPATH="$CLASSPATH:/usr/share/java/cup.jar"
export CLASSPATH
......
cup (0.11b-20160615-1) unstable; urgency=medium
* Team upload.
* New upstream version 0.11b-20160615.
* Switch to compat level 11.
* Change all versions to 0.11b.
* Convert debian/copyright to copyright format 1.0.
* Update build.patch for new release.
* Declare compliance with Debian Policy 4.2.1.
* Depend on java8-runtime-headless
-- Markus Koschany <apo@debian.org> Sun, 30 Sep 2018 23:30:46 +0200
cup (0.11a+20060608-8) unstable; urgency=medium
* Team upload.
......
......@@ -7,11 +7,11 @@ Uploaders:
Build-Depends:
ant,
cup (>= 0.11a),
debhelper (>= 9),
debhelper (>= 11),
default-jdk,
jflex (>= 1.6.1),
maven-repo-helper
Standards-Version: 3.9.8
Standards-Version: 4.2.1
Vcs-Git: https://anonscm.debian.org/git/pkg-java/cup.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/cup.git
Homepage: http://www2.cs.tum.edu/projects/cup/
......@@ -19,7 +19,7 @@ Homepage: http://www2.cs.tum.edu/projects/cup/
Package: cup
Architecture: all
Depends:
default-jre-headless | java1-runtime-headless | java2-runtime-headless,
default-jre-headless | java8-runtime-headless,
${misc:Depends}
Suggests:
java-compiler
......
This is the Debian GNU/Linux prepackaged version of CUP, a
parser generator for Java. It was debianized by Vincent Renardias
<vincent@waw.com> on Sun, 2 Feb 1997 07:03:45 +0100.
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: CUP
Source: http://www2.cs.tum.edu/projects/cup/
Files-Excluded:
*.jar
It was downloaded from the CUP web page at
<URL:http://www.cs.princeton.edu/~appel/modern/java/CUP/>.
CUP PARSER GENERATOR COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
Copyright 1996 by Scott Hudson, Frank Flannery, C. Scott Ananian
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and
that both the copyright notice and this permission notice and warranty
disclaimer appear in supporting documentation, and that the names of
the authors or their employers not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
The authors and their employers disclaim all warranties with regard to
this software, including all implied warranties of merchantability and
fitness. In no event shall the authors or their employers be liable
for any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether in an
action of contract, negligence or other tortious action, arising out
of or in connection with the use or performance of this software.
Files: *
Copyright: 1996-2015 by Scott Hudson, Frank Flannery, C. Scott Ananian, Michael Petter
License: CUP-License
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided that
the above copyright notice appear in all copies and that both the copyright
notice and this permission notice and warranty disclaimer appear in supporting
documentation, and that the names of the authors or their employers not be used
in advertising or publicity pertaining to distribution of the software without
specific, written prior permission.
.
The authors and their employers disclaim all warranties with regard to this
software, including all implied warranties of merchantability and fitness. In
no event shall the authors or their employers be liable for any special,
indirect or consequential damages or any damages whatsoever resulting from loss
of use, data or profits, whether in an action of contract, negligence or other
tortious action, arising out of or in connection with the use or performance of
this software. This is an open source license. It is also GPL-Compatible (see
entry for "Standard ML of New Jersey"). The portions of CUP output which are
hard-coded into the CUP source code are (naturally) covered by this same
license, as is the CUP runtime code linked with the generated parser.
.
Java is a trademark of Sun Microsystems, Inc. References to the Java
programming language in relation to JLex are not meant to imply that Sun
endorses this product.
dist/java-cup-0.11a.jar usr/share/java
debian/bin/cup usr/bin
dist/java-cup-0.11b.jar usr/share/java
dist/java-cup-11b-runtime.jar usr/share/java
debian/bin/cup usr/bin
/usr/share/java/java-cup-0.11a.jar /usr/share/java/cup.jar
/usr/share/java/java-cup-0.11a.jar /usr/share/maven-repo/net/sf/squirrel-sql/thirdparty-non-maven/java-cup/0.11a/java-cup-0.11a.jar
/usr/share/java/java-cup-0.11b.jar /usr/share/java/cup.jar
/usr/share/java/java-cup-0.11b.jar /usr/share/maven-repo/net/sf/squirrel-sql/thirdparty-non-maven/java-cup/0.11b/java-cup-0.11b.jar
debian/pom.xml --usj-name=cup --usj-version=0.11a --artifact=dist/java-cup-0.11a.jar
debian/pom.xml --usj-name=cup --usj-version=0.11b --artifact=dist/java-cup-0.11b.jar
From: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
Date: Wed, 27 Jul 2016 12:05:26 +0200
Subject: build
===================================================================
---
build.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build.xml b/build.xml
index 705edd6..ae8138c 100644
--- a/build.xml
+++ b/build.xml
@@ -53,7 +53,7 @@
<target name="compile" depends="jflex">
<copy todir="${java}"><fileset dir="${src}"></fileset></copy>
- <javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.2" target="1.2">
+ <javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.3" target="1.3">
<classpath refid="libraries"/>
</javac>
</target>
From: Markus Koschany <apo@debian.org>
Date: Sun, 30 Sep 2018 21:42:15 +0200
Subject: build
---
build.xml | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/build.xml b/build.xml
index 91bd60c..d464a96 100644
--- a/build.xml
+++ b/build.xml
@@ -21,26 +21,6 @@
<mkdir dir="${dist}" />
<loadfile property="cupversion" srcFile="version.txt" failonerror="false" />
<property name="cupversion" value="custombuild" unless:set="cupversion"/>
- <exec executable="git" outputproperty="gitversion">
- <arg value="log"/>
- <arg value="-1"/>
- <arg value="--format=%h"/>
- </exec>
- <exec executable="git" outputproperty="changed">
- <arg value="status"/>
- <arg value="--porcelain"/>
- <redirector>
- <outputfilterchain>
- <linecontainsregexp>
- <regexp pattern='^M.*'/>
- </linecontainsregexp>
- <tokenfilter>
- <replaceregex pattern=".*" replace="modifications based on "/>
- </tokenfilter>
- </outputfilterchain>
- </redirector>
- </exec>
- <property name="svnversion">${changed}${gitversion}</property>
</target>
<property environment="env" />
@@ -79,7 +59,7 @@
<copy todir="${java}"><fileset dir="${src}"></fileset></copy>
<replace file="${java}/java_cup/version.java"
token="+ version_str"
- value='+ "v0.11b ${cupversion} (GIT ${svnversion})"'>
+ value='+ "v0.11b ${cupversion}"'>
</replace>
<javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.8" target="1.8">
<classpath refid="libraries"/>
Description: Fixes the compatibility with the version of JFlex in Debian
Author: Markus Koschany <apo@debian.org>, Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
From: Markus Koschany <apo@debian.org>
Date: Mon, 1 Oct 2018 00:02:28 +0200
Subject: jflex 1.6.1
Fixes the compatibility with the version of JFlex in Debian
---
build.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build.xml b/build.xml
index d464a96..d3dba25 100644
--- a/build.xml
+++ b/build.xml
@@ -41,14 +41,14 @@
@@ -45,14 +45,14 @@
</target>
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${bin}/java-cup-11.jar" />
......@@ -16,7 +24,7 @@ Forwarded: no
<target name="jflex" depends="cup">
- <jflex file="${flex}/Lexer.jflex" destdir="${java}" />
+ <jflex file="${flex}/Lexer.jflex" destdir="${java}" legacydot="on"/>
+ <jflex file="${flex}/Lexer.jflex" destdir="${java}" legacydot="on" />
</target>
<target name="compile" depends="jflex">
build.diff
build.patch
jflex-1.6.1.patch
......@@ -3,7 +3,7 @@
<groupId>net.sf.squirrel-sql.thirdparty-non-maven</groupId>
<artifactId>java-cup</artifactId>
<name>Java CUP Parser Generator</name>
<version>0.11a</version>
<version>0.11b</version>
<description>
CUP is a system for generating LALR parsers from simple specifications. It serves the same role as
the widely used program YACC [1] and in fact offers most of the features of YACC. However, CUP is
......
......@@ -3,14 +3,16 @@ export JAVA_HOME=/usr/lib/jvm/default-java
export CLASSPATH=/usr/share/java/cup.jar:/usr/share/java/jflex.jar
%:
dh $@ --parallel --with maven-repo-helper --buildsystem=ant
dh $@ --with maven-repo-helper --buildsystem=ant
override_dh_install:
mv dist/java-cup-11a.jar dist/java-cup-0.11a.jar
if [ -f $(CURDIR)/dist/java-cup-11b.jar ]; then \
mv dist/java-cup-11b.jar dist/java-cup-0.11b.jar; \
fi
dh_install
override_dh_clean:
dh_clean
mh_clean
$(RM) dist/java-cup-0.11a.jar
$(RM) dist/java-cup-0.11b.jar
......@@ -23,11 +23,9 @@ import java.io.InputStreamReader;
private ComplexSymbolFactory symbolFactory;
private int csline,cscolumn;
public Symbol symbol(String name, int code){
// System.out.println("code:"+code+" "+yytext());
return symbolFactory.newSymbol(name, code,new Location(yyline+1,yycolumn+1-yylength()),new Location(yyline+1,yycolumn+1));
}
public Symbol symbol(String name, int code, String lexem){
// System.out.println("code:"+code+", lexem :"+lexem);
return symbolFactory.newSymbol(name, code, new Location(yyline+1, yycolumn +1), new Location(yyline+1,yycolumn+yylength()), lexem);
}
protected void emit_warning(String message){
......@@ -78,6 +76,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
"{:" { sb = new StringBuffer(); csline=yyline+1; cscolumn=yycolumn+1; yybegin(CODESEG); }
"package" { return symbol("PACKAGE",PACKAGE); }
"import" { return symbol("IMPORT",IMPORT); }
"class" { return symbol("CLASS",CLASS); }
"code" { return symbol("CODE",CODE); }
"action" { return symbol("ACTION",ACTION); }
"parser" { return symbol("PARSER",PARSER); }
......
CUP Parser Generator Copyright Notice, License, and Disclaimer
Copyright 1996-2015 by Scott Hudson, Frank Flannery, C. Scott Ananian, Michael Petter
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the names of the authors or their employers not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.
The authors and their employers disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the authors or their employers be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software.
This is an open source license. It is also GPL-Compatible (see entry for "Standard ML of New Jersey"). The portions of CUP output which are hard-coded into the CUP source code are (naturally) covered by this same license, as is the CUP runtime code linked with the generated parser.
Java is a trademark of Sun Microsystems, Inc. References to the Java programming language in relation to JLex are not meant to imply that Sun endorses this product.
This diff is collapsed.
......@@ -54,6 +54,8 @@ import java_cup.runtime.*;
* <dd> turn on debugging messages within JavaCup
* <dt> -nopositions
* <dd> don't generate the positions code
* <dt> -locations
* <dd> generate handles xleft/xright for symbol positions in actions
* <dt> -noscanner
* <dd> don't refer to java_cup.runtime.Scanner in the parser
* (for compatibility with old runtimes)
......@@ -89,6 +91,8 @@ public class Main {
protected static boolean opt_show_timing = false;
/** User option -- do we run produce extra debugging messages */
protected static boolean opt_do_debug = false;
/** User option -- do eclipse debug symbols */
protected static boolean opt_do_debugsymbols = false;
/** User option -- do we compact tables by making most common reduce the
default action */
protected static boolean opt_compact_red = false;
......@@ -103,7 +107,10 @@ public class Main {
/* frankf added this 6/18/96 */
/** User option -- should generator generate code for left/right values? */
protected static boolean lr_values = true;
protected static boolean locations = false;
protected static boolean xmlactions = false;
protected static boolean genericlabels = false;
/** User option -- should symbols be put in a class or an interface? [CSA]*/
protected static boolean sym_interface = false;
......@@ -173,7 +180,10 @@ public class Main {
/* frankf 6/18/96
hackish, yes, but works */
emit.set_lr_values(lr_values);
/* open output files */
emit.set_locations(locations);
emit.set_xmlactions(xmlactions);
emit.set_genericlabels(genericlabels);
/* open output set_xmlactionsfiles */
if (print_progress) System.err.println("Opening files...");
/* use a buffered version of standard input */
input_file = new BufferedInputStream(System.in);
......@@ -248,6 +258,7 @@ public class Main {
System.err.println(message);
System.err.println();
System.err.println(
version.title_str + "\n" +
"Usage: " + version.program_name + " [options] [filename]\n" +
" and expects a specification file on standard input if no filename is given.\n" +
" Legal options include:\n" +
......@@ -263,6 +274,9 @@ public class Main {
" -nowarn don't warn about useless productions, etc.\n" +
" -nosummary don't print the usual summary of parse states, etc.\n" +
" -nopositions don't propagate the left and right token position values\n" +
" -locations generate handles xleft/xright for symbol positions in actions\n" +
" -xmlactions make the generated parser yield its parse tree as XML\n" +
" -genericlabels automatically generate labels to all symbols in XML mode\n" +
" -noscanner don't refer to java_cup.runtime.Scanner\n" +
" -progress print messages to indicate progress of the system\n" +
" -time print time usage summary\n" +
......@@ -358,8 +372,12 @@ public class Main {
opt_dump_states = opt_dump_tables = opt_dump_grammar = true;
else if (argv[i].equals("-time")) opt_show_timing = true;
else if (argv[i].equals("-debug")) opt_do_debug = true;
else if (argv[i].equals("-debugsymbols")) opt_do_debugsymbols = true;
/* frankf 6/18/96 */
else if (argv[i].equals("-nopositions")) lr_values = false;
else if (argv[i].equals("-locations")) locations = true;
else if (argv[i].equals("-xmlactions")) xmlactions = true;
else if (argv[i].equals("-genericlabels")) genericlabels = true;
/* CSA 12/21/97 */
else if (argv[i].equals("-interface")) sym_interface = true;
/* CSA 23-Jul-1999 */
......@@ -470,6 +488,7 @@ public class Main {
/* create a parser and parse with it */
ComplexSymbolFactory csf = new ComplexSymbolFactory();
parser_obj = new parser(new Lexer(csf),csf);
parser_obj.setDebugSymbols(opt_do_debugsymbols);
try {
if (opt_do_debug)
parser_obj.debug_parse();
......@@ -696,7 +715,7 @@ public class Main {
System.err.println(
"---------------------------------------------------- (" +
version.version_str + ")");
version.title_str + ")");
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
......
......@@ -55,7 +55,11 @@ public class CUPTask extends Task
private boolean dump=false;
private boolean time=false;
private boolean debug=false;
private boolean debugsymbols=false;
private boolean nopositions=false;
private boolean xmlactions=false;
private boolean genericlabels=false;
private boolean locations=true;
private boolean noscanner=false;
private boolean force=false;
private boolean quiet=false;
......@@ -88,7 +92,11 @@ public class CUPTask extends Task
if (dump) { sc.add("-dump"); }
if (time) { sc.add("-time"); }
if (debug) { sc.add("-debug"); }
if (debugsymbols) { sc.add("-debugsymbols"); }
if (nopositions) { sc.add("-nopositions"); }
if (locations) { sc.add("-locations"); }
if (genericlabels) { sc.add("-genericlabels"); }
if (xmlactions) { sc.add("-xmlactions"); }
if (noscanner) { sc.add("-noscanner"); }
if (!quiet) log ("This is "+version.title_str);
if (!quiet) log ("Authors : "+version.author_str);
......@@ -159,23 +167,6 @@ public class CUPTask extends Task
log("CUP error occured int CUP task: "+e);
}
// this is a dirty hack to determine the apropriate class path
// URL url = CUPTask.class.getResource("/java_cup/Main.class");
// String path = url.getPath().substring(0,url.getPath().length()-20);
// // if called from a .jar or .zip remove the last "!"
// if (path.endsWith("!")) path=path.substring(0,path.length()-1);
// createClasspath().setPath(path);
//
// setFailonerror(true);
// setFork(true);
//
// here, we prepare for calling CUP
// setClassname("java_cup.Main");
// let's call CUP
// super.execute();
}
/**
......@@ -560,8 +551,26 @@ public class CUPTask extends Task
public void setDebug(boolean argDebug){
this.debug = argDebug;
}
/**
* Gets the value of debug
*
* @return the value of debug
*/
public boolean isDebugSymbols() {
return this.debugsymbols;
}
/**
* Sets the value of debug
*
* @param argDebug Value to assign to this.debug
*/
public void setDebugSymbols(boolean argDebug){
this.debugsymbols = argDebug;
}
/**
* Gets the value of nopositions
*
* @return the value of nopositions
......@@ -578,6 +587,23 @@ public class CUPTask extends Task
public void setNopositions(boolean argNopositions){
this.nopositions = argNopositions;
}
/**
* Gets the value of locations
*
* @return the value of locations
*/
public boolean isLocations() {
return this.locations;
}
/**
* Sets the value of locations
*
* @param argLocations Value to assign to this.locations
*/
public void setLocations(boolean argLocations){
this.locations = argLocations;
}
/**
* Gets the value of noscanner
......@@ -597,6 +623,22 @@ public class CUPTask extends Task
this.noscanner = argNoscanner;
}
public boolean isXmlactions() {
return xmlactions;
}
public void setXmlactions(boolean xmlactions) {
this.xmlactions = xmlactions;
}
public boolean isGenericlabels() {
return genericlabels;
}
public void setGenericlabels(boolean genericlabels) {
this.genericlabels = genericlabels;
}
}
......
This diff is collapsed.
......@@ -747,9 +747,10 @@ public class lalr_state {
}
}
/* report S/R conflicts under all the symbols we conflict under */
terminal_set lookahead = itm.lookahead();
for (int t = 0; t < terminal.number(); t++)
if (conflict_set.contains(t))
report_shift_reduce(itm,t);
if (conflict_set.contains(t) && lookahead.contains(t))
report_shift_reduce(itm,t);
}
}
}
......@@ -808,6 +809,7 @@ public class lalr_state {
String message = "*** Shift/Reduce conflict found in state #"+index()+"\n" +
" between " + red_itm.to_simple_string()+"\n";
int relevancecounter = 0;
/* find and report on all items that shift under our conflict symbol */
for (Enumeration itms = items().all(); itms.hasMoreElements(); )
{
......@@ -816,10 +818,12 @@ public class lalr_state {
/* only look if its not the same item and not a reduce */
if (itm != red_itm && !itm.dot_at_end())
{
/* is it a shift on our conflicting terminal */
shift_sym = itm.symbol_after_dot();
if (!shift_sym.is_non_term() && shift_sym.index() == conflict_sym)
{
relevancecounter++;
/* yes, report on it */
message += " and " + itm.to_simple_string()+"\n";
}
......@@ -827,7 +831,7 @@ public class lalr_state {
}
message += " under symbol "+ terminal.find(conflict_sym).name() + "\n"+
" Resolved in favor of shifting.\n";
if (relevancecounter==0) return;
/* count the conflict */
emit.num_conflicts++;
ErrorManager.getManager().emit_warning(message);
......
......@@ -395,7 +395,8 @@ public class production {
String ret;
/* Put in the left/right value labels */
if (emit.lr_values())
if (emit.lr_values()){
if (!emit.locations())
ret = "\t\tint " + labelname + "left = ((java_cup.runtime.Symbol)" +
emit.pre("stack") +
// TUM 20050917
......@@ -406,6 +407,17 @@ public class production {
// TUM 20050917
((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+
").right;\n";
else
ret = "\t\tLocation " + labelname + "xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)" +
emit.pre("stack") +
// TUM 20050917
((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+
").xleft;\n" +
"\t\tLocation " + labelname + "xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)" +
emit.pre("stack") +
// TUM 20050917
((offset==0)?".peek()":(".elementAt(" + emit.pre("top") + "-" + offset + ")"))+
").xright;\n";}
else ret = "";
/* otherwise, just declare label. */
......@@ -441,12 +453,13 @@ public class production {
if (!rhs[pos].is_action())
{
part = (symbol_part)rhs[pos];
String label;
/* if it has a label, make declaration! */
if (part.label() != null)
if ((label=part.label()) != null || emit._xmlactions)
{
if (label==null) label=part.the_symbol().name()+pos;
declaration = declaration +
make_declaration(part.label(), part.the_symbol().stack_type(),
make_declaration(label, part.the_symbol().stack_type(),
rhs_len-pos-1);
}
}
......
package java_cup.runtime;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* Default Implementation for SymbolFactory, creates
* plain old Symbols
......@@ -10,41 +13,143 @@ package java_cup.runtime;
/* *************************************************
class DefaultSymbolFactory
interface for creating new symbols
***************************************************/
public class ComplexSymbolFactory implements SymbolFactory{
public static class Location {
private String unit="unknown";
private int line, column;
private int line, column, offset=-1;
/**
* Copy Constructor for other ComplexSymbolFactory based Locations
* @param other
*/
public Location(Location other){
this(other.unit,other.line,other.column,other.offset);
}
/**
* Location Object
* stores compilation unit, line, column and offset to the file start
* @param unit compilation unit, e.g. file name
* @param line line number
* @param column column number
* @param offset offset from file start
*/
public Location(String unit, int line, int column, int offset){
this(unit,line,column);
this.offset=offset;
}
/**
* Location Object
* stores compilation unit, line and column
* @param unit compilation unit, e.g. file name
* @param line line number
* @param column column number
*/
public Location(String unit, int line, int column){
this.unit=unit;
this.line=line;
this.column=column;
}
/**
* Location Object
* stores line, column and offset to the file start
* @param line line number
* @param column column number
* @param offset offset from file start
*/
public Location(int line, int column, int offset){
this(line,column);
this.offset=offset;
}
/**
* Location Object
* stores line and column
* @param line line number
* @param column column number
*/
public Location(int line, int column){
this.line=line;
this.column=column;
}
public String toString(){
return unit+":"+line+"/"+column;
}
/**
* getColumn
* @returns column if known, else -1
*/
public int getColumn(){
return column;
}
/**
* getLine
* @returns line if known, else -1
*/
public int getLine(){
return line;
}
/**
* move moves this Location by the given differences.
* @param linediff
* @param coldiff
* @param offsetdiff
*/
public void move(int linediff, int coldiff, int offsetdiff){
if (this.line >= 0)
this.line += linediff;
if (this.column >= 0)
this.column += coldiff;
if (this.offset >= 0)
this.offset += offsetdiff;
}
/**
* Cloning factory method
* @param other
* @return new cloned Location
*/
public static Location clone(Location other){
return new Location(other);
}
/**
* getUnit
* @returns compilation unit if known, else 'unknown'
*/
public String getUnit(){
return unit;
}
/**
* getLine
* @returns line if known, else -1
*/
public String toString(){
return getUnit()+":"+getLine()+"/"+getColumn()+"("+offset+")";
}
/**
* Writes the location information directly into an XML document
* @param writer the destination XML Document
* @param orientation adds details about the orientation of this location as an attribute; often used with the strings "left" or "right"
* @throws XMLStreamException
*/
public void toXML(XMLStreamWriter writer,String orientation) throws XMLStreamException {
writer.writeStartElement("location");
writer.writeAttribute("compilationunit", unit);
writer.writeAttribute("orientation", orientation);
writer.writeAttribute("linenumber", line+"");
writer.writeAttribute("columnnumber", column+"");
writer.writeAttribute("offset", offset+"");
writer.writeEndElement();
}
/**
* getOffset
* @returns offset to start if known, else -1
*/
public int getOffset(){
return offset;
}
}
/**
* ComplexSymbol with detailed Location Informations and a Name
*/
public static class ComplexSymbol extends Symbol {
protected String name;
protected Location xleft,xright;
public Location xleft,xright;
public ComplexSymbol(String name, int id) {
super(id);
this.name=name;
......@@ -57,6 +162,9 @@ public class ComplexSymbolFactory implements SymbolFactory{
if (xleft==null || xright==null) return "Symbol: "+name;
return "Symbol: "+name+" ("+xleft+" - "+xright+")";
}
public String getName(){
return name;
}
public ComplexSymbol(String name, int id, int state) {
super(id,state);
this.name=name;
......@@ -68,19 +176,27 @@ public class ComplexSymbolFactory implements SymbolFactory{
if (right!=null) this.xright= ((ComplexSymbol)right).xright;
}
public ComplexSymbol(String name, int id, Location left, Location right) {
super(id);
super(id,left.offset,right.offset);
this.name=name;
this.xleft=left;
this.xright=right;
}
public ComplexSymbol(String name, int id, Symbol left, Symbol right, Object value) {
super(id,value);
super(id,left.left,right.right,value);
this.name=name;
if (left!=null) this.xleft = ((ComplexSymbol)left).xleft;
if (right!=null) this.xright= ((ComplexSymbol)right).xright;
}
public ComplexSymbol(String name, int id, Symbol left, Object value) {
super(id,left.right,left.right,value);
this.name=name;
if (left!=null) {
this.xleft = ((ComplexSymbol)left).xright;
this.xright= ((ComplexSymbol)left).xright;
}
}
public ComplexSymbol(String name, int id, Location left, Location right, Object value) {
super(id,value);
super(id,left.offset,right.offset,value);
this.name=name;
this.xleft=left;
this.xright=right;
......@@ -95,12 +211,25 @@ public class ComplexSymbolFactory implements SymbolFactory{
// Factory methods
/**
* newSymbol
* creates a complex symbol with Location objects for left and right boundaries;
* this is used for terminals with values!
*/
public Symbol newSymbol(String name, int id, Location left, Location right, Object value){
return new ComplexSymbol(name,id,left,right,value);
}
/**
* newSymbol
* creates a complex symbol with Location objects for left and right boundaries;
* this is used for terminals without values!
*/
public Symbol newSymbol(String name, int id, Location left, Location right){
return new ComplexSymbol(name,id,left,right);
}
public Symbol newSymbol(String name, int id, Symbol left, Object value) {
return new ComplexSymbol(name,id,left,value);
}
public Symbol newSymbol(String name, int id, Symbol left, Symbol right, Object value){
return new ComplexSymbol(name,id,left,right,value);
}
......
......@@ -31,6 +31,9 @@ public class DefaultSymbolFactory implements SymbolFactory{
public Symbol newSymbol(String name ,int id, Symbol left, Symbol right, Object value){
return new Symbol(id,left,right,value);
}
public Symbol newSymbol(String name ,int id, Symbol left, Object value){
return new Symbol(id,left,value);
}
public Symbol newSymbol(String name, int id, Symbol left, Symbol right){
return new Symbol(id,left,right);
}
......
package java_cup.runtime;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class ScannerBuffer implements Scanner {
private Scanner inner;
private List<Symbol> buffer = new LinkedList<Symbol>();
/**
* Wraps around a custom scanner and stores all so far produced tokens in a buffer
* @param inner the scanner to buffer
*/
public ScannerBuffer(Scanner inner){
this.inner=inner;
}
/**
* Read-Only access to the buffered Symbols
* @return an unmodifiable Version of the buffer
*/
public List<Symbol> getBuffered() {
return Collections.unmodifiableList(buffer);
}
@Override
public Symbol next_token() throws Exception {
Symbol buffered = inner.next_token();
buffer.add(buffered);
return buffered;
}
}
......@@ -34,7 +34,10 @@ public class Symbol {
public Symbol(int id, Symbol left, Symbol right){
this(id,left.left,right.right);
}
/*******************************
public Symbol(int id, Symbol left, Object o){
this(id,left.right,left.right,o);
}
/*******************************
Constructor for l,r values
*******************************/
......
......@@ -17,17 +17,61 @@ package java_cup.runtime;
public interface SymbolFactory {
// Factory methods
/**
* Construction with left/right propagation switched on
* newSymbol
* creates a symbol with a value, grouping other symbols with left/right locations;
* used frequently by the parser to implement non-terminal symbols
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param left symbol, to take the left location from
* @param right symbol, to take the right location from
* @param value value, attached to this symbol
*/
public Symbol newSymbol(String name, int id, Symbol left, Symbol right, Object value);
/**
* newSymbol
* creates a symbol, grouping other symbols with left/right locations;
* used frequently by the parser to implement non-terminal symbols
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param left symbol, to take the left location from
* @param right symbol, to take the right location from
*/
public Symbol newSymbol(String name, int id, Symbol left, Symbol right);
/**
* Construction with left/right propagation switched off
* newSymbol
* creates a symbol for an empty production, taking its location from the Symbol on the left
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param left symbol, to take the left location from
* @param value value, attached to this symbol
*/
public Symbol newSymbol(String name, int id, Symbol left, Object value);
/**
* newSymbol
* creates a basic symbol with an attached value;
* used frequently for terminal symbols like identifiers
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param value value, attached to this symbol
*/
public Symbol newSymbol(String name, int id, Object value);
/**
* newSymbol
* creates a basic symbol;
* used frequently for terminal symbols, like keywords
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param value value, attached to this symbol
*/
public Symbol newSymbol(String name, int id);
/**
* Construction of start symbol
* newSymbol
* creates the start symbol
* @param name Textual name for the Symbol for verbose error messages
* @param id enum value associated with this symbol, generated by cup via sym.java
* @param left symbol, to take the left location from
* @param right symbol, to take the right location from
* @param value value, attached to this symbol
*/
public Symbol startSymbol(String name, int id, int state);
}
package java_cup.runtime;
import java.util.HashMap;
import java.util.List;
public class SyntaxTreeDFS {
public static interface ElementHandler {
public void handle(XMLElement parent, List<XMLElement> children);
}
public static abstract class AbstractVisitor implements Visitor {
private HashMap<String, ElementHandler> preMap = new HashMap<>();
private HashMap<String, ElementHandler> postMap = new HashMap<>();
public abstract void defaultPre(XMLElement element, List<XMLElement> children);
public abstract void defaultPost(XMLElement element,List<XMLElement> children);
@Override
public void preVisit(XMLElement element) {
ElementHandler handler = preMap.get(element.tagname);
if (handler==null) {
defaultPre(element,element.getChildren());
} else
handler.handle(element, element.getChildren());
}
@Override
public void postVisit(XMLElement element) {
ElementHandler handler = postMap.get(element.tagname);
if (handler==null) {
defaultPost(element,element.getChildren());
} else
handler.handle(element, element.getChildren());
}
public void registerPreVisit(String s,ElementHandler h){
preMap.put(s, h);
}
public void registerPostVisit(String s, ElementHandler h){
postMap.put(s, h);
}
}
public static interface Visitor {
public void preVisit(XMLElement element);
public void postVisit(XMLElement element);
}
public static void dfs(XMLElement element, Visitor visitor){
visitor.preVisit(element);
for (XMLElement el :element.getChildren()){
dfs(el,visitor);
}
visitor.postVisit(element);
}
}
package java_cup.runtime;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
public class SyntaxTreeTransform {
private static class ChainRemover extends SyntaxTreeDFS.AbstractVisitor{
public XMLElement root(){
return stack.pop();
}
private Stack<XMLElement> stack = new Stack<XMLElement>();
@Override
public void defaultPost(XMLElement arg0, List<XMLElement> arg1) {
int n = arg1.size();
if (n>1){
LinkedList<XMLElement> elems = new LinkedList<>();
while (n-->0) elems.addFirst(stack.pop());
XMLElement ne = new XMLElement.NonTerminal(arg0.getTagname(),0,elems.toArray(new XMLElement[0]));
stack.push(ne);
return;
}
//if (n==1){}
if (n==0) stack.push(arg0);
}
@Override
public void defaultPre(XMLElement arg0, List<XMLElement> arg1) {}
}
public static XMLElement removeUnaryChains(XMLElement elem) {
ChainRemover cr = new ChainRemover();
SyntaxTreeDFS.dfs(elem, cr);
return cr.root();
}
}
package java_cup.runtime;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class SyntaxTreeXPath {
public static List<XMLElement> query(String query, XMLElement element){
if (query.startsWith("/")) query=query.substring(1);
return query0(new LinkedList<String>(Arrays.asList( query.split("/"))),0,element,0);
}
private static List<XMLElement> query0(List<String> q,int idx, XMLElement element,int seq){
if (q.get(idx).isEmpty()) { // match deeper descendant q[1]
return matchDeeperDescendant(q,idx+1 ,element,seq);
}
List<XMLElement> l = new LinkedList<XMLElement>();
if (!match(q.get(idx),element,seq)) return new LinkedList();
if (q.size()-1==idx) return singleton(element);
List<XMLElement> children = element.getChildren();
for (int i=0; i< children.size();i++){
XMLElement child= children.get(i);
l.addAll(query0(q,idx+1,child,i));
}
return l;
}
private static List<XMLElement> matchDeeperDescendant(List<String> query,int idx, XMLElement element, int seq){
if (query.size()<=idx) return singleton(element);
boolean matches = match(query.get(idx),element,seq);
List<XMLElement> l = new LinkedList<XMLElement>();
List<XMLElement> children = element.getChildren();
if (matches) return query0(query,idx,element,seq);
for (int i=0; i< children.size();i++){
XMLElement child= children.get(i);
l.addAll(matchDeeperDescendant(query, idx, child,i));
}
return l;
}
private static boolean match(String m,XMLElement elem,int seq){
// System.out.println("Matching "+elem.tagname+" with "+m);
boolean result = true;
String[] name = m.split("\\[");
String[] tag = name[0].split("\\*");
if (tag[0].isEmpty()) { // start is wildcard
if (tag.length>2)
result &= elem.tagname.contains(tag[1]);
else
if (tag.length==2)
result &= elem.tagname.endsWith(tag[1]);
else
result &= false;
} else { // match with start
if (tag.length==2)
result &=elem.tagname.startsWith(tag[1]);
else
result = elem.tagname.equals(tag[0]);
}
for (int i=1; i<name.length; i++) {
String predicate= name[i];
if (!predicate.endsWith("]")) return false;
predicate=predicate.substring(0, predicate.length()-1);
if (predicate.startsWith("@")){
if (predicate.substring(1).startsWith("variant"))
if ((elem instanceof XMLElement.NonTerminal)&& Integer.parseInt(predicate.substring(9))==((XMLElement.NonTerminal)elem).getVariant())
result&=true;
else
return false;
else return false;
} else
if (predicate.matches("\\d+")){
result &= Integer.parseInt(predicate)==seq;
}
else
return false; // submatch
}
return result;
}
private static List<XMLElement> singleton(XMLElement elem){
LinkedList<XMLElement> l = new LinkedList<XMLElement>();
l.add(elem);
return l;
}
}
package java_cup.runtime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java_cup.runtime.ComplexSymbolFactory.ComplexSymbol;
import java_cup.runtime.ComplexSymbolFactory.Location;
public abstract class XMLElement {
public abstract List<XMLElement> selectById(String s);
public static void dump(XMLStreamWriter writer, XMLElement elem, String ... blacklist) throws XMLStreamException {
dump(null,writer,elem,blacklist);
}
public static void dump(ScannerBuffer buffer, XMLStreamWriter writer, XMLElement elem, String ... blacklist) throws XMLStreamException {
writer.writeStartDocument("utf-8", "1.0");
writer.writeProcessingInstruction("xml-stylesheet","href=\"tree.xsl\" type=\"text/xsl\"");
writer.writeStartElement("document");
if (blacklist.length>0) {
writer.writeStartElement("blacklist");
for (String s: blacklist){
writer.writeStartElement("symbol");
writer.writeCharacters(s);
writer.writeEndElement();
}
writer.writeEndElement();
}
writer.writeStartElement("parsetree");
elem.dump(writer);
writer.writeEndElement();
if (buffer!=null){
writer.writeStartElement("tokensequence");
for (Symbol s:buffer.getBuffered()){
if (s instanceof ComplexSymbol){
ComplexSymbol cs = (ComplexSymbol)s;
if (cs.value!=null){
writer.writeStartElement("token");
writer.writeAttribute("name",cs.getName());
cs.getLeft().toXML(writer, "left");
writer.writeCharacters(cs.value+"");
cs.getRight().toXML(writer, "right");
writer.writeEndElement();
} else