Class VerifySyntax

java.lang.Object
com.jugubell.bproccli.compiler.VerifySyntax

public class VerifySyntax extends Object
The class handling the syntax verification of the code.
Author:
Jugurtha Bellagh
  • Constructor Details

    • VerifySyntax

      public VerifySyntax(List<String> code)
      Constructor of VerifySyntax
      Parameters:
      code - a trimmed code from any comment or extra spaces as List of String
  • Method Details

    • getProgramMetadata

      public ProgramMetadata getProgramMetadata()
      Getting the calculated program metadata.
      Returns:
      program metadata as ProgramMetadata object.
    • getCode

      public List<String> getCode()
    • getCodeLineType

      public TreeMap<Integer,LineType> getCodeLineType()
    • isSyntaxCorrect

      public boolean isSyntaxCorrect()
      Method to verify the syntax correctness. It logs program metadata and Syntax OK, if true It logs error, place of the error, type of the error if not. It generates line type in a TreeMap with the same size as the code and stores it in codeLineType. The code is inspected line by line, and checks each line the corresponding line type with the method whatLine(String[]). Checks for allowed data range declaration. Checks for program and data ranges overlapping. Checks for label start syntax requirement Checks for duplicate labels Checks for duplicate data declaration Checks for general syntax guidelines. If there is an error, it will be aborted, and returns false, with error logs.
      Returns:
      boolean true if syntax is correct
    • isLabel

      public LineType isLabel(String[] label)
      Checks if the line is a label
      Parameters:
      label - the code line as String array
      Returns:
      a LineType as LABEL if true, otherwise SYNTAX_ERROR
    • isStart

      public LineType isStart(String[] str)
      Checks if the line is the label start:
      Parameters:
      str - the code line as a String array
      Returns:
      a LineType START, otherwise SYNTAX_ERROR
    • whatLine

      public LineType whatLine(String[] str)
      Returns what type of line of code is.
      Parameters:
      str - a code line as a String array
      Returns:
      a LineType according to the line type, otherwise SYNTAX_ERROR