Covfefe is a parser framework for languages generated by any (deterministic or nondeterministic) context free grammar.
It implements the Earley and CYK algorithm.
Usage
Swift Package Dependency in Xcode
Go to “File” > “Swift Packages” > “Add Package Dependency…”
Alternatively, it can be added as a dependency via CocoaPods (iOS, tvOS, watchOS and macOS).
target 'Your-App-Name' do
use_frameworks!
pod 'Covfefe', '~> 0.6.1'
end
Example
Grammars can be specified in a superset of EBNF or a superset of BNF, which adopts some features of EBNF (documented here).
Alternatively, ABNF is supported.
This grammar describes simple mathematical expressions consisting of unary and binary operations and parentheses.
A syntax tree can be generated, which describes how a given word was derived from the grammar above:
let parser = EarleyParser(grammar: grammar)
let syntaxTree = try parser.syntaxTree(for: "(a+b)*(-c)")
For a more complete example, i.e. how to evaluate syntax tree, check out ExpressionSolver.
Covfefe
Covfefe is a parser framework for languages generated by any (deterministic or nondeterministic) context free grammar. It implements the Earley and CYK algorithm.
Usage
Swift Package Dependency in Xcode
Swift Package Manager
This framework can be imported as a Swift Package by adding it as a dependency to the
Package.swift
file:CocoaPods
Alternatively, it can be added as a dependency via CocoaPods (iOS, tvOS, watchOS and macOS).
Example
Grammars can be specified in a superset of EBNF or a superset of BNF, which adopts some features of EBNF (documented here). Alternatively, ABNF is supported.
This grammar describes simple mathematical expressions consisting of unary and binary operations and parentheses. A syntax tree can be generated, which describes how a given word was derived from the grammar above:
For a more complete example, i.e. how to evaluate syntax tree, check out ExpressionSolver.