Commit 8419c9ac authored by Sebastian Pretscher's avatar Sebastian Pretscher

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents 0081a262 9f6d08ff
......@@ -251,7 +251,7 @@ parser code {:
Object info)
{
done_parsing();
if (info instanceof Symbol)
if (info instanceof java_cup.runtime.Symbol)
errMan.Fatal(ErrorSource.Parser, message + "\nCan't recover from previous error(s), giving up.",(ComplexSymbol)info);
else
errMan.Fatal(ErrorSource.Parser, message + "\nCan't recover from previous error(s), giving up.",(ComplexSymbol)cur_token);
......@@ -261,7 +261,7 @@ parser code {:
@Override
public void report_error(String message, Object info)
{
if (info instanceof Symbol)
if (info instanceof java_cup.runtime.Symbol)
errMan.Error(ErrorSource.Parser, message, (ComplexSymbol) info);
else
errMan.Error(ErrorSource.Parser, message, (ComplexSymbol) cur_token);
......@@ -1078,13 +1078,14 @@ new_term_id ::=
multipart_name = "Object";
}
Range range = Range.fromLocations(term_idxleft, term_idxright);
Terminal t = new Terminal(new Name(term_id, range), (Range) range.clone());
/* build a production_part and put it in the table */
symbols.put(term_id,
new symbol_part(new terminal(context, term_id, multipart_name)));
Range range = Range.fromLocations(term_idxleft, term_idxright);
RESULT = new Terminal(new Name(term_id, range), (Range) range.clone());
new symbol_part(new terminal(context, t, term_id, multipart_name)));
RESULT = t;
}
:}
;
......@@ -1106,9 +1107,15 @@ new_non_term_id ::=
if (multipart_name.equals("")) {
multipart_name ="Object";
}
// jrTODO: positions!
// jrTODO: non_term_id vs. multipart_name
Range range = Range.fromLocations(non_term_idxleft, non_term_idxright);
NonTerminal nt = new NonTerminal(new Name(non_term_id, range), (Range) range.clone());
/* build the non terminal object */
non_terminal this_nt =
new non_terminal(context, non_term_id, multipart_name);
new non_terminal(context, nt, non_term_id, multipart_name);
/* put it in the non_terms table */
non_terms.put(non_term_id, this_nt);
......@@ -1116,10 +1123,8 @@ new_non_term_id ::=
/* build a production_part and put it in the symbols table */
symbols.put(non_term_id, new symbol_part(this_nt));
// jrTODO: positions!
// jrTODO: non_term_id vs. multipart_name
Range range = Range.fromLocations(non_term_idxleft, non_term_idxright);
RESULT = new NonTerminal(new Name(non_term_id, range), (Range) range.clone());
RESULT = nt;
}
:}
;
......
package de.in.tum.www2.cup.ast;
public interface IHasDeclarationReference {
AbstractNode getDeclaration();
void setDeclaration(AbstractNode node);
......
......@@ -3,8 +3,7 @@ package de.in.tum.www2.cup.ast;
import de.in.tum.www2.cup.analysis.AbstractVisitor;
import de.in.tum.www2.cup.Range;
public class NonTerminal extends AbstractNode
implements IWithName, IHasDeclarationReference, IHasDefinitionReference {
public class NonTerminal extends Symbol implements IHasDefinitionReference {
private Name name;
private Production definitionRef; // has to be resolved first.
......
package de.in.tum.www2.cup.ast;
import de.in.tum.www2.cup.Range;
public abstract class Symbol extends AbstractNode
implements IWithName, IHasDeclarationReference {
public Symbol(Range range) {
super(range);
}
}
......@@ -3,8 +3,7 @@ package de.in.tum.www2.cup.ast;
import de.in.tum.www2.cup.analysis.AbstractVisitor;
import de.in.tum.www2.cup.Range;
public class Terminal extends AbstractNode
implements IWithName, IHasDeclarationReference {
public class Terminal extends Symbol {
private Name name;
private Terminal declarationRef; // has to be resolved first.
......
......@@ -4,6 +4,7 @@ import java.util.Hashtable;
import java.util.Enumeration;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.ast.NonTerminal;
import de.in.tum.www2.cup.internal.terminal.terminal_shared;
/** This class represents a non-terminal symbol in the grammar. Each
......@@ -27,10 +28,10 @@ public class non_terminal extends symbol {
* @param nm the name of the non terminal.
* @param tp the type string for the non terminal.
*/
public non_terminal(CupContext context, String nm, String tp)
public non_terminal(CupContext context, NonTerminal astNode, String nm, String tp)
{
/* super class does most of the work */
super(nm, tp);
super(astNode, nm, tp);
stat = context.getForContext(non_terminal_shared.class);
......@@ -57,9 +58,9 @@ public class non_terminal extends symbol {
/** Constructor with default type.
* @param nm the name of the non terminal.
*/
public non_terminal(CupContext context, String nm)
public non_terminal(CupContext context, NonTerminal astNode, String nm)
{
this(context, nm, null);
this(context, astNode, nm, null);
}
/*-----------------------------------------------------------*/
......@@ -132,7 +133,7 @@ public class non_terminal extends symbol {
public non_terminal getSTART_nt() {
if (_START_nt == null)
_START_nt = new non_terminal(context, "$START");
_START_nt = new non_terminal(context, null, "$START");
return _START_nt;
}
}
......@@ -174,7 +175,7 @@ public class non_terminal extends symbol {
if (prefix==null)
prefix = "NT$";
non_terminal_shared shared = non_terminal.getShared(context);
return new non_terminal(context, prefix + shared.next_nt++,type);
return new non_terminal(context, null, prefix + shared.next_nt++,type);
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
......
package de.in.tum.www2.cup.internal;
import de.in.tum.www2.cup.ast.AbstractNode;
import de.in.tum.www2.cup.ast.NonTerminal;
import de.in.tum.www2.cup.ast.Symbol;
/** This abstract class serves as the base class for grammar symbols (i.e.,
* both terminals and non-terminals). Each symbol has a name string, and
* a string giving the type of object that the symbol will be represented by
......@@ -18,12 +22,20 @@ public abstract class symbol {
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
private Symbol astNode;
public Symbol getAstNode() {
return astNode;
}
/** Full constructor.
* @param nm the name of the symbol.
* @param tp a string with the type name.
*/
public symbol(String nm, String tp)
public symbol(Symbol astNode, String nm, String tp)
{
this.astNode = astNode;
/* sanity check */
if (nm == null) nm = "";
......@@ -39,9 +51,9 @@ public abstract class symbol {
/** Constructor with default type.
* @param nm the name of the symbol.
*/
public symbol(String nm)
public symbol(Symbol astNode, String nm)
{
this(nm, null);
this(astNode, nm, null);
}
/*-----------------------------------------------------------*/
......
......@@ -4,6 +4,7 @@ import java.util.Hashtable;
import java.util.Enumeration;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.ast.Terminal;
import de.in.tum.www2.cup.internal.assoc;
import de.in.tum.www2.cup.internal.parse_action_row.parse_action_row_shared;
......@@ -28,11 +29,11 @@ public class terminal extends symbol {
* @param nm the name of the terminal.
* @param tp the type of the terminal.
*/
public terminal(CupContext context, String nm, String tp, int precedence_side, int precedence_num)
public terminal(CupContext context, Terminal astNode, String nm, String tp, int precedence_side, int precedence_num)
{
/* superclass does most of the work */
super(nm, tp);
super(astNode, nm, tp);
stat = context.getForContext(terminal_shared.class);
......@@ -62,9 +63,9 @@ public class terminal extends symbol {
/** Constructor for non-precedented terminal
*/
public terminal(CupContext context, String nm, String tp)
public terminal(CupContext context, Terminal astNode, String nm, String tp)
{
this(context, nm, tp, assoc.no_prec, -1);
this(context, astNode, nm, tp, assoc.no_prec, -1);
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
......@@ -72,9 +73,9 @@ public class terminal extends symbol {
/** Constructor with default type.
* @param nm the name of the terminal.
*/
public terminal(CupContext context, String nm)
public terminal(CupContext context, Terminal astNode, String nm)
{
this(context, nm, null);
this(context, astNode, nm, null);
}
/*-----------------------------------------------------------*/
......@@ -97,13 +98,13 @@ public class terminal extends symbol {
public terminal getEOF() {
if (_EOF == null)
_EOF = new terminal(context, "EOF");
_EOF = new terminal(context, null, "EOF");
return _EOF;
}
public terminal getError() {
if (_error == null)
_error = new terminal(context, "error");
_error = new terminal(context, null, "error");
return _error;
}
......@@ -117,8 +118,8 @@ public class terminal extends symbol {
_all.clear();
_all_by_index.clear();
next_index=0;
_EOF = new terminal(context, "EOF");
_error = new terminal (context, "error");
_EOF = new terminal(context, null, "EOF");
_error = new terminal (context, null, "error");
}
/** Access to all terminals. */
......
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