Beispiel #1
0
 public ArrayTypeNode(Token arrayKeywordNode, Token openBracketNode, ListNode<DelimitedItemNode<AstNode>> indexListNode, Token closeBracketNode, Token ofKeywordNode, AstNode typeNode)
 {
     _arrayKeywordNode = arrayKeywordNode;
     _openBracketNode = openBracketNode;
     _indexListNode = indexListNode;
     _closeBracketNode = closeBracketNode;
     _ofKeywordNode = ofKeywordNode;
     _typeNode = typeNode;
 }
Beispiel #2
0
 public AnonMethodHeadingNode(Token methodType, Token openParenthesis, ListNode<DelimitedItemNode<ParameterNode>> parameterList, Token closeParenthesis, Token colon, AstNode returnType)
 {
     MethodType = methodType;
     OpenParenthesis = openParenthesis;
     ParameterList = parameterList;
     CloseParenthesis = closeParenthesis;
     Colon = colon;
     ReturnType = returnType;
 }
Beispiel #3
0
        public Token NextToken()
        {
            while(_index < _source.Length && Char.IsWhiteSpace(_source[_index]))
                ++_index;
            if(_index >= _source.Length)
                return null;

            Match match = NextMatch();
            if(match == null)
                throw new LexException("Unrecognized character '" + _source[_index] + "'", Location);
            string text = _source.Substring(_index, match.Length);
            Token result = new Token(match.TokenType, Location, text, match.ParsedText);
            _index += match.Length;
            return result;
        }
Beispiel #4
0
 public virtual void VisitToken(Token token)
 {
 }
