Search in sources :

Example 11 with LexicalException

use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.

the class IdentifiersTable method addProcedureInterfaceIfNotForwarded.

public void addProcedureInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters) throws LexicalException {
    TypeDescriptor descriptor = this.identifiersMap.get(identifier);
    if (descriptor != null) {
        if (!(descriptor instanceof ProcedureDescriptor)) {
            throw new LexicalException("Not a subroutine");
        } else {
            if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
                throw new LexicalException("Argument types mismatch");
            }
        }
        return;
    }
    this.forwardProcedure(identifier, formalParameters);
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) TypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor) TypeTypeDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeTypeDescriptor)

Example 12 with LexicalException

use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.

the class NodeFactory method startUnitFunctionImplementation.

public void startUnitFunctionImplementation(FunctionHeading heading) {
    String identifier = this.getIdentifierFromToken(heading.identifierToken);
    TypeDescriptor returnTypeDescriptor = heading.returnTypeDescriptor;
    try {
        if (currentLexicalScope.containsLocalIdentifier(identifier) && !currentLexicalScope.isSubroutine(identifier)) {
            parser.SemErr("Cannot implement. Not a function: " + identifier);
        } else if (!currentLexicalScope.containsLocalIdentifier(identifier)) {
            currentLexicalScope.forwardFunction(identifier, heading.formalParameters, returnTypeDescriptor);
        }
        currentLexicalScope = new LexicalScope(currentLexicalScope, identifier, parser.isUsingTPExtension());
        currentLexicalScope.registerReturnVariable(currentLexicalScope.getName(), returnTypeDescriptor);
        this.addParameterIdentifiersToLexicalScope(heading.formalParameters);
    } 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)

Example 13 with LexicalException

use of cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException in project TrufflePascal by Aspect26.

the class IdentifiersTableTP method addBuiltinFunctions.

@Override
protected void addBuiltinFunctions() {
    super.addBuiltinFunctions();
    try {
        this.registerNewIdentifier("random", new RandomSubroutineDescriptor());
        this.registerNewIdentifier("randomize", new RandomizeSubroutineDescriptor());
        this.registerNewIdentifier("assign", new AssignSubroutineDescriptor());
    } catch (LexicalException e) {
        throw new PascalRuntimeException("Could not initialize extension builtin functions: " + e.getMessage());
    }
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) AssignSubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.AssignSubroutineDescriptor) RandomSubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomSubroutineDescriptor) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException) RandomizeSubroutineDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.builtin.RandomizeSubroutineDescriptor)

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