- # Get a token, or null if it is discarded
- private fun get_token: nullable Token
- do
- var dfa_state = 0
-
- var start_pos = _pos
- var start_line = _line
-
- var accept_state = -1
- var accept_token = -1
- var accept_length = -1
- var accept_pos = -1
- var accept_line = -1
-
- var goto_table = _goto_table[_state]
- var accept = _accept_table[_state]
- var text = _text
- text.clear
-
- loop
- var c = get_char
-
- if c != -1 then
- var cr = _cr
- var line = _line
- var pos = _pos
- if c == 10 then
- if cr then
- cr = false
- else
- line = line + 1
- pos = 0
- end
- else if c == 13 then
- line = line + 1
- pos = 0
- cr = true
- else
- pos = pos + 1
- cr = false
- end
-
- text.add(c.ascii)
-
- loop
- var old_state = dfa_state
- if dfa_state < -1 then
- old_state = -2 - dfa_state
- end
-
- dfa_state = -1
-
- var tmp0 = goto_table[old_state]
- var low = 0
- var high = tmp0.length - 1
-
- if high >= 0 then
- var tmp1 = tmp0.intern_items
- while low <= high do
- var middle = (low + high) / 2
- var tmp2 = tmp1[middle].intern_items
-
- if c < tmp2[0] then
- high = middle - 1
- else if c > tmp2[1] then
- low = middle + 1
- else
- dfa_state = tmp2[2]
- break
- end
- end
- end
- if dfa_state > -2 then break
- end
-
- _cr = cr
- _line = line
- _pos = pos
- else
- dfa_state = -1
- end
-
- if dfa_state >= 0 then
- if accept[dfa_state] != -1 then
- accept_state = dfa_state
- accept_token = accept[dfa_state]
- accept_length = text.length
- accept_pos = _pos
- accept_line = _line
- end
- else
- if accept_state != -1 then
- var location = new Location(_filename, start_line + 1, accept_line + 1, start_pos + 1, accept_pos)
- _pos = accept_pos
- _line = accept_line
- push_back(accept_length)
- if accept_token == 0 then
- return null
- end
- if accept_token == 1 then
- var token_text = text.substring(0, accept_length)
- return new TEol.init_tk(token_text, location)
- end
- if accept_token == 2 then
- var token_text = text.substring(0, accept_length)
- return new TComment.init_tk(token_text, location)
- end
- if accept_token == 3 then
- return new TKwpackage.init_tk(location)
- end
- if accept_token == 4 then
- return new TKwimport.init_tk(location)
- end
- if accept_token == 5 then
- return new TKwclass.init_tk(location)
- end
- if accept_token == 6 then
- return new TKwabstract.init_tk(location)
- end
- if accept_token == 7 then
- return new TKwinterface.init_tk(location)
- end
- if accept_token == 8 then
- return new TKwuniversal.init_tk(location)
- end
- if accept_token == 9 then
- return new TKwspecial.init_tk(location)
- end
- if accept_token == 10 then
- return new TKwend.init_tk(location)
- end
- if accept_token == 11 then
- return new TKwmeth.init_tk(location)
- end
- if accept_token == 12 then
- return new TKwtype.init_tk(location)
- end
- if accept_token == 13 then
- return new TKwinit.init_tk(location)
- end
- if accept_token == 14 then
- return new TKwredef.init_tk(location)
- end
- if accept_token == 15 then
- return new TKwis.init_tk(location)
- end
- if accept_token == 16 then
- return new TKwdo.init_tk(location)
- end
- if accept_token == 17 then
- return new TKwreadable.init_tk(location)
- end
- if accept_token == 18 then
- return new TKwwritable.init_tk(location)
- end
- if accept_token == 19 then
- return new TKwvar.init_tk(location)
- end
- if accept_token == 20 then
- return new TKwintern.init_tk(location)
- end
- if accept_token == 21 then
- return new TKwextern.init_tk(location)
- end
- if accept_token == 22 then
- return new TKwprotected.init_tk(location)
- end
- if accept_token == 23 then
- return new TKwprivate.init_tk(location)
- end
- if accept_token == 24 then
- return new TKwintrude.init_tk(location)
- end
- if accept_token == 25 then
- return new TKwif.init_tk(location)
- end
- if accept_token == 26 then
- return new TKwthen.init_tk(location)
- end
- if accept_token == 27 then
- return new TKwelse.init_tk(location)
- end
- if accept_token == 28 then
- return new TKwwhile.init_tk(location)
- end
- if accept_token == 29 then
- return new TKwloop.init_tk(location)
- end
- if accept_token == 30 then
- return new TKwfor.init_tk(location)
- end
- if accept_token == 31 then
- return new TKwin.init_tk(location)
- end
- if accept_token == 32 then
- return new TKwand.init_tk(location)
- end
- if accept_token == 33 then
- return new TKwor.init_tk(location)
- end
- if accept_token == 34 then
- return new TKwnot.init_tk(location)
- end
- if accept_token == 35 then
- return new TKwreturn.init_tk(location)
- end
- if accept_token == 36 then
- return new TKwcontinue.init_tk(location)
- end
- if accept_token == 37 then
- return new TKwbreak.init_tk(location)
- end
- if accept_token == 38 then
- return new TKwabort.init_tk(location)
- end
- if accept_token == 39 then
- return new TKwassert.init_tk(location)
- end
- if accept_token == 40 then
- return new TKwnew.init_tk(location)
- end
- if accept_token == 41 then
- return new TKwisa.init_tk(location)
- end
- if accept_token == 42 then
- return new TKwonce.init_tk(location)
- end
- if accept_token == 43 then
- return new TKwsuper.init_tk(location)
- end
- if accept_token == 44 then
- return new TKwself.init_tk(location)
- end
- if accept_token == 45 then
- return new TKwtrue.init_tk(location)
- end
- if accept_token == 46 then
- return new TKwfalse.init_tk(location)
- end
- if accept_token == 47 then
- return new TKwnull.init_tk(location)
- end
- if accept_token == 48 then
- return new TKwas.init_tk(location)
- end
- if accept_token == 49 then
- return new TKwnullable.init_tk(location)
- end
- if accept_token == 50 then
- return new TKwisset.init_tk(location)
- end
- if accept_token == 51 then
- return new TKwlabel.init_tk(location)
- end
- if accept_token == 52 then
- return new TOpar.init_tk(location)
- end
- if accept_token == 53 then
- return new TCpar.init_tk(location)
- end
- if accept_token == 54 then
- return new TObra.init_tk(location)
- end
- if accept_token == 55 then
- return new TCbra.init_tk(location)
- end
- if accept_token == 56 then
- return new TComma.init_tk(location)
- end
- if accept_token == 57 then
- return new TColumn.init_tk(location)
- end
- if accept_token == 58 then
- return new TQuad.init_tk(location)
- end
- if accept_token == 59 then
- return new TAssign.init_tk(location)
- end
- if accept_token == 60 then
- return new TPluseq.init_tk(location)
- end
- if accept_token == 61 then
- return new TMinuseq.init_tk(location)
- end
- if accept_token == 62 then
- return new TDotdotdot.init_tk(location)
- end
- if accept_token == 63 then
- return new TDotdot.init_tk(location)
- end
- if accept_token == 64 then
- return new TDot.init_tk(location)
- end
- if accept_token == 65 then
- return new TPlus.init_tk(location)
- end
- if accept_token == 66 then
- return new TMinus.init_tk(location)
- end
- if accept_token == 67 then
- return new TStar.init_tk(location)
- end
- if accept_token == 68 then
- return new TSlash.init_tk(location)
- end
- if accept_token == 69 then
- return new TPercent.init_tk(location)
- end
- if accept_token == 70 then
- return new TEq.init_tk(location)
- end
- if accept_token == 71 then
- return new TNe.init_tk(location)
- end
- if accept_token == 72 then
- return new TLt.init_tk(location)
- end
- if accept_token == 73 then
- return new TLe.init_tk(location)
- end
- if accept_token == 74 then
- return new TGt.init_tk(location)
- end
- if accept_token == 75 then
- return new TGe.init_tk(location)
- end
- if accept_token == 76 then
- return new TStarship.init_tk(location)
- end
- if accept_token == 77 then
- return new TBang.init_tk(location)
- end
- if accept_token == 78 then
- var token_text = text.substring(0, accept_length)
- return new TClassid.init_tk(token_text, location)
- end
- if accept_token == 79 then
- var token_text = text.substring(0, accept_length)
- return new TId.init_tk(token_text, location)
- end
- if accept_token == 80 then
- var token_text = text.substring(0, accept_length)
- return new TAttrid.init_tk(token_text, location)
- end
- if accept_token == 81 then
- var token_text = text.substring(0, accept_length)
- return new TNumber.init_tk(token_text, location)
- end
- if accept_token == 82 then
- var token_text = text.substring(0, accept_length)
- return new TFloat.init_tk(token_text, location)
- end
- if accept_token == 83 then
- var token_text = text.substring(0, accept_length)
- return new TChar.init_tk(token_text, location)
- end
- if accept_token == 84 then
- var token_text = text.substring(0, accept_length)
- return new TString.init_tk(token_text, location)
- end
- if accept_token == 85 then
- var token_text = text.substring(0, accept_length)
- return new TStartString.init_tk(token_text, location)
- end
- if accept_token == 86 then
- var token_text = text.substring(0, accept_length)
- return new TMidString.init_tk(token_text, location)
- end
- if accept_token == 87 then
- var token_text = text.substring(0, accept_length)
- return new TEndString.init_tk(token_text, location)
- end
- else
- var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
- if text.length > 0 then
- var token = new AError.init_error("Syntax error: unknown token {text}.", location)
- return token
- else
- var token = new EOF(location)
- return token
- end
- end
- end
- if false then break # FIXME remove once unreach loop exits are in c_src
- end
- return null # FIXME remove once unreach loop exits are in c_src
- end