/** * O P E R A T O R S */ /// <summary> /// Carries out identification on an operation node /// </summary> /// <param name="operation">The node to perform identification on</param> private void PerformIdentificationOnOperator(OperatorNode operation) { IDeclarationNode declaration = SymbolTable.Retrieve(operation.OperatorToken.Spelling); operation.Declaration = declaration; if (declaration == null) { Reporter.ReportError($"{operation.Position} -> " + $"{operation.OperatorToken.Spelling} is not an operator"); } }
/** * I D E N T I F I E R */ /// <summary> /// Carries out identification on an identifier node /// </summary> /// <param name="identifier">The node to perform identification on</param> private void PerformIdentificationOnIdentifier(IdentifierNode identifier) { IDeclarationNode declaration = SymbolTable.Retrieve(identifier.IdentifierToken.Spelling); identifier.Declaration = declaration; if (declaration == null) { Reporter.ReportError($"{identifier.Position} -> " + $"{identifier.IdentifierToken.Spelling} has not been declared"); } }
/// <summary> /// Parses a let command /// </summary> private ICommandNode ParseLetCommand() { Debugger.Write("Parsing Let Command"); Position startPosition = CurrentToken.Position; Accept(TokenType.Let); IDeclarationNode declaration = ParseDeclaration(); Accept(TokenType.In); ICommandNode command = ParseSingleCommand(); return(new LetCommandNode(declaration, command, startPosition)); }
/// <summary> /// Carries out identification on an operation node /// </summary> /// <param name="operation">The node to perform identification on</param> private void PerformIdentificationOnOperator(OperatorNode operation) { IDeclarationNode declaration = SymbolTable.Retrieve(operation.OperatorToken.Spelling); if (declaration != null) { operation.Declaration = declaration; } else { IsItDirty(); Reporter.IdentifierErrorPositions.Add($"Error has occured here: {declaration.Position}, operation node is null"); } }
/// <summary> /// Carries out identification on an identifier node /// </summary> /// <param name="identifier">The node to perform identification on</param> private void PerformIdentificationOnIdentifier(IdentifierNode identifier) { IDeclarationNode declaration = SymbolTable.Retrieve(identifier.IdentifierToken.Spelling); if (declaration != null) { identifier.Declaration = declaration; } else { IsItDirty(); Reporter.IdentifierErrorPositions.Add($"Error has occured here: {identifier.Position}, identifier node is null"); } }
/// <summary> /// Enters a symbol in the table /// </summary> /// <param name="symbol">The symbol to enter</param> /// <param name="declaration">The declaration of the symbol</param> /// <returns>True if the symbol could be entered or false if an error occurred</returns> public bool Enter(string symbol, IDeclarationNode declaration) { Debugger.Write($"Adding {symbol} to the symbol table"); if (Scopes.Peek().ContainsKey(symbol)) { Debugger.Write($"{symbol} was already declared in the current scope"); return(true); } else { Scopes.Peek().Add(symbol, declaration); Debugger.Write($"Successfully added {symbol} to the current scope"); return(false); } }
private string TraverseDeclaration(IDeclarationNode declaration) { switch (declaration.Kind) { case DeclarationKind.Interface: return(TraverseInterface(declaration as JavaInterface)); case DeclarationKind.Class: return(TraverseClass(declaration as JavaClass)); case DeclarationKind.Field: return(TraverseField(declaration as JavaField)); case DeclarationKind.Ctor: return(TraverseCtor(declaration as CtorMethod)); case DeclarationKind.Method: return(TraverseMethod(declaration as JavaMethod)); } return(default(string)); }
/// <summary> /// Carries out identification on an operation node /// </summary> /// <param name="operation">The node to perform identification on</param> private void PerformIdentificationOnOperator(OperatorNode operation) { IDeclarationNode declaration = SymbolTable.Retrieve(operation.OperatorToken.Spelling); operation.Declaration = declaration; }
/// <summary> /// Carries out identification on an identifier node /// </summary> /// <param name="identifier">The node to perform identification on</param> private void PerformIdentificationOnIdentifier(IdentifierNode identifier) { IDeclarationNode declaration = SymbolTable.Retrieve(identifier.IdentifierToken.Spelling); identifier.Declaration = declaration; }
/// <summary> /// Creates a new let command node /// </summary> /// <param name="declaration">The declarations for the let block</param> /// <param name="command">The command inside the let block</param> /// <param name="position">The position in the code where the content associated with the node begins</param> public LetCommandNode(IDeclarationNode declaration, ICommandNode command, Position position) { Declaration = declaration; Command = command; Position = position; }