Commit 4a8fdee5 authored by Johannes Roith's avatar Johannes Roith

Various fixes in the backend.

parent 29fba38e
......@@ -26,7 +26,7 @@
<mkdir dir="${classes}"/>
<mkdir dir="${result}"/>
<javac srcdir="${java}" destdir="${classes}">
<javac srcdir="${java}" includeantruntime="false" destdir="${classes}">
<classpath refid="libraries" />
</javac>
......
......@@ -140,9 +140,6 @@ action code {:
protected String multipart_name = new String();
protected Stack multipart_names = new Stack();
// TODO: this is a hack, since we can't store the CODE_STRING offsets properly.
private int prod_part_offset;
/** table of declared symbols -- contains production parts indexed by name */
protected Hashtable symbols = new Hashtable();
......@@ -341,13 +338,15 @@ spec ::=
package_spec ::=
PACKAGE : p
multipart_id
multipart_id : mi
{:
/* save the package name */
context.package_name = multipart_name;
parserResult.pack = new de.in.tum.www2.cup.ast.Package(
new Name (multipart_name, null), // TODO: from, to
new Name (multipart_name,
Range.fromLocations(mixleft, mixright)
),
new Range(Position.fromLocation(pxleft),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token)));
......@@ -372,15 +371,15 @@ import_list ::=
import_spec ::=
IMPORT : import_token
import_id
import_id : ii
SEMI : semi {:
/* save this import on the imports list */
context.import_list.push(multipart_name);
Import imprt = new Import(
new Name (multipart_name, null), // TODO: from, to
new Range(Position.fromLocation(import_tokenxleft),
Position.fromLocation(semixright)));
new Name (multipart_name,
Range.fromLocations(iixleft, iixright)),
Range.fromLocations(import_tokenxleft, semixright));
parserResult.imports.add(imprt);
/* reset the accumulated multipart name */
......@@ -510,58 +509,41 @@ symbol_list ::= symbol_list symbol | symbol;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
symbol ::=
TERMINAL
TERMINAL : t
type_id : tid
declares_term : lst {:
//jrTODO: BUG? this is strange!!! -> there must be a better way
// to refer to these terminals.
ComplexSymbol terminal = (ComplexSymbol) stack.elementAt(stack.size()-2);
parserResult.symbols.add(new TypedTerminalDeclaration(
(String) tid,
(List<Terminal>) lst,
new Range(Position.fromComplexSymbolLeft(terminal),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()))));
new Range(Position.fromLocation(txleft),
Position.fromLocation(txright))));
:}
|
TERMINAL
TERMINAL : t
declares_term : lst {:
//jrTODO: BUG? this is strange!!! -> there must be a better way
// to refer to these terminals.
ComplexSymbol terminal = (ComplexSymbol) stack.elementAt(stack.size()-2);
parserResult.symbols.add(new TerminalDeclaration(
(List<Terminal>) lst,
new Range(Position.fromComplexSymbolLeft(terminal),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()))));
new Range(Position.fromLocation(txleft),
Position.fromLocation(txright))));
;
:}
|
non_terminal
non_terminal : nt
type_id : tid
declares_non_term : lst {:
//jrTODO: BUG? this is strange!!! -> there must be a better way
// to refer to these terminals.
ComplexSymbol nonTerminal = (ComplexSymbol) stack.elementAt(stack.size()-3);
parserResult.symbols.add(new TypedNonTerminalDeclaration(
(String) tid,
(List<NonTerminal>) lst,
new Range(Position.fromComplexSymbolLeft(nonTerminal),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()))));
new Range(Position.fromLocation(ntxleft),
Position.fromLocation(ntxright))));
:}
|
non_terminal
non_terminal : nt
declares_non_term:lst {:
//jrTODO: BUG? this is strange!!! -> there must be a better way
// to refer to these terminals.
ComplexSymbol nonTerminal = (ComplexSymbol) stack.elementAt(stack.size()-2);
parserResult.symbols.add(new NonTerminalDeclaration(
(List<NonTerminal>) lst,
new Range(Position.fromComplexSymbolLeft(nonTerminal),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()))));
new Range(Position.fromLocation(ntxleft),
Position.fromLocation(ntxright))));
:}
|
......@@ -809,7 +791,7 @@ rhs_list ::= rhs_list : lst BAR rhs : item {:
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
rhs ::=
prod_part_list PERCENT_PREC term_id:term_name
prod_part_list : ppl PERCENT_PREC term_id:term_name
{:
symbol sym = null;
if (lhs_nt != null)
......@@ -846,6 +828,16 @@ rhs ::=
p = new production(context, lhs_nt, rhs_parts, rhs_pos);
}
Range range = Range.fromLocations(term_namexleft, term_namexright);
RESULT = new ProductionRight(p.index(),
p.get_embedded_actions(),
ast_get_rhs_parts_copy(),
new Terminal(
new Name(term_name, range),
(Range) range.clone()
),
Range.fromLocations(pplxleft, term_namexright));
// p.index();
/* if we have no start non-terminal declared and this is
......@@ -875,9 +867,6 @@ rhs ::=
ast_new_rhs();
}
}
// jrTODO
// RESULT = "blub!!!";
/* reset the rhs accumulation in any case */
new_rhs();
......@@ -896,6 +885,7 @@ rhs ::=
RESULT = new ProductionRight(p.index(),
p.get_embedded_actions(),
ast_get_rhs_parts_copy(),
null,
Range.fromLocations(pplxleft, pplxright));
......@@ -931,13 +921,7 @@ rhs ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
prod_part_list ::= prod_part_list {:
// TODO: This is not quite correct, but it seems that we can't get the correct offset
// of CODE_STRING below. So we get the offset of the previous token here.
//
prod_part_offset = ((ComplexSymbol) cur_token).xright.getOffset();
:} prod_part | empty;
prod_part_list ::= prod_part_list prod_part | empty;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
......@@ -958,8 +942,7 @@ prod_part ::=
add_rhs_part(add_lab(symb, labid));
ProductionSymbolRef ref = null;
Range range = new Range (Position.fromLocation(symidxleft),
Position.fromLocation(symidxright));
Range range = Range.fromLocations(symidxleft, symidxright);
if (labid == null)
ref = new ProductionSymbolRef(new Name(symid, range), (Range) range.clone());
else
......@@ -973,20 +956,9 @@ prod_part ::=
int debug_id = get_new_debug_id();
add_rhs_part(new action_part(attach_debug_symbol(debug_id, code_str)));
// TODO: assign inner range as well: code_strxleft, code_strxright
// TODO: this is a quick and dirty workaround.
// it means, however, that the columns and offsets don't properly match up!
int offsetEnd = prod_part_offset + code_str.length();
Position pos1 = new Position(
code_strxleft.getLine(), code_strxleft.getColumn(), prod_part_offset);
Position pos2 = new Position(
code_strxright.getLine(), code_strxright.getColumn(), offsetEnd);
ast_add_rhs_part(new ActionCodeBlock(debug_id, code_str,
new Range(pos1, pos2)
Range.fromLocations(code_strxleft, code_strxright)
));
:}
;
......@@ -1090,8 +1062,7 @@ new_term_id ::=
symbols.put(term_id,
new symbol_part(new terminal(context, term_id, multipart_name)));
Range range = new Range(Position.fromLocation(term_idxleft),
Position.fromLocation(term_idxright));
Range range = Range.fromLocations(term_idxleft, term_idxright);
RESULT = new Terminal(new Name(term_id, range), (Range) range.clone());
}
......@@ -1127,8 +1098,7 @@ new_non_term_id ::=
// jrTODO: positions!
// jrTODO: non_term_id vs. multipart_name
Range range = new Range(Position.fromLocation(non_term_idxleft),
Position.fromLocation(non_term_idxright));
Range range = Range.fromLocations(non_term_idxleft, non_term_idxright);
RESULT = new NonTerminal(new Name(non_term_id, range), (Range) range.clone());
}
:}
......
......@@ -38,7 +38,7 @@ import java.io.InputStreamReader;
private StringBuffer sb;
private ComplexSymbolFactory symbolFactory;
private int csline,cscolumn;
private int csline, cscolumn, csoffset;
public Symbol symbol(String name, int code){
return symbolFactory.newSymbol(name, code,
......@@ -98,7 +98,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
">" { return symbol("GT",GT); }
"<" { return symbol("LT",LT); }
{Comment} { }
"{:" { sb = new StringBuffer(); csline=yyline+1; cscolumn=yycolumn+1; yybegin(CODESEG); }
"{:" { sb = new StringBuffer(); csline=yyline+1; cscolumn=yycolumn+1; csoffset=yychar; yybegin(CODESEG); }
"package" { return symbol("PACKAGE",PACKAGE); }
"import" { return symbol("IMPORT",IMPORT); }
"class" { return symbol("CLASS",CLASS); }
......@@ -123,7 +123,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
}
<CODESEG> {
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn),new Location(yyline+1,yycolumn+1+yylength()), sb.toString()); }
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn, csoffset),new Location(yyline+1,yycolumn+1+yylength(), csoffset+yylength()), sb.toString()); }
.|\n { sb.append(yytext()); }
}
......
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