pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/xtay2/recursive-descent-parser

hubassets.com/assets/primer-70be7debc79a8eff.css" /> GitHub - xtay2/recursive-descent-parser: Part of the context-compiler · GitHub
Skip to content

xtay2/recursive-descent-parser

Repository files navigation

Recursive descent-parser for Java jdk18+

Introduction

This parser is a part of the compiler for the language "Context". You can watch the progress in the weekly german devlog on Youtube.

Features

This is a linear LL(k)-parser with error-recovery which is able to transform a text into an abstract syntax tree (AST) based on the following rules:

Terminals


Name Short Description
Literal Matches a previously set string.
Section Matches anything between two previously specified characters.
Pattern Matches a specified Regex-Pattern.

NonTerminals


Name Short Description
Ordered Matches a bunch of rules in their specified order.
Unordered Matches all passed rules in any order.
Alteration Matches any one of the passed rules.
Multiple Matches the passed rule as many times as possible.
Optional Tries to match the passed rule or an empty string.
Lazy Matches the passed rule lazily to enable circular dependencies.

Example

This is the EBNF for a simple mathematical expression:

nr  := '-'? ('0' | ... | '9')+
op  := '+' | '-' | '*' | '/'
exp := nr (op nr)*

And this is the implementation with this library (the boolean-literal describes the optionality of the rule):

Rule nr  = new Pattern("-?[0-9]");
Rule op  = new Alteration(false, "+", "-", "*", "/");
Rule exp = new Ordered(nr, new Multiple(true, op, nr));

Now calling exp.tokenize("10 + -20 * 147") will yield the following tree:

"TokenArray": {
  "LiteralToken": "10",
  "TokenList": [
    "TokenArray": {
      "LiteralToken": "+",
      "LiteralToken": "-20"
    },
    "TokenArray": {
      "LiteralToken": "*",
      "LiteralToken": "147"
    }
  ]
}

Meanwhile calling exp.tokenize("10 xxx * 147") will result in:

"TokenArray": {
  "LiteralToken": "10",
  "TokenList": [
    "ErrorToken": "xxx", <-- Error
    "TokenArray": {
      "LiteralToken": "*",
      "LiteralToken": "147"
    }
  ]
}

Dependencies

This project requires:

Contributors

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy