Skip to content

Instantly share code, notes, and snippets.

import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
// Implement visitor
fun main(args: Array<String>) {
val stream = CharStreams.fromStream("1 + 1".byteInputStream())
val lexer = GrammarLexer(stream)
val tokens = CommonTokenStream(lexer)
val parser = GrammarParser(tokens)
interface Visitor<T> {
fun visitPlus(left: Expr, right: Expr): T
fun visitTimes(left: Expr, right: Expr): T
fun visitVar(name: String): T
fun visitNum(value: Double): T
}
interface Expr {
fun <T> accept(visitor: Visitor<T>): T
}
plugins {
kotlin("jvm") version "1.8.0"
application
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
import java.io.InputStream
const val ERROR_STATE = 0
const val EOF_SYMBOL = -1
const val SKIP_SYMBOL = 0
const val INT_SYMBOL = 1
const val VARIABLE_SYMBOL = 2
const val SEMI_SYMBOL = 3
const val PLUS_SYMBOL = 4
interface Regex {
fun isNullable(): Boolean
fun first(): Set<Int>
fun last(): Set<Int>
fun follow(): Set<Pair<Int, Int>>
fun chr(): Map<Int, Char>
}
class Union(private val left: Regex, private val right: Regex): Regex {
{"features":[{"geometry":{"coordinates":[[[1,1],[1.0415858940466054,1.081451606765279],[1.0908121449281685,1.1644103837934126],[1.146916458719871,1.2481140371595818],[1.2091365414968962,1.33180027293897],[1.276710099334426,1.414706797206759],[1.3488748383076432,1.4960713160381316],[1.42486846449173,1.5751315355082702],[1.5039286839618684,1.651125161692357],[1.585293202793241,1.723289900665574],[1.66819972706103,1.7908634585031038],[1.7518859628404182,1.853083541280129],[1.8355896162065877,1.909187855071832],[1.9185483932347207,1.9584141059533948],[2,2]],[[2,2],[2.015382797428333,1.9096941704434491],[2.045106254837051,1.8165743012339328],[2.087740813923373,1.722069950674228],[2.1418569163845214,1.6276106770671168],[2.2060250039177154,1.5346260387153765],[2.2788155182201777,1.4445455939217873],[2.358798900989128,1.3587989009891281],[2.444545593921788,1.2788155182201781],[2.534626038715377,1.2060250039177158],[2.627610677067117,1.1418569163845211],[2.7220699506742285,1.087740813923373],[2.816574301233932,1.04510
enum class Bool {
TRUE,
FALSE
}
enum class Direction {
NORTH,
SOUTH,
EAST,
WEST
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="binary">
<xsd:complexType>
<xsd:group ref="Binary" />
</xsd:complexType>
</xsd:element>
<xsd:group name="Binary">
<xsd:choice>
<xsd:element name="node" type="Node" />
<binary>
<node>
<node>
<leaf />
<value>1</value>
<leaf />
</node>
<value>2</value>
<node>
<leaf />
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="list">
<xsd:complexType>
<xsd:group ref="List" />
</xsd:complexType>
</xsd:element>
<xsd:group name="List">
<xsd:choice>
<xsd:element name="cell" type="Cell" />