Fixes to the type system and error handler.

This commit is contained in:
jeff.dyer%compilercompany.com 2000-12-06 18:27:42 +00:00
Родитель a910b65553
Коммит c8f0271f30
22 изменённых файлов: 268 добавлений и 164 удалений

Просмотреть файл

@ -933,11 +933,13 @@ public class JSILGenerator extends Evaluator implements Tokens {
}
Value evaluate( Context context, ProgramNode node ) throws Exception {
String tag = "Program";
emit(context.getIndent()+tag);
context.indent++;
node.statements.evaluate(context,this);
context.indent--;
if( node.statements != null ) {
String tag = "Program";
emit(context.getIndent()+tag);
context.indent++;
node.statements.evaluate(context,this);
context.indent--;
}
return null;
}
}

Просмотреть файл

@ -30,7 +30,7 @@ import java.io.*;
public class InputBuffer implements CharacterClasses {
private static final boolean debug = false;
private static final boolean debug_nextchar = false;
private static final boolean debug_nextchar = true;
private static final boolean debug_retract = false;
StringBuffer lineA = new StringBuffer();

Просмотреть файл

@ -39,6 +39,7 @@ public class Scanner implements Tokens, States, CharacterClasses {
private String codebase;
private boolean foundNewlineInComment;
private boolean isFirstTokenOnLine;
protected int errorCount = 0;
InputBuffer input;
@ -305,8 +306,8 @@ public class Scanner implements Tokens, States, CharacterClasses {
};
public final void error(int kind, String msg, int tokenid) {
errorCount++;
String loc = null;
int pos;
switch(kind) {
case lexical_error:
case lexical_lineterminatorinsinglequotedstringliteral_error:
@ -320,10 +321,9 @@ public class Scanner implements Tokens, States, CharacterClasses {
msg = msg==null?error_messages[kind]:msg;
break;
}
pos = loc.length()-1;
System.err.println(loc+msg);
System.err.println(input.getLineText(input.positionOfMark()));
System.err.println(getLinePointer(input.markCol));
System.err.println(getLinePointer(input.markCol-1));
skiperror(kind);
}
@ -376,10 +376,13 @@ public class Scanner implements Tokens, States, CharacterClasses {
}
}
case syntax_error:
err.println("Syntax error");
break;
default:
break;
while ( true ) {
char nc = nextchar();
if( nc == ';' || nc == '\n' || nc == 0 ) {
return;
}
}
}
} catch (Exception x) {
x.printStackTrace();

Просмотреть файл

@ -124,7 +124,7 @@ public class Main {
Node node;
Value type;
Evaluator evaluator;
Value value;
Value value = UndefinedValue.undefinedValue;
Class pc = Parser.class;
Class[] args = new Class[0];
@ -134,6 +134,8 @@ public class Main {
ObjectValue global = null;
int errorCount=0;
for( int i = 0; i < input.length; i++ ) {
try {
@ -161,32 +163,38 @@ public class Main {
System.gc();
t = System.currentTimeMillis();
node = parser.parseProgram();
if( traceParser ) {
Debugger.trace("setting parser output to " + input[i]);
JSILGenerator.setOut( input[i]+".par" );
node.evaluate(context,new JSILGenerator());
errorCount = parser.errorCount();
if( errorCount == 0 ) {
if( traceParser ) {
Debugger.trace("setting parser output to " + input[i]);
JSILGenerator.setOut( input[i]+".par" );
node.evaluate(context,new JSILGenerator());
}
//Evaluator evaluator;
context.setEvaluator(new BlockEvaluator());
node.evaluate(context, context.getEvaluator());
JSILGenerator.setOut( input[i]+".blocks" );
context.setEvaluator(new JSILGenerator());
node.evaluate(context, context.getEvaluator());
context.setEvaluator(new ConstantEvaluator());
value = node.evaluate(context, context.getEvaluator());
context.setEvaluator(new JSILGenerator());
JSILGenerator.setOut( input[i]+".jsil" );
node.evaluate(context, context.getEvaluator());
errorCount = context.errorCount();
}
//Evaluator evaluator;
context.setEvaluator(new BlockEvaluator());
node.evaluate(context, context.getEvaluator());
JSILGenerator.setOut( input[i]+".blocks" );
context.setEvaluator(new JSILGenerator());
node.evaluate(context, context.getEvaluator());
context.setEvaluator(new ConstantEvaluator());
value = node.evaluate(context, context.getEvaluator());
context.setEvaluator(new JSILGenerator());
JSILGenerator.setOut( input[i]+".jsil" );
node.evaluate(context, context.getEvaluator());
t = System.currentTimeMillis() - t;
//Debugger.trace(""+global);
System.out.println(input[i] + ": "+context.errorCount()+" errors [" + Long.toString(t) + " msec] --> " + value.getValue(context) );
System.out.println(input[i] + ": "+ errorCount +" errors [" + Long.toString(t) + " msec] --> " + value.getValue(context) );
} catch( Exception x ) {
x.printStackTrace();

Просмотреть файл

@ -31,7 +31,7 @@ public class Node {
private static final boolean debug = false;
Block block;
private int position;
int position;
public Node() {
}

Просмотреть файл

@ -79,7 +79,7 @@ public final class NodeFactory {
return new LiteralUndefinedNode();
}
static ParenthesizedExpressionNode ParenthesizedExpression( Node expr ) {
return new ParenthesizedExpressionNode(expr);
return new ParenthesizedExpressionNode(expr,in.positionOfMark());
}
static ParenthesizedListExpressionNode ParenthesizedListExpression( Node expr ) {
return new ParenthesizedListExpressionNode(expr);
@ -124,13 +124,13 @@ public final class NodeFactory {
return new CallExpressionNode(member,args);
}
static IndexedMemberExpressionNode IndexedMemberExpression( Node base, Node member ) {
return new IndexedMemberExpressionNode(base,member);
return new IndexedMemberExpressionNode(base,member,in.positionOfMark());
}
static MemberExpressionNode MemberExpression( Node base, Node name ) {
return new MemberExpressionNode(base,name);
return new MemberExpressionNode(base,name,in.positionOfMark());
}
static CoersionExpressionNode CoersionExpression( Node expr, Node type ) {
return new CoersionExpressionNode(expr,type);
return new CoersionExpressionNode(expr,type,in.positionOfMark());
}
static UnaryExpressionNode UnaryExpression( int op, Node expr ) {
return new UnaryExpressionNode(op,expr);

Просмотреть файл

@ -332,7 +332,8 @@ final class CoersionExpressionNode extends Node {
Node expr, type;
CoersionExpressionNode( Node expr, Node type ) {
CoersionExpressionNode( Node expr, Node type, int pos ) {
super(pos);
this.expr = expr;
this.type = type;
}
@ -953,7 +954,8 @@ final class IndexedMemberExpressionNode extends Node {
Node base, expr;
IndexedMemberExpressionNode( Node base, Node expr ) {
IndexedMemberExpressionNode( Node base, Node expr, int pos ) {
super(pos);
this.base = base;
this.expr = expr;
}
@ -1333,7 +1335,8 @@ final class MemberExpressionNode extends Node {
Node base, name;
MemberExpressionNode( Node base, Node name ) {
MemberExpressionNode( Node base, Node name, int pos ) {
super(pos);
this.base = base;
this.name = name;
}
@ -1494,7 +1497,8 @@ final class ParenthesizedExpressionNode extends Node {
Node expr;
public ParenthesizedExpressionNode( Node expr ) {
public ParenthesizedExpressionNode( Node expr, int pos ) {
super(pos);
this.expr = expr;
}

Просмотреть файл

@ -31,7 +31,7 @@ import java.lang.reflect.*;
public class Parser implements Tokens, Errors {
private static final boolean debug = false;
private static final boolean debug = true;
private static final boolean debug_lookahead = false;
private static final boolean debug_match = false;
@ -42,6 +42,7 @@ public class Parser implements Tokens, Errors {
private boolean isNewLine = false;
protected Vector statements = null;
protected Vector functions = null;
private int errors = 0;
public static PrintStream out;
public static void setOut(String filename) throws Exception {
@ -213,15 +214,12 @@ public class Parser implements Tokens, Errors {
int result = error_token;
if( !lookahead( expectedTokenClass ) )
scanner.error(scanner.syntax_error,"Expecting \'" + Token.getTokenClassName(expectedTokenClass) +
"\' before '" + scanner.getTokenSource(nexttoken),error_token);
/*
throw new Exception( "\nExpecting \'" + Token.getTokenClassName(expectedTokenClass) +
"\' before '" + scanner.getTokenSource(nexttoken) +
"' in the text '" + scanner.getLineText() + "'" );
*/
else
if( !lookahead( expectedTokenClass ) ) {
scanner.error(scanner.syntax_error,"Expecting " + Token.getTokenClassName(expectedTokenClass) +
" before " + scanner.getTokenSource(nexttoken),error_token);
nexttoken = empty_token;
throw new Exception("syntax error");
} else
if( expectedTokenClass != scanner.getTokenClass( nexttoken ) ) {
result = thistoken;
} else {
@ -379,6 +377,10 @@ public class Parser implements Tokens, Errors {
}
}
public int errorCount() {
return scanner.errorCount;
}
/**
* Start grammar.
*/
@ -408,6 +410,7 @@ public class Parser implements Tokens, Errors {
$$ = NodeFactory.Identifier(scanner.getTokenText(match(identifier_token)));
} else {
scanner.error(scanner.syntax_error,"Expecting an Identifier.");
throw new Exception();
}
if( debug ) {
@ -690,7 +693,7 @@ public class Parser implements Tokens, Errors {
} else {
scanner.error(scanner.syntax_error,"Expecting <primary expression> before '" +
scanner.getTokenSource(nexttoken),error_token);
$$ = null; // Make the compiler happy.
throw new Exception();
}
if( debug ) {
@ -757,9 +760,12 @@ public class Parser implements Tokens, Errors {
Node $$;
match( leftparen_token );
int mark = scanner.input.positionOfMark();
$$ = NodeFactory.ParenthesizedExpression(parseAssignmentExpression(allowIn_mode));
$$.position = mark;
match( rightparen_token );
if( debug ) {
@ -2114,7 +2120,9 @@ public class Parser implements Tokens, Errors {
match(class_token);
$$ = NodeFactory.ClassofExpression($1);
} else {
int mark = scanner.input.positionOfMark();
$2 = parseQualifiedIdentifier();
$2.position = mark;
$$ = NodeFactory.MemberExpression($1,$2);
}
@ -3348,9 +3356,11 @@ public class Parser implements Tokens, Errors {
Debugger.trace( "begin parseTopStatement" );
}
Node $$;
Node $$ = null;
if( lookahead(use_token) ) {
try {
if( lookahead(use_token) ) {
$$ = parseLanguageDeclaration();
matchNoninsertableSemicolon(mode);
} else if( lookahead(package_token) ) {
@ -3359,6 +3369,11 @@ public class Parser implements Tokens, Errors {
$$ = parseStatement(mode);
}
} catch ( Exception x ) {
// Do nothing. We are simply recovering from an error in the
// current statement.
}
if( debug ) {
Debugger.trace( "finish parseTopStatement" );
}
@ -4717,6 +4732,7 @@ public class Parser implements Tokens, Errors {
if( newline() ) {
scanner.error(scanner.syntax_error,"No line break in attributes list.");
throw new Exception();
}
$2 = parseAttributes();
@ -5366,6 +5382,7 @@ public class Parser implements Tokens, Errors {
if( newline() ) {
scanner.error(scanner.syntax_error,"No line break in multiple attributes definition.");
throw new Exception();
}
$1 = NodeFactory.List($1,parseAttribute());
@ -6648,12 +6665,17 @@ public class Parser implements Tokens, Errors {
Node $$;
$$ = NodeFactory.Program(parseTopStatements());
$$ = parseTopStatements();
if( debug ) {
Debugger.trace( "finish parseProgram" );
}
if( scanner.errorCount == 0 ) {
$$ = NodeFactory.Program($$);
} else {
$$ = NodeFactory.Program(null);
}
return $$;
}

Просмотреть файл

@ -876,9 +876,11 @@ public class BlockEvaluator extends Evaluator {
Debugger.trace( "defining ProgramNode: " + node );
}
node.statements.first().markLeader();
node.statements.evaluate(context,this);
context.exitBlock(node.statements.last());
if( node.statements != null ) {
node.statements.first().markLeader();
node.statements.evaluate(context,this);
context.exitBlock(node.statements.last());
}
return UndefinedValue.undefinedValue;
}

Просмотреть файл

@ -512,7 +512,7 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
ref = (ReferenceValue) value;
ref.scope = base;
} else {
error(context,0,"Expecting reference expression after dot operator.",node.pos());
error(context,0,"Expecting reference expression after dot operator.",node.name.pos());
}
return value;
@ -619,8 +619,7 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
Value expr = UndefinedValue.undefinedValue;
if( !TypeType.type.includes(typeValue) ) {
error(context,"A constant type expression expected on right hand side of coerce operator." +
typeValue,node.pos());
error(context,"A constant type expression expected on right hand side of coerce operator.",node.type.pos());
} else {
Value value;
expr = node.expr.evaluate(context,this);
@ -1957,8 +1956,8 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
// Put the new namespace into the current local scope.
Scope local = context.getLocal();
Slot slot = local.add(null,name);
Scope scope = context.getGlobal();
Slot slot = scope.add(null,name);
slot.type = NamespaceType.type;
slot.value = value;
slot.attrs = null; // ACTION: do attrs.
@ -1993,18 +1992,23 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
Scope scope;
Slot slot;
Vector prev_namespaces = used_namespaces;
used_namespaces = (Vector)prev_namespaces.clone();
if( node.statements != null ) {
scope = context.getGlobal();
slot = scope.add(null,"_code_");
slot.value = node.statements.evaluate(context,this);
slot.type = ObjectType.type;
slot.attrs = null; // ACTION: do attrs
Vector prev_namespaces = used_namespaces;
used_namespaces = (Vector)prev_namespaces.clone();
used_namespaces = prev_namespaces;
scope = context.getGlobal();
slot = scope.add(null,"_code_");
slot.value = node.statements.evaluate(context,this);
slot.type = ObjectType.type;
slot.attrs = null; // ACTION: do attrs
used_namespaces = prev_namespaces;
return slot.value;
} else {
return UndefinedValue.undefinedValue;
}
return slot.value;
}
/*

Просмотреть файл

@ -37,8 +37,7 @@ public class ObjectValue extends Value implements Attributes, Scope {
*
*/
Hashtable slots = new Hashtable();
Hashtable attributes = new Hashtable();
Hashtable slots = new Hashtable();
String name;
/**
@ -123,20 +122,28 @@ public class ObjectValue extends Value implements Attributes, Scope {
*/
public Slot get(Value namespace, String name) {
if( debug ) {
Debugger.trace("ObjectValue.get() namespace="+namespace+", name="+name);
}
Hashtable names;
Slot slot;
if( namespace == null ) {
names = slots;
slot = (Slot) slots.get(name);
} else {
names = (Hashtable) ((ObjectValue)slots.get(namespace)).slots;
ObjectValue names = (ObjectValue)slots.get(namespace);
if( names == null ) {
slot = null;
} else {
slot = (Slot) names.slots.get(name);
}
}
return (Slot) names.get(name);
return slot;
}
/**
*
* Add a name to a namespace and return the resulting slot.
*/
public Slot add(Value namespace, String name) throws Exception {

Просмотреть файл

@ -933,11 +933,13 @@ public class JSILGenerator extends Evaluator implements Tokens {
}
Value evaluate( Context context, ProgramNode node ) throws Exception {
String tag = "Program";
emit(context.getIndent()+tag);
context.indent++;
node.statements.evaluate(context,this);
context.indent--;
if( node.statements != null ) {
String tag = "Program";
emit(context.getIndent()+tag);
context.indent++;
node.statements.evaluate(context,this);
context.indent--;
}
return null;
}
}

Просмотреть файл

@ -30,7 +30,7 @@ import java.io.*;
public class InputBuffer implements CharacterClasses {
private static final boolean debug = false;
private static final boolean debug_nextchar = false;
private static final boolean debug_nextchar = true;
private static final boolean debug_retract = false;
StringBuffer lineA = new StringBuffer();

Просмотреть файл

@ -39,6 +39,7 @@ public class Scanner implements Tokens, States, CharacterClasses {
private String codebase;
private boolean foundNewlineInComment;
private boolean isFirstTokenOnLine;
protected int errorCount = 0;
InputBuffer input;
@ -305,8 +306,8 @@ public class Scanner implements Tokens, States, CharacterClasses {
};
public final void error(int kind, String msg, int tokenid) {
errorCount++;
String loc = null;
int pos;
switch(kind) {
case lexical_error:
case lexical_lineterminatorinsinglequotedstringliteral_error:
@ -320,10 +321,9 @@ public class Scanner implements Tokens, States, CharacterClasses {
msg = msg==null?error_messages[kind]:msg;
break;
}
pos = loc.length()-1;
System.err.println(loc+msg);
System.err.println(input.getLineText(input.positionOfMark()));
System.err.println(getLinePointer(input.markCol));
System.err.println(getLinePointer(input.markCol-1));
skiperror(kind);
}
@ -376,10 +376,13 @@ public class Scanner implements Tokens, States, CharacterClasses {
}
}
case syntax_error:
err.println("Syntax error");
break;
default:
break;
while ( true ) {
char nc = nextchar();
if( nc == ';' || nc == '\n' || nc == 0 ) {
return;
}
}
}
} catch (Exception x) {
x.printStackTrace();

Просмотреть файл

@ -124,7 +124,7 @@ public class Main {
Node node;
Value type;
Evaluator evaluator;
Value value;
Value value = UndefinedValue.undefinedValue;
Class pc = Parser.class;
Class[] args = new Class[0];
@ -134,6 +134,8 @@ public class Main {
ObjectValue global = null;
int errorCount=0;
for( int i = 0; i < input.length; i++ ) {
try {
@ -161,32 +163,38 @@ public class Main {
System.gc();
t = System.currentTimeMillis();
node = parser.parseProgram();
if( traceParser ) {
Debugger.trace("setting parser output to " + input[i]);
JSILGenerator.setOut( input[i]+".par" );
node.evaluate(context,new JSILGenerator());
errorCount = parser.errorCount();
if( errorCount == 0 ) {
if( traceParser ) {
Debugger.trace("setting parser output to " + input[i]);
JSILGenerator.setOut( input[i]+".par" );
node.evaluate(context,new JSILGenerator());
}
//Evaluator evaluator;
context.setEvaluator(new BlockEvaluator());
node.evaluate(context, context.getEvaluator());
JSILGenerator.setOut( input[i]+".blocks" );
context.setEvaluator(new JSILGenerator());
node.evaluate(context, context.getEvaluator());
context.setEvaluator(new ConstantEvaluator());
value = node.evaluate(context, context.getEvaluator());
context.setEvaluator(new JSILGenerator());
JSILGenerator.setOut( input[i]+".jsil" );
node.evaluate(context, context.getEvaluator());
errorCount = context.errorCount();
}
//Evaluator evaluator;
context.setEvaluator(new BlockEvaluator());
node.evaluate(context, context.getEvaluator());
JSILGenerator.setOut( input[i]+".blocks" );
context.setEvaluator(new JSILGenerator());
node.evaluate(context, context.getEvaluator());
context.setEvaluator(new ConstantEvaluator());
value = node.evaluate(context, context.getEvaluator());
context.setEvaluator(new JSILGenerator());
JSILGenerator.setOut( input[i]+".jsil" );
node.evaluate(context, context.getEvaluator());
t = System.currentTimeMillis() - t;
//Debugger.trace(""+global);
System.out.println(input[i] + ": "+context.errorCount()+" errors [" + Long.toString(t) + " msec] --> " + value.getValue(context) );
System.out.println(input[i] + ": "+ errorCount +" errors [" + Long.toString(t) + " msec] --> " + value.getValue(context) );
} catch( Exception x ) {
x.printStackTrace();

Просмотреть файл

@ -31,7 +31,7 @@ public class Node {
private static final boolean debug = false;
Block block;
private int position;
int position;
public Node() {
}

Просмотреть файл

@ -79,7 +79,7 @@ public final class NodeFactory {
return new LiteralUndefinedNode();
}
static ParenthesizedExpressionNode ParenthesizedExpression( Node expr ) {
return new ParenthesizedExpressionNode(expr);
return new ParenthesizedExpressionNode(expr,in.positionOfMark());
}
static ParenthesizedListExpressionNode ParenthesizedListExpression( Node expr ) {
return new ParenthesizedListExpressionNode(expr);
@ -124,13 +124,13 @@ public final class NodeFactory {
return new CallExpressionNode(member,args);
}
static IndexedMemberExpressionNode IndexedMemberExpression( Node base, Node member ) {
return new IndexedMemberExpressionNode(base,member);
return new IndexedMemberExpressionNode(base,member,in.positionOfMark());
}
static MemberExpressionNode MemberExpression( Node base, Node name ) {
return new MemberExpressionNode(base,name);
return new MemberExpressionNode(base,name,in.positionOfMark());
}
static CoersionExpressionNode CoersionExpression( Node expr, Node type ) {
return new CoersionExpressionNode(expr,type);
return new CoersionExpressionNode(expr,type,in.positionOfMark());
}
static UnaryExpressionNode UnaryExpression( int op, Node expr ) {
return new UnaryExpressionNode(op,expr);

Просмотреть файл

@ -332,7 +332,8 @@ final class CoersionExpressionNode extends Node {
Node expr, type;
CoersionExpressionNode( Node expr, Node type ) {
CoersionExpressionNode( Node expr, Node type, int pos ) {
super(pos);
this.expr = expr;
this.type = type;
}
@ -953,7 +954,8 @@ final class IndexedMemberExpressionNode extends Node {
Node base, expr;
IndexedMemberExpressionNode( Node base, Node expr ) {
IndexedMemberExpressionNode( Node base, Node expr, int pos ) {
super(pos);
this.base = base;
this.expr = expr;
}
@ -1333,7 +1335,8 @@ final class MemberExpressionNode extends Node {
Node base, name;
MemberExpressionNode( Node base, Node name ) {
MemberExpressionNode( Node base, Node name, int pos ) {
super(pos);
this.base = base;
this.name = name;
}
@ -1494,7 +1497,8 @@ final class ParenthesizedExpressionNode extends Node {
Node expr;
public ParenthesizedExpressionNode( Node expr ) {
public ParenthesizedExpressionNode( Node expr, int pos ) {
super(pos);
this.expr = expr;
}

Просмотреть файл

@ -31,7 +31,7 @@ import java.lang.reflect.*;
public class Parser implements Tokens, Errors {
private static final boolean debug = false;
private static final boolean debug = true;
private static final boolean debug_lookahead = false;
private static final boolean debug_match = false;
@ -42,6 +42,7 @@ public class Parser implements Tokens, Errors {
private boolean isNewLine = false;
protected Vector statements = null;
protected Vector functions = null;
private int errors = 0;
public static PrintStream out;
public static void setOut(String filename) throws Exception {
@ -213,15 +214,12 @@ public class Parser implements Tokens, Errors {
int result = error_token;
if( !lookahead( expectedTokenClass ) )
scanner.error(scanner.syntax_error,"Expecting \'" + Token.getTokenClassName(expectedTokenClass) +
"\' before '" + scanner.getTokenSource(nexttoken),error_token);
/*
throw new Exception( "\nExpecting \'" + Token.getTokenClassName(expectedTokenClass) +
"\' before '" + scanner.getTokenSource(nexttoken) +
"' in the text '" + scanner.getLineText() + "'" );
*/
else
if( !lookahead( expectedTokenClass ) ) {
scanner.error(scanner.syntax_error,"Expecting " + Token.getTokenClassName(expectedTokenClass) +
" before " + scanner.getTokenSource(nexttoken),error_token);
nexttoken = empty_token;
throw new Exception("syntax error");
} else
if( expectedTokenClass != scanner.getTokenClass( nexttoken ) ) {
result = thistoken;
} else {
@ -379,6 +377,10 @@ public class Parser implements Tokens, Errors {
}
}
public int errorCount() {
return scanner.errorCount;
}
/**
* Start grammar.
*/
@ -408,6 +410,7 @@ public class Parser implements Tokens, Errors {
$$ = NodeFactory.Identifier(scanner.getTokenText(match(identifier_token)));
} else {
scanner.error(scanner.syntax_error,"Expecting an Identifier.");
throw new Exception();
}
if( debug ) {
@ -690,7 +693,7 @@ public class Parser implements Tokens, Errors {
} else {
scanner.error(scanner.syntax_error,"Expecting <primary expression> before '" +
scanner.getTokenSource(nexttoken),error_token);
$$ = null; // Make the compiler happy.
throw new Exception();
}
if( debug ) {
@ -757,9 +760,12 @@ public class Parser implements Tokens, Errors {
Node $$;
match( leftparen_token );
int mark = scanner.input.positionOfMark();
$$ = NodeFactory.ParenthesizedExpression(parseAssignmentExpression(allowIn_mode));
$$.position = mark;
match( rightparen_token );
if( debug ) {
@ -2114,7 +2120,9 @@ public class Parser implements Tokens, Errors {
match(class_token);
$$ = NodeFactory.ClassofExpression($1);
} else {
int mark = scanner.input.positionOfMark();
$2 = parseQualifiedIdentifier();
$2.position = mark;
$$ = NodeFactory.MemberExpression($1,$2);
}
@ -3348,9 +3356,11 @@ public class Parser implements Tokens, Errors {
Debugger.trace( "begin parseTopStatement" );
}
Node $$;
Node $$ = null;
if( lookahead(use_token) ) {
try {
if( lookahead(use_token) ) {
$$ = parseLanguageDeclaration();
matchNoninsertableSemicolon(mode);
} else if( lookahead(package_token) ) {
@ -3359,6 +3369,11 @@ public class Parser implements Tokens, Errors {
$$ = parseStatement(mode);
}
} catch ( Exception x ) {
// Do nothing. We are simply recovering from an error in the
// current statement.
}
if( debug ) {
Debugger.trace( "finish parseTopStatement" );
}
@ -4717,6 +4732,7 @@ public class Parser implements Tokens, Errors {
if( newline() ) {
scanner.error(scanner.syntax_error,"No line break in attributes list.");
throw new Exception();
}
$2 = parseAttributes();
@ -5366,6 +5382,7 @@ public class Parser implements Tokens, Errors {
if( newline() ) {
scanner.error(scanner.syntax_error,"No line break in multiple attributes definition.");
throw new Exception();
}
$1 = NodeFactory.List($1,parseAttribute());
@ -6648,12 +6665,17 @@ public class Parser implements Tokens, Errors {
Node $$;
$$ = NodeFactory.Program(parseTopStatements());
$$ = parseTopStatements();
if( debug ) {
Debugger.trace( "finish parseProgram" );
}
if( scanner.errorCount == 0 ) {
$$ = NodeFactory.Program($$);
} else {
$$ = NodeFactory.Program(null);
}
return $$;
}

Просмотреть файл

@ -876,9 +876,11 @@ public class BlockEvaluator extends Evaluator {
Debugger.trace( "defining ProgramNode: " + node );
}
node.statements.first().markLeader();
node.statements.evaluate(context,this);
context.exitBlock(node.statements.last());
if( node.statements != null ) {
node.statements.first().markLeader();
node.statements.evaluate(context,this);
context.exitBlock(node.statements.last());
}
return UndefinedValue.undefinedValue;
}

Просмотреть файл

@ -512,7 +512,7 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
ref = (ReferenceValue) value;
ref.scope = base;
} else {
error(context,0,"Expecting reference expression after dot operator.",node.pos());
error(context,0,"Expecting reference expression after dot operator.",node.name.pos());
}
return value;
@ -619,8 +619,7 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
Value expr = UndefinedValue.undefinedValue;
if( !TypeType.type.includes(typeValue) ) {
error(context,"A constant type expression expected on right hand side of coerce operator." +
typeValue,node.pos());
error(context,"A constant type expression expected on right hand side of coerce operator.",node.type.pos());
} else {
Value value;
expr = node.expr.evaluate(context,this);
@ -1957,8 +1956,8 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
// Put the new namespace into the current local scope.
Scope local = context.getLocal();
Slot slot = local.add(null,name);
Scope scope = context.getGlobal();
Slot slot = scope.add(null,name);
slot.type = NamespaceType.type;
slot.value = value;
slot.attrs = null; // ACTION: do attrs.
@ -1993,18 +1992,23 @@ public class ConstantEvaluator extends Evaluator implements Tokens, Attributes {
Scope scope;
Slot slot;
Vector prev_namespaces = used_namespaces;
used_namespaces = (Vector)prev_namespaces.clone();
if( node.statements != null ) {
scope = context.getGlobal();
slot = scope.add(null,"_code_");
slot.value = node.statements.evaluate(context,this);
slot.type = ObjectType.type;
slot.attrs = null; // ACTION: do attrs
Vector prev_namespaces = used_namespaces;
used_namespaces = (Vector)prev_namespaces.clone();
used_namespaces = prev_namespaces;
scope = context.getGlobal();
slot = scope.add(null,"_code_");
slot.value = node.statements.evaluate(context,this);
slot.type = ObjectType.type;
slot.attrs = null; // ACTION: do attrs
used_namespaces = prev_namespaces;
return slot.value;
} else {
return UndefinedValue.undefinedValue;
}
return slot.value;
}
/*

Просмотреть файл

@ -37,8 +37,7 @@ public class ObjectValue extends Value implements Attributes, Scope {
*
*/
Hashtable slots = new Hashtable();
Hashtable attributes = new Hashtable();
Hashtable slots = new Hashtable();
String name;
/**
@ -123,20 +122,28 @@ public class ObjectValue extends Value implements Attributes, Scope {
*/
public Slot get(Value namespace, String name) {
if( debug ) {
Debugger.trace("ObjectValue.get() namespace="+namespace+", name="+name);
}
Hashtable names;
Slot slot;
if( namespace == null ) {
names = slots;
slot = (Slot) slots.get(name);
} else {
names = (Hashtable) ((ObjectValue)slots.get(namespace)).slots;
ObjectValue names = (ObjectValue)slots.get(namespace);
if( names == null ) {
slot = null;
} else {
slot = (Slot) names.slots.get(name);
}
}
return (Slot) names.get(name);
return slot;
}
/**
*
* Add a name to a namespace and return the resulting slot.
*/
public Slot add(Value namespace, String name) throws Exception {