Search in sources :

Example 1 with LexicalException

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());
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot)

Example 2 with LexicalException

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.");
        }
    });
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) SubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)

Example 3 with LexicalException

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;
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) RecordDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)

Example 4 with LexicalException

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);
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)

Example 5 with LexicalException

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);
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) ReturnTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor) EnumTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.EnumTypeDescriptor) SubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)

Aggregations

LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)13 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)9 PascalRuntimeException (cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException)3 SubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.SubroutineDescriptor)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 TypeTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeTypeDescriptor)2 EnumTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.EnumTypeDescriptor)2 ReturnTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)2 OrdinalDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.OrdinalDescriptor)1 PointerDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)1 RecordDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.compound.RecordDescriptor)1 AssignSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.AssignSubroutineDescriptor)1 RandomSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomSubroutineDescriptor)1 RandomizeSubroutineDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomizeSubroutineDescriptor)1