Commit ece51f27 authored by Markus Koschany's avatar Markus Koschany

Merge tag 'upstream/0.11a+20060608'

Upstream version 0.11a+20060608

# gpg: Signature made Wed 30 Dec 2015 03:15:47 CET using RSA key ID 513B51E4
# gpg: Good signature from "Markus Koschany <apo@gambaru.de>" [ultimate]
# gpg:                 aka "Markus Koschany <markus@koschany.net>" [ultimate]
# gpg:                 aka "Markus Koschany <apo@debian.org>" [ultimate]
parents bc0d8701 2a52475f
<project name="emugen" default ="dist" basedir=".">
<property name="etc" location="etc" />
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="src" location="src" />
<property name="java" location="java" />
<property name="classes" location="classes" />
<property name="dist" location="dist" />
<!--property name="test" location="test" /-->
<property name="flex" location="flex" />
<property name="cup" location="cup" />
<!-- initialize the workspace -->
<target name="init">
<tstamp />
<mkdir dir="${src}" />
<mkdir dir="${java}" />
<mkdir dir="${classes}" />
<mkdir dir="${dist}" />
</target>
<property environment="env" />
<path id="libraries">
<pathelement location="${src}" />
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="binaries">
<fileset dir="${bin}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${java}" />
<delete dir="${classes}" />
<delete dir="${dist}" />
</target>
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${bin}/java-cup-11.jar" />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${bin}/JFlex.jar" />
<target name="cup" depends="init">
<cup srcfile="${cup}/parser.cup" interface="on" destdir="${java}" parser="parser" symbols="sym" quiet="false" nonterms="true"/>
</target>
<target name="jflex" depends="cup">
<jflex file="${flex}/Lexer.jflex" destdir="${java}" />
</target>
<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">
<classpath refid="libraries"/>
</javac>
</target>
<target name="dist" depends="compile">
<jar jarfile="${dist}/java-cup-11a.jar" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="java_cup/Main" />
<attribute name="Class-Path" value="java-cup-11a-runtime.jar" />
</manifest>
</jar>
<jar jarfile="${dist}/java-cup-11a-runtime.jar" basedir="${classes}" includes="java_cup/runtime/*">
</jar>
</target>
<target name="test" depends="dist">
<java jar="${dist}/java-cup-11a.jar" fork="true">
<arg value="-interface" />
<arg value="${cup}/parser.cup" />
</java>
</target>
</project>
This diff is collapsed.
This diff is collapsed.
package java_cup;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.ComplexSymbolFactory.Location;
import java_cup.runtime.Symbol;
import java.lang.Error;
import java.io.InputStreamReader;
%%
%class Lexer
%implements sym
%public
%unicode
%line
%column
%cup
%{
public Lexer(ComplexSymbolFactory sf){
this(new InputStreamReader(System.in));
symbolFactory = sf;
}
private StringBuffer sb;
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){
ErrorManager.getManager().emit_warning("Scanner at " + (yyline+1) + "(" + (yycolumn+1) + "): " + message);
}
protected void emit_error(String message){
ErrorManager.getManager().emit_error("Scanner at " + (yyline+1) + "(" + (yycolumn+1) + "): " + message);
}
%}
Newline = \r | \n | \r\n
Whitespace = [ \t\f] | {Newline}
/* comments */
Comment = {TraditionalComment} | {EndOfLineComment}
TraditionalComment = "/*" {CommentContent} \*+ "/"
EndOfLineComment = "//" [^\r\n]* {Newline}
CommentContent = ( [^*] | \*+[^*/] )*
ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
%eofval{
return symbolFactory.newSymbol("EOF",sym.EOF);
%eofval}
%state CODESEG
%%
<YYINITIAL> {
{Whitespace} { }
"?" { return symbol("QESTION",QUESTION); }
";" { return symbol("SEMI",SEMI); }
"," { return symbol("COMMA",COMMA); }
"*" { return symbol("STAR",STAR); }
"." { return symbol("DOT",DOT); }
"|" { return symbol("BAR",BAR); }
"[" { return symbol("LBRACK",LBRACK); }
"]" { return symbol("RBRACK",RBRACK); }
":" { return symbol("COLON",COLON); }
"::=" { return symbol("COLON_COLON_EQUALS",COLON_COLON_EQUALS); }
"%prec" { return symbol("PERCENT_PREC",PERCENT_PREC); }
">" { return symbol("GT",GT); }
"<" { return symbol("LT",LT); }
{Comment} { }
"{:" { sb = new StringBuffer(); csline=yyline+1; cscolumn=yycolumn+1; yybegin(CODESEG); }
"package" { return symbol("PACKAGE",PACKAGE); }
"import" { return symbol("IMPORT",IMPORT); }
"code" { return symbol("CODE",CODE); }
"action" { return symbol("ACTION",ACTION); }
"parser" { return symbol("PARSER",PARSER); }
"terminal" { return symbol("PARSER",TERMINAL); }
"non" { return symbol("NON",NON); }
"nonterminal" { return symbol("NONTERMINAL",NONTERMINAL); }
"init" { return symbol("INIT",INIT); }
"scan" { return symbol("SCAN",SCAN); }
"with" { return symbol("WITH",WITH); }
"start" { return symbol("START",START); }
"precedence" { return symbol("PRECEDENCE",PRECEDENCE); }
"left" { return symbol("LEFT",LEFT); }
"right" { return symbol("RIGHT",RIGHT); }
"nonassoc" { return symbol("NONASSOC",NONASSOC); }
"extends" { return symbol("EXTENDS",EXTENDS); }
"super" { return symbol("SUPER",SUPER); }
{ident} { return symbol("ID",ID,yytext()); }
}
<CODESEG> {
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn),new Location(yyline+1,yycolumn+1+yylength()), sb.toString()); }
.|\n { sb.append(yytext()); }
}
// error fallback
.|\n { emit_warning("Unrecognized character '" +yytext()+"' -- ignored"); }
This diff is collapsed.
package java_cup;
import java_cup.runtime.Symbol;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class ErrorManager{
private static ErrorManager errorManager;
private int errors = 0;
private int warnings = 0;
private int fatals = 0;
public int getFatalCount() { return fatals; }
public int getErrorCount() { return errors; }
public int getWarningCount() { return warnings; }
static {
errorManager = new ErrorManager();
}
public static ErrorManager getManager() { return errorManager; }
private ErrorManager(){
}
//TODO: migrate to java.util.logging
/**
* Error message format:
* ERRORLEVEL at (LINE/COLUMN)@SYMBOL: MESSAGE
* ERRORLEVEL : MESSAGE
**/
public void emit_fatal(String message){
System.err.println("Fatal : "+message);
fatals++;
}
public void emit_fatal(String message, Symbol sym){
//System.err.println("Fatal at ("+sym.left+"/"+sym.right+")@"+convSymbol(sym)+" : "+message);
System.err.println("Fatal: "+message+" @ "+sym);
fatals++;
}
public void emit_warning(String message){
System.err.println("Warning : " + message);
warnings++;
}
public void emit_warning(String message, Symbol sym){
// System.err.println("Warning at ("+sym.left+"/"+sym.right+")@"+convSymbol(sym)+" : "+message);
System.err.println("Fatal: "+message+" @ "+sym);
warnings++;
}
public void emit_error(String message){
System.err.println("Error : " + message);
errors++;
}
public void emit_error(String message, Symbol sym){
// System.err.println("Error at ("+sym.left+"/"+sym.right+")@"+convSymbol(sym)+" : "+message);
System.err.println("Error: "+message+" @ "+sym);
errors++;
}
private static String convSymbol(Symbol symbol){
String result = (symbol.value == null)? "" : " (\""+symbol.value.toString()+"\")";
Field [] fields = sym.class.getFields();
for (int i = 0; i < fields.length ; i++){
if (!Modifier.isPublic(fields[i].getModifiers())) continue;
try {
if (fields[i].getInt(null) == symbol.sym) return fields[i].getName()+result;
}catch (Exception ex) {
}
}
return symbol.toString()+result;
}
}
This diff is collapsed.
package java_cup;
/**
* This class represents a part of a production which contains an
* action. These are eventually eliminated from productions and converted
* to trailing actions by factoring out with a production that derives the
* empty string (and ends with this action).
*
* @see java_cup.production
* @version last update: 11/25/95
* @author Scott Hudson
*/
public class action_part extends production_part {
/*-----------------------------------------------------------*/
/*--- Constructors ------------------------------------------*/
/*-----------------------------------------------------------*/
/** Simple constructor.
* @param code_str string containing the actual user code.
*/
public action_part(String code_str)
{
super(/* never have a label on code */null);
_code_string = code_str;
}
/*-----------------------------------------------------------*/
/*--- (Access to) Instance Variables ------------------------*/
/*-----------------------------------------------------------*/
/** String containing code for the action in question. */
protected String _code_string;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** String containing code for the action in question. */
public String code_string() {return _code_string;}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Set the code string. */
public void set_code_string(String new_str) {_code_string = new_str;}
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/** Override to report this object as an action. */
public boolean is_action() { return true; }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Equality comparison for properly typed object. */
public boolean equals(action_part other)
{
/* compare the strings */
return other != null && super.equals(other) &&
other.code_string().equals(code_string());
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Generic equality comparison. */
public boolean equals(Object other)
{
if (!(other instanceof action_part))
return false;
else
return equals((action_part)other);
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Produce a hash code. */
public int hashCode()
{
return super.hashCode() ^
(code_string()==null ? 0 : code_string().hashCode());
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Convert to a string. */
public String toString()
{
return super.toString() + "{" + code_string() + "}";
}
/*-----------------------------------------------------------*/
}
package java_cup;
/** A specialized version of a production used when we split an existing
* production in order to remove an embedded action. Here we keep a bit
* of extra bookkeeping so that we know where we came from.
* @version last updated: 11/25/95
* @author Scott Hudson
*/
public class action_production extends production {
/** Constructor.
* @param base the production we are being factored out of.
* @param lhs_sym the LHS symbol for this production.
* @param rhs_parts array of production parts for the RHS.
* @param rhs_len how much of the rhs_parts array is valid.
* @param action_str the trailing reduce action for this production.
* @param indexOfIntermediateResult the index of the result of the previous intermediate action on the stack relative to top, -1 if no previous action
*/
public action_production(
production base,
non_terminal lhs_sym,
production_part rhs_parts[],
int rhs_len,
String action_str,
int indexOfIntermediateResult)
throws internal_error
{
super(lhs_sym, rhs_parts, rhs_len, action_str);
_base_production = base;
this.indexOfIntermediateResult = indexOfIntermediateResult;
}
private int indexOfIntermediateResult;
/**
* @return the index of the result of the previous intermediate action on the stack relative to top, -1 if no previous action
*/
public int getIndexOfIntermediateResult(){
return indexOfIntermediateResult;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The production we were taken out of. */
protected production _base_production;
/** The production we were taken out of. */
public production base_production() {return _base_production;}
}
This diff is collapsed.
package java_cup;
/* Defines integers that represent the associativity of terminals
* @version last updated: 7/3/96
* @author Frank Flannery
*/
public class assoc {
/* various associativities, no_prec being the default value */
public final static int left = 0;
public final static int right = 1;
public final static int nonassoc = 2;
public final static int no_prec = -1;
}
\ No newline at end of file
This diff is collapsed.
package java_cup;
/** Exception subclass for reporting internal errors in JavaCup. */
public class internal_error extends Exception
{
/** Constructor with a message */
public internal_error(String msg)
{
super(msg);
}
/** Method called to do a forced error exit on an internal error
for cases when we can't actually throw the exception. */
public void crash()
{
ErrorManager.getManager().emit_fatal("JavaCUP Internal Error Detected: "+getMessage());
printStackTrace();
System.exit(-1);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package java_cup;
/** This class represents a transition in an LALR viable prefix recognition
* machine. Transitions can be under terminals for non-terminals. They are
* internally linked together into singly linked lists containing all the
* transitions out of a single state via the _next field.
*
* @see java_cup.lalr_state
* @version last updated: 11/25/95
* @author Scott Hudson
*
*/
public class lalr_transition {
/*-----------------------------------------------------------*/
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
/** Full constructor.
* @param on_sym symbol we are transitioning on.
* @param to_st state we transition to.
* @param nxt next transition in linked list.
*/
public lalr_transition(symbol on_sym, lalr_state to_st, lalr_transition nxt)
throws internal_error
{
/* sanity checks */
if (on_sym == null)
throw new internal_error("Attempt to create transition on null symbol");
if (to_st == null)
throw new internal_error("Attempt to create transition to null state");
/* initialize */
_on_symbol = on_sym;
_to_state = to_st;
_next = nxt;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Constructor with null next.
* @param on_sym symbol we are transitioning on.
* @param to_st state we transition to.
*/
public lalr_transition(symbol on_sym, lalr_state to_st) throws internal_error
{
this(on_sym, to_st, null);
}
/*-----------------------------------------------------------*/
/*--- (Access to) Instance Variables ------------------------*/
/*-----------------------------------------------------------*/
/** The symbol we make the transition on. */
protected symbol _on_symbol;
/** The symbol we make the transition on. */
public symbol on_symbol() {return _on_symbol;}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** The state we transition to. */
protected lalr_state _to_state;
/** The state we transition to. */
public lalr_state to_state() {return _to_state;}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Next transition in linked list of transitions out of a state */
protected lalr_transition _next;
/** Next transition in linked list of transitions out of a state */
public lalr_transition next() {return _next;}
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/** Convert to a string. */
public String toString()
{
String result;
result = "transition on " + on_symbol().name() + " to state [";
result += _to_state.index();
result += "]";
return result;
}
/*-----------------------------------------------------------*/
}
This diff is collapsed.
This diff is collapsed.
package java_cup;
/** This class represents a shift/reduce nonassociative error within the
* parse table. If action_table element is assign to type
* nonassoc_action, it cannot be changed, and signifies that there
* is a conflict between shifting and reducing a production and a
* terminal that shouldn't be next to each other.
*
* @version last updated: 7/2/96
* @author Frank Flannery
*/
public class nonassoc_action extends parse_action {
/*-----------------------------------------------------------*/
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
/** Simple constructor.
*/
public nonassoc_action() throws internal_error
{
/* don't need to set anything, since it signifies error */
}
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/** Quick access to type of action. */
public int kind() {return NONASSOC;}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Equality test. */
public boolean equals(parse_action other)
{
return other != null && other.kind() == NONASSOC;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Generic equality test. */
public boolean equals(Object other)
{
if (other instanceof parse_action)
return equals((parse_action)other);
else
return false;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Compute a hash code. */
public int hashCode()
{
/* all objects of this class hash together */
return 0xCafe321;
}
/** Convert to string. */
public String toString()
{
return "NONASSOC";
}
/*-----------------------------------------------------------*/
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package java_cup.runtime;
/**
* Defines the Scanner interface, which CUP uses in the default
* implementation of <code>lr_parser.scan()</code>. Integration
* of scanners implementing <code>Scanner</code> is facilitated.
*
* @version last updated 23-Jul-1999
* @author David MacMahon <davidm@smartsc.com>
*/
/* *************************************************
Interface Scanner
Declares the next_token() method that should be
implemented by scanners. This method is typically
called by lr_parser.scan(). End-of-file can be
indicated either by returning
<code>new Symbol(lr_parser.EOF_sym())</code> or
<code>null</code>.
***************************************************/
public interface Scanner {
/** Return the next token, or <code>null</code> on end-of-file. */
public Symbol next_token() throws java.lang.Exception;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment