nitcc_runtime :: Parser :: _state_stack
The stack of statesnitcc_runtime :: Parser :: defaultinit
nitcc_runtime :: Parser :: goto
After a reduction ongoto
go to the next state
nitcc_runtime :: Parser :: node_stack=
The stack of nodesnitcc_runtime :: Parser :: parse
Parse a full sequence of tokens and return a complete syntactic treenitcc_runtime :: Parser :: shift
Consume the next token and shift to the statedest
.
nitcc_runtime :: Parser :: start_state
The stating state for parsingnitcc_runtime :: Parser :: state_stack=
The stack of statesnitcc_runtime :: Parser :: tokens=
The list of tokensnitcc_runtime $ Parser :: SELF
Type of this instance, automatically specialized in every classnitcc_runtime $ Parser :: init
nitcc_runtime :: Parser :: _state_stack
The stack of statescore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitcc_runtime :: Parser :: defaultinit
core :: Object :: defaultinit
nitcc_runtime :: Parser :: goto
After a reduction ongoto
go to the next state
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.nitcc_runtime :: Parser :: node_stack=
The stack of nodescore :: Object :: output_class_name
Display class name on stdout (debug only).nitcc_runtime :: Parser :: parse
Parse a full sequence of tokens and return a complete syntactic treenitcc_runtime :: Parser :: shift
Consume the next token and shift to the statedest
.
nitcc_runtime :: Parser :: start_state
The stating state for parsingnitcc_runtime :: Parser :: state_stack=
The stack of statesnitcc_runtime :: Parser :: tokens=
The list of tokens
# 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