A abstract parser engine generated by nitcc

Introduced properties

fun get_token: NToken

nitcc_runtime :: Parser :: get_token

Consume the next token
fun goto(goto: LRGoto)

nitcc_runtime :: Parser :: goto

After a reduction on goto go to the next state
fun node_stack: Array[Node]

nitcc_runtime :: Parser :: node_stack

The stack of nodes
protected fun node_stack=(node_stack: Array[Node])

nitcc_runtime :: Parser :: node_stack=

The stack of nodes
fun parse: Node

nitcc_runtime :: Parser :: parse

Parse a full sequence of tokens and return a complete syntactic tree
fun parse_error

nitcc_runtime :: Parser :: parse_error

Produce a parse error and stop the parsing
fun peek_token: NToken

nitcc_runtime :: Parser :: peek_token

Look at the next token
fun pop: Node

nitcc_runtime :: Parser :: pop

Pop and return the last node
fun push(dest: LRState)

nitcc_runtime :: Parser :: push

push a new state on the stack of states (
fun shift(dest: LRState)

nitcc_runtime :: Parser :: shift

Consume the next token and shift to the state dest.
protected abstract fun start_state: LRState

nitcc_runtime :: Parser :: start_state

The stating state for parsing
fun state: LRState

nitcc_runtime :: Parser :: state

The current state
protected fun state=(state: LRState)

nitcc_runtime :: Parser :: state=

The current state
fun state_stack: Array[LRState]

nitcc_runtime :: Parser :: state_stack

The stack of states
protected fun state_stack=(state_stack: Array[LRState])

nitcc_runtime :: Parser :: state_stack=

The stack of states
fun stop: Bool

nitcc_runtime :: Parser :: stop

Should the parser stop
fun stop=(stop: Bool)

nitcc_runtime :: Parser :: stop=

Should the parser stop
fun tokens: CircularArray[NToken]

nitcc_runtime :: Parser :: tokens

The list of tokens
protected fun tokens=(tokens: CircularArray[NToken])

nitcc_runtime :: Parser :: tokens=

The list of tokens

Redefined properties

redef type SELF: Parser

nitcc_runtime $ Parser :: SELF

Type of this instance, automatically specialized in every class
redef init init

nitcc_runtime $ Parser :: init

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun get_token: NToken

nitcc_runtime :: Parser :: get_token

Consume the next token
fun goto(goto: LRGoto)

nitcc_runtime :: Parser :: goto

After a reduction on goto go to the next state
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun node_stack: Array[Node]

nitcc_runtime :: Parser :: node_stack

The stack of nodes
protected fun node_stack=(node_stack: Array[Node])

nitcc_runtime :: Parser :: node_stack=

The stack of nodes
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parse: Node

nitcc_runtime :: Parser :: parse

Parse a full sequence of tokens and return a complete syntactic tree
fun parse_error

nitcc_runtime :: Parser :: parse_error

Produce a parse error and stop the parsing
fun peek_token: NToken

nitcc_runtime :: Parser :: peek_token

Look at the next token
fun pop: Node

nitcc_runtime :: Parser :: pop

Pop and return the last node
fun push(dest: LRState)

nitcc_runtime :: Parser :: push

push a new state on the stack of states (
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun shift(dest: LRState)

nitcc_runtime :: Parser :: shift

Consume the next token and shift to the state dest.
protected abstract fun start_state: LRState

nitcc_runtime :: Parser :: start_state

The stating state for parsing
fun state: LRState

nitcc_runtime :: Parser :: state

The current state
protected fun state=(state: LRState)

nitcc_runtime :: Parser :: state=

The current state
fun state_stack: Array[LRState]

nitcc_runtime :: Parser :: state_stack

The stack of states
protected fun state_stack=(state_stack: Array[LRState])

nitcc_runtime :: Parser :: state_stack=

The stack of states
fun stop: Bool

nitcc_runtime :: Parser :: stop

Should the parser stop
fun stop=(stop: Bool)

nitcc_runtime :: Parser :: stop=

Should the parser stop
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun tokens: CircularArray[NToken]

nitcc_runtime :: Parser :: tokens

The list of tokens
protected fun tokens=(tokens: CircularArray[NToken])

nitcc_runtime :: Parser :: tokens=

The list of tokens
package_diagram nitcc_runtime::Parser Parser core::Object Object nitcc_runtime::Parser->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitcc_runtime $ Parser
# A abstract parser engine generated by nitcc
abstract class Parser
	# The list of tokens
	# FIXME: provide something better, like a lexer?
	var tokens = new CircularArray[NToken]

	# Look at the next token
	# Used by generated parsers
	fun peek_token: NToken do return tokens.first

	# Consume the next token
	# Used by generated parsers
	fun get_token: NToken do return tokens.shift

	# Consume the next token and shift to the state `dest`.
	# Used by generated parsers
	fun shift(dest: LRState)
	do
		var t = get_token
		#print "shift {t} -> {dest}"
		node_stack.push t
		state_stack.push state
		state = dest
	end

	# After a reduction on `goto` go to the next state
	# Used by generated parsers
	fun goto(goto: LRGoto)
	do
		#print "reduce from {state} -> {prod}"
		state.goto(self, goto)
	end

	# push a new state on the stack of states (
	# Used by generated parsers
	fun push(dest: LRState)
	do
		#print "push prod {prod} -> {dest}"
		state_stack.push state
		state = dest
	end

	# Pop and return the last node
	# Also pop (and discard) the associated state
	# Used by generated parsers
	fun pop: Node
	do
		var res = node_stack.pop
		state = state_stack.pop
		return res
	end

	# Produce a parse error and stop the parsing
	# Used by generated parsers
	fun parse_error
	do
		var token = peek_token
		#print "* parse error in state {state} on token {token}"
		#print "  expected: {state.error_msg}"
		#print "  node_stack={node_stack.join(", ")}"
		#print "  state_stack={state_stack.join(", ")}"
		node_stack.push(token)
		var error: NError
		if token isa NLexerError then
			error = token
		else
			error = new NParserError
			error.position = token.position
			error.text = token.text
			error.token = token
		end
		error.error_tree.children.add_all(node_stack)
		error.expected = state.error_msg
		node_stack.clear
		node_stack.add error
		stop = true
	end

	# The stating state for parsing
	# Used by generated parsers
	protected fun start_state: LRState is abstract

	# The current state
	# Used by generated parsers
	var state: LRState is noinit

	init
	do
		state = start_state
	end

	# The stack of nodes
	# Used by generated parsers
	var node_stack = new Array[Node]

	# The stack of states
	# Used by generated parsers
	var state_stack = new Array[LRState]

	# Should the parser stop
	# Used by generated parsers
	var stop = true is writable

	# Parse a full sequence of tokens and return a complete syntactic tree
	fun parse: Node
	do
		state = start_state
		state_stack.clear
		node_stack.clear
		stop = false
		while not stop do
			#print "* current state {state}"
			#print "  tokens={tokens.join(" ")}"
			#print "  node_stack={node_stack.join(" ")}"
			#print "  state_stack={state_stack.join(" ")}"
			state.action(self)
		end
		#print "* over"
		return node_stack.first
	end
end
lib/nitcc_runtime/nitcc_runtime.nit:20,1--140,3