Go to file
2022-03-20 14:39:35 +01:00
examples [mod] example:logic 2022-03-20 14:39:35 +01:00
lib/plankton [upd] plankton 2021-09-19 01:57:14 +02:00
source [mod] cleanup 2021-09-19 01:57:25 +02:00
tools [add] readme 2022-03-19 19:23:38 +01:00
.gitignore [mod] update 2021-09-19 01:14:32 +02:00
readme.md [add] readme 2022-03-19 19:23:38 +01:00

Description

type2 is a slow, but versatile parser for context free languages (type 2 in the Chomsky hierarchy).

Being fed with a JSON file, specifying the language and a string via stdin, it decomposes the input, analyzes it and spits out its corresponding abstract syntax tree on stdout.

A typical call looks like this: type2 language.tp2.json < input.txt

Language specification

A language is specified by a JSON file containing a value of the following type:

record<
	lexer_rules:list<
		record<
			type:string,
			parameters:map<string,any>
		>
	>,
	parser_rules:list<
		record<
			label:string,
			premise:string,
			conclusion:list<
				record<
					type:string,
					parameters:map<string,any>
				>
			>
		>
	>,
	parser_start:string
>

The recommended extension for such files is .tp2.json.

Lexer rule types

type meaning parameters
ignore disregard matching strings pattern
void do not assign a value to matching strings pattern,id
boolean interpret matching strings as boolean values pattern,id,value
int interpret matching strings as integer number values pattern,id
float interpret matching strings as floating point number values pattern,id
string interpret matching strings as string values pattern,id

Conclusion element types

type meaning parameters
terminal id
variable id