Beispiel #5
0
 public ConstantDeclNode(Token nameNode, Token colonNode, AstNode typeNode, Token equalSignNode, AstNode valueNode, ListNode<Token> portabilityDirectiveListNode, Token semicolonNode)
 {
     _nameNode = nameNode;
     _colonNode = colonNode;
     _typeNode = typeNode;
     _equalSignNode = equalSignNode;
     _valueNode = valueNode;
     _portabilityDirectiveListNode = portabilityDirectiveListNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #6
0
 public ClassOfNode(Token classKeywordNode, Token ofKeywordNode, AstNode typeNode)
 {
     _classKeywordNode = classKeywordNode;
     _ofKeywordNode = ofKeywordNode;
     _typeNode = typeNode;
 }
Beispiel #7
0
 public WhileStatementNode(Token whileKeywordNode, AstNode conditionNode, Token doKeywordNode, AstNode statementNode)
 {
     _whileKeywordNode = whileKeywordNode;
     _conditionNode = conditionNode;
     _doKeywordNode = doKeywordNode;
     _statementNode = statementNode;
 }
Beispiel #8
0
 public VarSectionNode(Token varKeywordNode, ListNode<VarDeclNode> varListNode)
 {
     _varKeywordNode = varKeywordNode;
     _varListNode = varListNode;
 }
Beispiel #9
0
 public VariantGroupNode(ListNode<DelimitedItemNode<AstNode>> valueListNode, Token colonNode, Token openParenthesisNode, ListNode<FieldDeclNode> fieldDeclListNode, VariantSectionNode variantSectionNode, Token closeParenthesisNode, Token semicolonNode)
 {
     _valueListNode = valueListNode;
     _colonNode = colonNode;
     _openParenthesisNode = openParenthesisNode;
     _fieldDeclListNode = fieldDeclListNode;
     _variantSectionNode = variantSectionNode;
     _closeParenthesisNode = closeParenthesisNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #10
0
 public TypeForwardDeclarationNode(Token nameNode, Token equalSignNode, Token typeNode, Token semicolonNode)
 {
     _nameNode = nameNode;
     _equalSignNode = equalSignNode;
     _typeNode = typeNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #11
0
 public TypeDeclNode(Token nameNode, Token equalSignNode, Token typeKeywordNode, AstNode typeNode, ListNode<Token> portabilityDirectiveListNode, Token semicolonNode)
 {
     _nameNode = nameNode;
     _equalSignNode = equalSignNode;
     _typeKeywordNode = typeKeywordNode;
     _typeNode = typeNode;
     _portabilityDirectiveListNode = portabilityDirectiveListNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #12
0
 public TryFinallyNode(Token tryKeywordNode, ListNode<DelimitedItemNode<AstNode>> tryStatementListNode, Token finallyKeywordNode, ListNode<DelimitedItemNode<AstNode>> finallyStatementListNode, Token endKeywordNode)
 {
     _tryKeywordNode = tryKeywordNode;
     _tryStatementListNode = tryStatementListNode;
     _finallyKeywordNode = finallyKeywordNode;
     _finallyStatementListNode = finallyStatementListNode;
     _endKeywordNode = endKeywordNode;
 }
Beispiel #13
0
        private IEnumerable <Token> HandleCompilerDirective(Stack <IfDefTruth> ifDefStack, Token token)
        {
            string directive = token.ParsedText;
            string firstWord = FirstWordOf(directive);
            string parameter = directive.Substring(firstWord.Length).Trim();

            switch (GetDirectiveType(firstWord))
            {
            case DirectiveType.Unrecognized:
                if (ifDefStack.Peek() == IfDefTruth.True)
                {
                    throw new LexException("Unrecognized compiler directive '" + firstWord + "'",
                                           token.Location);
                }
                break;

            case DirectiveType.Ignored:
                break;

            case DirectiveType.PossibleInclude:
                if (parameter.StartsWith("-") || parameter.StartsWith("+"))
                {
                    // $I = $IOCHECKS. Ignore it.
                    break;
                }
                else
                {
                    // $I = $INCLUDE. Handle it.
                    goto case DirectiveType.Include;
                }

            case DirectiveType.Include:
                IEnumerable <Token> sourceTokens   = GetSourceTokensForInclude(token, parameter);
                IEnumerable <Token> filteredTokens = Filter(ifDefStack, sourceTokens);
                foreach (Token newToken in filteredTokens)
                {
                    yield return(newToken);
                }
                break;

            case DirectiveType.Define:
                if (ifDefStack.Peek() == IfDefTruth.True)
                {
                    _compilerDefines.DefineSymbol(parameter);
                }
                break;

            case DirectiveType.Undefine:
                if (ifDefStack.Peek() == IfDefTruth.True)
                {
                    _compilerDefines.UndefineSymbol(parameter);
                }
                break;

            case DirectiveType.If:
                HandleIf(ifDefStack, directive, token.Location);
                break;

            case DirectiveType.Else:
                HandleElse(ifDefStack);
                break;

            case DirectiveType.ElseIf:
                HandleElseIf(ifDefStack, directive, token.Location);
                break;

            case DirectiveType.EndIf:
                ifDefStack.Pop();
                break;
            }
        }
Beispiel #14
0
 private IEnumerable<Token> GetSourceTokensForInclude(Token token, string baseName)
 {
     string currentDirectory = token.Location.Directory;
     string fileName = _fileLoader.ExpandFileName(currentDirectory, baseName);
     string source = _fileLoader.Load(fileName);
     Lexer lexer = new Lexer(source, fileName);
     return lexer.Tokens;
 }
Beispiel #15
0
 public TypeHelperNode(Token typeKeywordNode, Token helperSemikeywordNode, Token openParenthesisNode, AstNode baseHelperTypeNode, Token closeParenthesisNode, Token forKeywordNode, AstNode typeNode, ListNode<VisibilitySectionNode> contentListNode, Token endKeywordNode)
 {
     _typeKeywordNode = typeKeywordNode;
     _helperSemikeywordNode = helperSemikeywordNode;
     _openParenthesisNode = openParenthesisNode;
     _baseHelperTypeNode = baseHelperTypeNode;
     _closeParenthesisNode = closeParenthesisNode;
     _forKeywordNode = forKeywordNode;
     _typeNode = typeNode;
     _contentListNode = contentListNode;
     _endKeywordNode = endKeywordNode;
 }
Beispiel #16
0
 public virtual void VisitToken(Token token)
 {
 }
Beispiel #17
0
 public TypeSectionNode(Token typeKeywordNode, ListNode<AstNode> typeListNode)
 {
     _typeKeywordNode = typeKeywordNode;
     _typeListNode = typeListNode;
 }
Beispiel #18
0
 public VariantSectionNode(Token caseKeywordNode, Token nameNode, Token colonNode, AstNode typeNode, Token ofKeywordNode, ListNode<VariantGroupNode> variantGroupListNode)
 {
     _caseKeywordNode = caseKeywordNode;
     _nameNode = nameNode;
     _colonNode = colonNode;
     _typeNode = typeNode;
     _ofKeywordNode = ofKeywordNode;
     _variantGroupListNode = variantGroupListNode;
 }
Beispiel #19
0
 public CaseStatementNode(Token caseKeywordNode, AstNode expressionNode, Token ofKeywordNode, ListNode<CaseSelectorNode> selectorListNode, Token elseKeywordNode, ListNode<DelimitedItemNode<AstNode>> elseStatementListNode, Token endKeywordNode)
 {
     _caseKeywordNode = caseKeywordNode;
     _expressionNode = expressionNode;
     _ofKeywordNode = ofKeywordNode;
     _selectorListNode = selectorListNode;
     _elseKeywordNode = elseKeywordNode;
     _elseStatementListNode = elseStatementListNode;
     _endKeywordNode = endKeywordNode;
 }
Beispiel #20
0
 public VisibilityNode(Token strictSemikeywordNode, Token visibilityKeywordNode)
 {
     _strictSemikeywordNode = strictSemikeywordNode;
     _visibilityKeywordNode = visibilityKeywordNode;
 }
Beispiel #21
0
 public UnaryOperationNode(Token operatorNode, AstNode operandNode)
 {
     _operatorNode = operatorNode;
     _operandNode = operandNode;
 }
Beispiel #22
0
 public WithStatementNode(Token withKeywordNode, ListNode<DelimitedItemNode<AstNode>> expressionListNode, Token doKeywordNode, AstNode statementNode)
 {
     _withKeywordNode = withKeywordNode;
     _expressionListNode = expressionListNode;
     _doKeywordNode = doKeywordNode;
     _statementNode = statementNode;
 }
Beispiel #23
0
 public UnitNode(Token unitKeywordNode, Token unitNameNode, ListNode<Token> portabilityDirectiveListNode, Token semicolonNode, UnitSectionNode interfaceSectionNode, UnitSectionNode implementationSectionNode, InitSectionNode initSectionNode, Token dotNode)
 {
     _unitKeywordNode = unitKeywordNode;
     _unitNameNode = unitNameNode;
     _portabilityDirectiveListNode = portabilityDirectiveListNode;
     _semicolonNode = semicolonNode;
     _interfaceSectionNode = interfaceSectionNode;
     _implementationSectionNode = implementationSectionNode;
     _initSectionNode = initSectionNode;
     _dotNode = dotNode;
 }
Beispiel #24
0
 public ClassTypeNode(Token classKeywordNode, Token dispositionNode, Token openParenthesisNode, ListNode<DelimitedItemNode<AstNode>> inheritanceListNode, Token closeParenthesisNode, ListNode<VisibilitySectionNode> contentListNode, Token endKeywordNode)
 {
     _classKeywordNode = classKeywordNode;
     _dispositionNode = dispositionNode;
     _openParenthesisNode = openParenthesisNode;
     _inheritanceListNode = inheritanceListNode;
     _closeParenthesisNode = closeParenthesisNode;
     _contentListNode = contentListNode;
     _endKeywordNode = endKeywordNode;
 }
Beispiel #25
0
 public UnitSectionNode(Token headerKeywordNode, UsesClauseNode usesClauseNode, ListNode<AstNode> contentListNode)
 {
     _headerKeywordNode = headerKeywordNode;
     _usesClauseNode = usesClauseNode;
     _contentListNode = contentListNode;
 }
Beispiel #26
0
 public ConstantListNode(Token openParenthesisNode, ListNode<DelimitedItemNode<AstNode>> itemListNode, Token closeParenthesisNode)
 {
     _openParenthesisNode = openParenthesisNode;
     _itemListNode = itemListNode;
     _closeParenthesisNode = closeParenthesisNode;
 }
Beispiel #27
0
 public UsedUnitNode(AstNode nameNode, Token inKeywordNode, Token fileNameNode)
 {
     _nameNode = nameNode;
     _inKeywordNode = inKeywordNode;
     _fileNameNode = fileNameNode;
 }
Beispiel #28
0
 public virtual void VisitDelimitedItemNode(AstNode node, AstNode item, Token delimiter)
 {
     Visit(item);
     Visit(delimiter);
 }
Beispiel #29
0
 public UsesClauseNode(Token usesKeywordNode, ListNode<DelimitedItemNode<UsedUnitNode>> unitListNode, Token semicolonNode)
 {
     _usesKeywordNode = usesKeywordNode;
     _unitListNode = unitListNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #30
0
 public Frame(Token token)
 {
     _token = token;
 }
Beispiel #31
0
 public VarDeclNode(ListNode<DelimitedItemNode<Token>> nameListNode, Token colonNode, AstNode typeNode, ListNode<Token> firstPortabilityDirectiveListNode, Token absoluteSemikeywordNode, AstNode absoluteAddressNode, Token equalSignNode, AstNode valueNode, ListNode<Token> secondPortabilityDirectiveListNode, Token semicolonNode)
 {
     _nameListNode = nameListNode;
     _colonNode = colonNode;
     _typeNode = typeNode;
     _firstPortabilityDirectiveListNode = firstPortabilityDirectiveListNode;
     _absoluteSemikeywordNode = absoluteSemikeywordNode;
     _absoluteAddressNode = absoluteAddressNode;
     _equalSignNode = equalSignNode;
     _valueNode = valueNode;
     _secondPortabilityDirectiveListNode = secondPortabilityDirectiveListNode;
     _semicolonNode = semicolonNode;
 }
Beispiel #32
0
        private IEnumerable<Token> HandleCompilerDirective(Stack<IfDefTruth> ifDefStack, Token token)
        {
            string directive = token.ParsedText;
            string firstWord = FirstWordOf(directive);
            string parameter = directive.Substring(firstWord.Length).Trim();
            switch (GetDirectiveType(firstWord))
            {
                case DirectiveType.Unrecognized:
                    if (ifDefStack.Peek() == IfDefTruth.True)
                    {
                        throw new LexException("Unrecognized compiler directive '" + firstWord + "'",
                            token.Location);
                    }
                    break;

                case DirectiveType.Ignored:
                    break;

                case DirectiveType.PossibleInclude:
                    if (parameter.StartsWith("-") || parameter.StartsWith("+"))
                    {
                        // $I = $IOCHECKS. Ignore it.
                        break;
                    }
                    else
                    {
                        // $I = $INCLUDE. Handle it.
                        goto case DirectiveType.Include;
                    }

                case DirectiveType.Include:
                    IEnumerable<Token> sourceTokens = GetSourceTokensForInclude(token, parameter);
                    IEnumerable<Token> filteredTokens = Filter(ifDefStack, sourceTokens);
                    foreach (Token newToken in filteredTokens)
                        yield return newToken;
                    break;

                case DirectiveType.Define:
                    if (ifDefStack.Peek() == IfDefTruth.True)
                        _compilerDefines.DefineSymbol(parameter);
                    break;

                case DirectiveType.Undefine:
                    if (ifDefStack.Peek() == IfDefTruth.True)
                        _compilerDefines.UndefineSymbol(parameter);
                    break;

                case DirectiveType.If:
                    HandleIf(ifDefStack, directive, token.Location);
                    break;

                case DirectiveType.Else:
                    HandleElse(ifDefStack);
                    break;

                case DirectiveType.ElseIf:
                    HandleElseIf(ifDefStack, directive, token.Location);
                    break;

                case DirectiveType.EndIf:
                    ifDefStack.Pop();
                    break;
            }
        }
Beispiel #33
0
 public virtual void VisitDelimitedItemNode(AstNode node, AstNode item, Token delimiter)
 {
     Visit(item);
     Visit(delimiter);
 }