use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.
the class NodeFactory method addParameterIdentifiersToLexicalScope.
private void addParameterIdentifiersToLexicalScope(List<FormalParameter> parameters) {
try {
int count = 0;
for (FormalParameter parameter : parameters) {
TypeDescriptor typeDescriptor = parameter.type;
if (typeDescriptor == null)
return;
if (parameter.isReference) {
FrameSlot frameSlot = this.currentLexicalScope.registerReferenceVariable(parameter.identifier, typeDescriptor);
final ReferenceInitializationNode initializationNode = new ReferenceInitializationNode(frameSlot, count++);
this.currentLexicalScope.addScopeInitializationNode(initializationNode);
} else {
this.currentLexicalScope.registerLocalVariable(parameter.identifier, typeDescriptor);
final ExpressionNode readNode = new ReadArgumentNode(count, parameters.get(count++).type);
final SimpleAssignmentNode assignment = this.createAssignmentNode(parameter.identifier, readNode);
this.currentLexicalScope.addScopeInitializationNode(assignment);
}
}
} catch (LexicalException e) {
parser.SemErr(e.getMessage());
}
}
use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.
the class NodeFactory method createSubroutineCall.
public ExpressionNode createSubroutineCall(Token identifierToken, List<ExpressionNode> params) {
String identifier = this.getIdentifierFromToken(identifierToken);
return this.doLookup(identifier, (LexicalScope foundInScope, String foundIdentifier) -> {
if (foundInScope.isSubroutine(foundIdentifier)) {
SubroutineDescriptor subroutineDescriptor = foundInScope.getSubroutineDescriptor(foundIdentifier, params);
subroutineDescriptor.verifyArguments(params);
return this.createInvokeNode(foundIdentifier, subroutineDescriptor, foundInScope, params);
} else {
throw new LexicalException(foundIdentifier + " is not a subroutine.");
}
});
}
use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.
the class NodeFactory method stepIntoRecordElementScope.
private FrameSlot stepIntoRecordElementScope(String recordIdentifier) throws LexicalException {
TypeDescriptor recordDescriptor = this.currentLexicalScope.getIdentifierDescriptor(recordIdentifier);
if (recordDescriptor == null || !(recordDescriptor instanceof RecordDescriptor)) {
throw new LexicalException("Not a record: " + recordIdentifier);
} else {
FrameSlot recordSlot = this.currentLexicalScope.getLocalSlot(recordIdentifier);
this.currentLexicalScope = ((RecordDescriptor) recordDescriptor).getLexicalScope();
return recordSlot;
}
}
use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.
the class LexicalScope method registerBuiltinSubroutine.
public void registerBuiltinSubroutine(String identifier, SubroutineDescriptor descriptor) {
try {
this.localIdentifiers.addSubroutine(identifier, descriptor);
PascalLanguage.INSTANCE.findContext().updateSubroutine(this.name, identifier, descriptor.getRootNode());
} catch (LexicalException e) {
throw new PascalRuntimeException("Could not register builtin subroutine: " + identifier);
}
}
use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.
the class LexicalScope method isReferenceParameter.
boolean isReferenceParameter(String identifier, int parameterIndex) throws LexicalException {
TypeDescriptor subroutineDescriptor = this.localIdentifiers.getIdentifierDescriptor(identifier);
if (!(subroutineDescriptor instanceof SubroutineDescriptor)) {
throw new LexicalException("Not a subroutine: " + identifier);
}
SubroutineDescriptor descriptor = (SubroutineDescriptor) subroutineDescriptor;
return descriptor.isReferenceParameter(parameterIndex);
}
Aggregations