Search in sources :

Example 6 with LexicalException

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

the class NodeFactory method registerRecordVariantTagVariable.

public void registerRecordVariantTagVariable(Token identifierToken, Token typeToken) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor type = this.getTypeDescriptor(typeToken);
    if (!(type instanceof OrdinalDescriptor)) {
        parser.SemErr("Record variant selector must be of ordinal type");
    }
    try {
        currentLexicalScope.registerLocalVariable(identifier, type);
    } 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) OrdinalDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.OrdinalDescriptor)

Example 7 with LexicalException

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

the class StringBuiltinUnit method importTo.

@Override
public void importTo(UnitLexicalScope scope) {
    super.importTo(scope);
    try {
        scope.registerType("pchar", new PointerDescriptor(PCharDesriptor.getInstance()));
    } catch (LexicalException e) {
        throw new PascalRuntimeException("Could not import string unit: " + e.getMessage());
    }
    scope.markAllIdentifiersPublic();
}
Also used : LexicalException(cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException) PascalRuntimeException(cz.cuni.mff.d3s.trupple.language.runtime.exceptions.PascalRuntimeException) PointerDescriptor(cz.cuni.mff.d3s.trupple.parser.identifierstable.types.complex.PointerDescriptor)

Example 8 with LexicalException

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

the class LexicalScope method isSubroutineParameter.

boolean isSubroutineParameter(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.isSubroutineParameter(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)

Example 9 with LexicalException

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

the class NodeFactory method addUnitFunctionInterface.

public void addUnitFunctionInterface(Token identifierToken, List<FormalParameter> formalParameters, Token returnTypeToken) {
    String identifier = this.getIdentifierFromToken(identifierToken);
    TypeDescriptor returnTypeDescriptor = this.getTypeDescriptor(returnTypeToken);
    try {
        currentLexicalScope.forwardFunction(identifier, formalParameters, returnTypeDescriptor);
    } 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 10 with LexicalException

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

the class IdentifiersTable method addFunctionInterfaceIfNotForwarded.

public void addFunctionInterfaceIfNotForwarded(String identifier, List<FormalParameter> formalParameters, TypeDescriptor returnType) throws LexicalException {
    TypeDescriptor descriptor = this.identifiersMap.get(identifier);
    if (descriptor != null) {
        if (!(descriptor instanceof FunctionDescriptor)) {
            throw new LexicalException("Not a subroutine");
        } else {
            if (!SubroutineDescriptor.compareFormalParametersExact(((SubroutineDescriptor) descriptor).getFormalParameters(), formalParameters)) {
                throw new LexicalException("Argument types mismatch");
            }
        }
        return;
    }
    this.forwardFunction(identifier, formalParameters, returnType);
}
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)

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