Class AwkParser

java.lang.Object
org.metricshub.jawk.frontend.AwkParser

public class AwkParser extends Object
Converts the AWK script into a syntax tree, which is useful the backend that either compiles or interprets the script.

It contains the internal state of the parser and the lexer.

Author:
Danny Daglas
  • Constructor Details

    • AwkParser

      public AwkParser(Map<String,JawkExtension> extensions)

      Constructor for AwkParser.

      Parameters:
      extensions - a Map object
  • Method Details

    • parse

      public AstNode parse(List<ScriptSource> localScriptSources) throws IOException
      Parse the script streamed by script_reader. Build and return the root of the abstract syntax tree which represents the Jawk script.
      Parameters:
      localScriptSources - List of script sources
      Returns:
      The abstract syntax tree of this script.
      Throws:
      IOException - upon an IO error.
    • parseExpression

      public AstNode parseExpression(ScriptSource expressionSource) throws IOException
      Parse a single AWK expression and return the corresponding AST.
      Parameters:
      expressionSource - The expression to parse (not a statement or rule, just an expression)
      Returns:
      tuples representing the expression
      Throws:
      IOException - upon an IO error or parsing error
    • populateGlobalVariableNameToOffsetMappings

      public void populateGlobalVariableNameToOffsetMappings(AwkTuples tuples)
      Adds {varName -> offset} mappings to the tuples so that global variables can be set by the interpreter while processing filename and name=value entries from the command-line. Also sends function names to the tuples, to provide the back end with names to invalidate if name=value assignments are passed in via the -v or ARGV arguments.
      Parameters:
      tuples - The tuples to add the mapping to.