Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

Properties

DATETIME

DATETIME: number = 4

DIGIT

DIGIT: number = 5

E

E: number = 6

EOF

EOF: number = -1

EscapeSequence

EscapeSequence: number = 7

FALSE

FALSE: number = 8

FLOAT

FLOAT: number = 9

HexDigit

HexDigit: number = 10

ID

ID: number = 11

INTEGER

INTEGER: number = 12

LETTER

LETTER: number = 13

NAME

NAME: number = 14

STRING

STRING: number = 15

TRUE

TRUE: number = 16

T__19

T__19: number = 19

T__20

T__20: number = 20

T__21

T__21: number = 21

T__22

T__22: number = 22

T__23

T__23: number = 23

T__24

T__24: number = 24

T__25

T__25: number = 25

T__26

T__26: number = 26

T__27

T__27: number = 27

T__28

T__28: number = 28

T__29

T__29: number = 29

T__30

T__30: number = 30

T__31

T__31: number = 31

T__32

T__32: number = 32

T__33

T__33: number = 33

T__34

T__34: number = 34

T__35

T__35: number = 35

T__36

T__36: number = 36

T__37

T__37: number = 37

T__38

T__38: number = 38

T__39

T__39: number = 39

T__40

T__40: number = 40

T__41

T__41: number = 41

T__42

T__42: number = 42

T__43

T__43: number = 43

T__44

T__44: number = 44

T__45

T__45: number = 45

T__46

T__46: number = 46

T__47

T__47: number = 47

T__48

T__48: number = 48

UnicodeEscape

UnicodeEscape: number = 17

WS

WS: number = 18

defaultTokenChannel

defaultTokenChannel: number = TokenChannels.default

dfa14

dfa14: DFA14

dfa7

dfa7: DFA7

grammarFileName

grammarFileName: string

For debugging and other purposes, might want the grammar name. Have ANTLR generate an implementation for this method.

hidden

hidden: number = TokenChannels.hidden

Protected input

Where is the lexer drawing characters from?

memoRuleFailed

memoRuleFailed: number = -2

memoRuleUnknown

memoRuleUnknown: number = -1

nextTokenRuleName

nextTokenRuleName: string = "nextToken"

state

State of a lexer, parser, or tree parser are collected into a this.state object so the this.state can be shared. This sharing is needed to have one grammar import others and share same error variables and other this.state variables. It's a kind of explicit multiple inheritance via delegation of methods and shared this.state.

tokenNames

tokenNames: string[] = null

Used to print out token names like ID during debugging and error reporting. The generated parsers implement a method that overrides this to point to their String[] tokenNames.

Static initialFollowStackSize

initialFollowStackSize: number = 100

Accessors

backtrackingLevel

  • get backtrackingLevel(): number
  • set backtrackingLevel(value: number): void

charIndex

  • get charIndex(): number
  • What is the index of the current character of lookahead?

    Returns number

charPositionInLine

  • get charPositionInLine(): number
  • set charPositionInLine(value: number): void

charStream

failed

  • get failed(): boolean
  • Return whether or not a backtracking attempt failed.

    Returns boolean

line

  • get line(): number
  • set line(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

numberOfSyntaxErrors

  • get numberOfSyntaxErrors(): number
  • Get number of recognition errors (lexer, parser, tree parser). Each recognizer tracks its own number. So parser and lexer each have separate count. Does not count the spurious errors found between an error and next valid token match

    Returns number

sourceName

  • get sourceName(): string

text

  • get text(): string
  • set text(value: string): void
  • Gets or sets the text matched so far for the current token or any text override. Setting this value replaces any previously set value, and overrides the original text.

    Returns string

  • Gets or sets the text matched so far for the current token or any text override. Setting this value replaces any previously set value, and overrides the original text.

    Parameters

    • value: string

    Returns void

Methods

alreadyParsedRule

  • alreadyParsedRule(input: IIntStream, ruleIndex: number): boolean
  • Has this rule already parsed input at the current index in the input stream? Return the stop token index or MEMO_RULE_UNKNOWN. If we attempted but failed to parse properly before, return MEMO_RULE_FAILED.

    This method has a side-effect: if we have seen this input for this rule and successfully parsed before, then seek ahead to 1 past the stop token matched for this rule last time.

    Parameters

    Returns boolean

beginResync

  • beginResync(): void
  • A hook to listen in on the token consumption during error recovery. The DebugParser subclasses this to fire events to the listenter.

    Returns void

Protected combineFollows

  • combineFollows(exact: boolean): BitSet
  • what is exact? it seems to only add sets from above on stack if EOR is in set i. When it sees a set w/o EOR, it stops adding. Why would we ever want them all? Maybe no viable alt instead of mismatched token?

    Parameters

    • exact: boolean

    Returns BitSet

Protected computeContextSensitiveRuleFOLLOW

  • computeContextSensitiveRuleFOLLOW(): BitSet
  • Compute the context-sensitive FOLLOW set for current rule. This is set of token types that can follow a specific rule reference given a specific call chain. You get the set of viable tokens that can possibly come next (lookahead depth 1) given the current call chain. Contrast this with the definition of plain FOLLOW for rule r:

    FOLLOW(r)={x | S=>*alpha r beta in G and x in FIRST(beta)}

    where x in T* and alpha, beta in V*; T is set of terminals and V is the set of terminals and nonterminals. In other words, FOLLOW(r) is the set of all tokens that can possibly follow references to r in any sentential form (context). At runtime, however, we know precisely which context applies as we have the call chain. We may compute the exact (rather than covering superset) set of following tokens.

    For example, consider grammar:

    stat : ID '=' expr ';' // FOLLOW(stat)=={EOF} | "return" expr '.' ; expr : atom ('+' atom)* ; // FOLLOW(expr)=={';','.',')'} atom : INT // FOLLOW(atom)=={'+',')',';','.'} | '(' expr ')' ;

    The FOLLOW sets are all inclusive whereas context-sensitive FOLLOW sets are precisely what could follow a rule reference. For input input "i=(3);", here is the derivation:

    stat => ID '=' expr ';' => ID '=' atom ('+' atom)* ';' => ID '=' '(' expr ')' ('+' atom)* ';' => ID '=' '(' atom ')' ('+' atom)* ';' => ID '=' '(' INT ')' ('+' atom)* ';' => ID '=' '(' INT ')' ';'

    At the "3" token, you'd have a call chain of

    stat -> expr -> atom -> expr -> atom

    What can follow that specific nested ref to atom? Exactly ')' as you can see by looking at the derivation of this specific input. Contrast this with the FOLLOW(atom)={'+',')',';','.'}.

    You want the exact viable token set when recovering from a token mismatch. Upon token mismatch, if LA(1) is member of the viable next token set, then you know there is most likely a missing token in the input stream. "Insert" one by just not throwing an exception.

    Returns BitSet

Protected computeErrorRecoverySet

  • computeErrorRecoverySet(): BitSet
  • Compute the error recovery set for the current rule. During rule invocation, the parser pushes the set of tokens that can follow that rule reference on the stack; this amounts to computing FIRST of what follows the rule reference in the enclosing rule. This local follow set only includes tokens from within the rule; i.e., the FIRST computation done by ANTLR stops at the end of a rule.

    EXAMPLE

    When you find a "no viable alt exception", the input is not consistent with any of the alternatives for rule r. The best thing to do is to consume tokens until you see something that can legally follow a call to r or any rule that called r. You don't want the exact set of viable next tokens because the input might just be missing a token--you might consume the rest of the input looking for one of the missing tokens.

    Consider grammar:

    a : '[' b ']' | '(' b ')' ; b : c '^' INT ; c : ID | INT ;

    At each rule invocation, the set of tokens that could follow that rule is pushed on a stack. Here are the various "local" follow sets:

    FOLLOW(b1_in_a) = FIRST(']') = ']' FOLLOW(b2_in_a) = FIRST(')') = ')' FOLLOW(c_in_b) = FIRST('^') = '^'

    Upon erroneous input "[]", the call chain is

    a -> b -> c

    and, hence, the follow context stack is:

    depth local follow set after call to rule 0 a (from main()) 1 ']' b 3 '^' c

    Notice that ')' is not included, because b would have to have been called from a different context in rule a for ')' to be included.

    For error recovery, we cannot consider FOLLOW(c) (context-sensitive or otherwise). We need the combined set of all context-sensitive FOLLOW sets--the set of all tokens that could follow any reference in the call chain. We need to resync to one of those tokens. Note that FOLLOW(c)='^' and if we resync'd to that token, we'd consume until EOF. We need to sync to context-sensitive FOLLOWs for a, b, and c: {']','^'}. In this case, for input "[]", LA(1) is in this set so we would not consume anything and after printing an error rule c would return normally. It would not find the required '^' though. At this point, it gets a mismatched token error and throws an exception (since LA(1) is not in the viable following token set). The rule exception handler tries to recover, but finds the same recovery set and doesn't consume anything. Rule b exits normally returning to rule a. Now it finds the ']' (and with the successful match exits errorRecovery mode).

    So, you cna see that the parser walks up call chain looking for the token that was a member of the recovery set.

    Errors are not generated in errorRecovery mode.

    ANTLR's error recovery mechanism is based upon original ideas:

    "Algorithms + Data Structures = Programs" by Niklaus Wirth

    and

    "A note on error recovery in recursive descent parsers": http://portal.acm.org/citation.cfm?id=947902.947905

    Later, Josef Grosch had some good ideas:

    "Efficient and Comfortable Error Recovery in Recursive Descent Parsers": ftp://www.cocolab.com/products/cocktail/doca4.ps/ell.ps.zip

    Like Grosch I implemented local FOLLOW sets that are combined at run-time upon error to avoid overhead during parsing.

    Returns BitSet

consumeUntil

  • consumeUntil(input: IIntStream, tokenType: number): void

consumeUntil2

displayRecognitionError

emit

  • The standard method called to automatically emit a token at the outermost lexical rule. The token object should point into the char buffer start..stop. If there is a text override in 'text', use that to set the token's text. Override this method to emit custom Token objects.

    If you are building trees, then you should also override Parser or TreeParser.getMissingSymbol().

    Returns IToken

emit2

  • Currently does not support multiple emits per nextToken invocation for efficiency reasons. Subclass and override this method and nextToken (to push tokens into a list and pull from that list rather than a single variable as this implementation does).

    Parameters

    Returns void

emitErrorMessage

  • emitErrorMessage(msg: string): void

endResync

  • endResync(): void

enterRule_T__34

  • enterRule_T__34(): void
  • Returns void

enterRule_T__45

  • enterRule_T__45(): void
  • Returns void

getCharErrorDisplay

  • getCharErrorDisplay(c: number): string

Protected getCurrentInputSymbol

  • Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID. Token and tree parsers need to return different objects. Rather than test for input stream type or change the IntStream interface, I use a simple method to ask the recognizer to tell me what the current input symbol is.

    This is ignored for lexers.

    Parameters

    Returns any

getEndOfFileToken

  • Returns the EOF token (default), if you need to return a custom token instead override this method.

    Returns IToken

getErrorHeader

getErrorMessage

Protected getMissingSymbol

  • Conjure up a missing token during error recovery.

    The recognizer attempts to recover from single missing symbols. But, actions might refer to that missing symbol. For example, x=ID {f($x);}. The action clearly assumes that there has been an identifier matched previously and that $x points at that token. If that token is missing, but the next token in the stream is what we want we assume that this token is missing and we keep going. Because we have to return some token to replace the missing token, we have to conjure one up. This method gives the user control over the tokens returned for missing tokens. Mostly, you will want to create something special for identifier tokens. For literals such as '{' and ',', the default action in the parser or tree parser works. It simply creates a CommonToken of the appropriate type. The text will be the token. If you change what tokens must be created by the lexer, override this method to create the appropriate tokens.

    Parameters

    Returns any

getRuleMemoization

  • getRuleMemoization(ruleIndex: number, ruleStartIndex: number): number
  • Given a rule number and a start token index number, return MEMO_RULE_UNKNOWN if the rule has not parsed input starting from start index. If this rule has parsed input starting from the start index before, then return where the rule stopped parsing. It returns the index of the last token matched by the rule.

    For now we use a hashtable and just the slow Object-based one. Later, we can make a special one for ints and also one that tosses out data after we commit past input position i.

    Parameters

    • ruleIndex: number
    • ruleStartIndex: number

    Returns number

getRuleMemoizationCacheSize

  • getRuleMemoizationCacheSize(): number

getTokenErrorDisplay

  • getTokenErrorDisplay(t: IToken): string
  • How should a token be displayed in an error message? The default is to display just the text, but during development you might want to have a lot of information spit out. Override in that case to use t.ToString() (which, for CommonToken, dumps everything about the token). This is better than forcing you to override a method in your token objects because you don't have to go modify your lexer so that it creates a new Java type.

    Parameters

    Returns string

implements

  • implements(): any[]

initDFAs

  • initDFAs(): void

leaveRule_T__34

  • leaveRule_T__34(): void
  • Returns void

leaveRule_T__45

  • leaveRule_T__45(): void
  • Returns void

mDATETIME

  • mDATETIME(): void
  • Returns void

mDIGIT

  • mDIGIT(): void
  • Returns void

mE

  • mE(): void
  • Returns void

mEscapeSequence

  • mEscapeSequence(): void
  • Returns void

mFALSE

  • mFALSE(): void
  • Returns void

mFLOAT

  • mFLOAT(): void
  • Returns void

mHexDigit

  • mHexDigit(): void
  • Returns void

mID

  • mID(): void
  • Returns void

mINTEGER

  • mINTEGER(): void
  • Returns void

mLETTER

  • mLETTER(): void
  • Returns void

mNAME

  • mNAME(): void
  • Returns void

mSTRING

  • mSTRING(): void
  • Returns void

mTRUE

  • mTRUE(): void
  • Returns void

mT__19

  • mT__19(): void
  • Returns void

mT__20

  • mT__20(): void
  • Returns void

mT__21

  • mT__21(): void
  • Returns void

mT__22

  • mT__22(): void
  • Returns void

mT__23

  • mT__23(): void
  • Returns void

mT__24

  • mT__24(): void
  • Returns void

mT__25

  • mT__25(): void
  • Returns void

mT__26

  • mT__26(): void
  • Returns void

mT__27

  • mT__27(): void
  • Returns void

mT__28

  • mT__28(): void
  • Returns void

mT__29

  • mT__29(): void
  • Returns void

mT__30

  • mT__30(): void
  • Returns void

mT__31

  • mT__31(): void
  • Returns void

mT__32

  • mT__32(): void
  • Returns void

mT__33

  • mT__33(): void
  • Returns void

mT__34

  • mT__34(): void
  • Returns void

mT__35

  • mT__35(): void
  • Returns void

mT__36

  • mT__36(): void
  • Returns void

mT__37

  • mT__37(): void
  • Returns void

mT__38

  • mT__38(): void
  • Returns void

mT__39

  • mT__39(): void
  • Returns void

mT__40

  • mT__40(): void
  • Returns void

mT__41

  • mT__41(): void
  • Returns void

mT__42

  • mT__42(): void
  • Returns void

mT__43

  • mT__43(): void
  • Returns void

mT__44

  • mT__44(): void
  • Returns void

mT__45

  • mT__45(): void
  • Returns void

mT__46

  • mT__46(): void
  • Returns void

mT__47

  • mT__47(): void
  • Returns void

mT__48

  • mT__48(): void
  • Returns void

mTokens

  • mTokens(): void

mUnicodeEscape

  • mUnicodeEscape(): void
  • Returns void

mWS

  • mWS(): void
  • Returns void

match

  • Match current input symbol against ttype. Attempt single token insertion or deletion error recovery. If that fails, throw MismatchedTokenException.

    To turn off single token insertion or deletion error recovery, override recoverFromMismatchedToken() and have it throw an exception. See TreeParser.recoverFromMismatchedToken(). This way any error in a rule will cause an exception and immediate exit from rule. Rule would recover by resynchronizing to the set of symbols that can follow rule ref.

    Parameters

    Returns any

match2

  • match2(c: number): void
  • Parameters

    • c: number

    Returns void

match3

  • match3(s: string): void
  • Parameters

    • s: string

    Returns void

matchAny

  • matchAny(): void

matchRange

  • matchRange(a: number, b: number): void
  • Parameters

    • a: number
    • b: number

    Returns void

memoize

  • memoize(input: IIntStream, ruleIndex: number, ruleStartIndex: number): void
  • Record whether or not this rule parsed the input at this position successfully. Use a standard java hashtable for now.

    Parameters

    • input: IIntStream
    • ruleIndex: number
    • ruleStartIndex: number

    Returns void

mismatchIsMissingToken

mismatchIsUnwantedToken

  • mismatchIsUnwantedToken(input: IIntStream, ttype: number): boolean

nextToken

Protected parseNextToken

  • parseNextToken(): void

Protected popFollow

  • popFollow(): void

Protected pushFollow

  • pushFollow(fset: BitSet): void

recover

  • Recover from an error found on the input stream. This is for NoViableAlt and mismatched symbol exceptions. If you enable single token insertion and deletion, this will usually not handle mismatched symbol exceptions but there could be a mismatched token that the match() routine could not recover from.

    Parameters

    Returns void

recover2

  • Lexers can normally match any char in it's vocabulary after matching a token, so do the easy thing and just kill a character and hope it all works out. You can instead use the rule invocation stack to do sophisticated error recovery if you are in a fragment rule.

    Parameters

    Returns void

recoverFromMismatchedSet

Protected recoverFromMismatchedToken

  • recoverFromMismatchedToken(input: IIntStream, ttype: number, follow: BitSet): any
  • Attempt to recover from a single missing or extra token.

    EXTRA TOKEN

    LA(1) is not what we are looking for. If LA(2) has the right token, however, then assume LA(1) is some extra spurious token. Delete it and LA(2) as if we were doing a normal match(), which advances the input.

    MISSING TOKEN

    If current token is consistent with what could come after ttype then it is ok to "insert" the missing token, else throw exception For example, Input "i=(3;" is clearly missing the ')'. When the parser returns from the nested call to expr, it will have call chain:

    stat -> expr -> atom

    and it will be trying to match the ')' at this point in the derivation:

      => ID '=' '(' INT ')' ('+' atom)* ';'
                         ^
    

    match() will see that ';' doesn't match ')' and report a mismatched token error. To recover, it sees that LA(1)==';' is in the set of tokens that can follow the ')' token reference in rule atom. It can assume that you forgot the ')'.

    Parameters

    Returns any

reportError

reset

  • reset(): void

setState

skip

  • skip(): void
  • Instruct the lexer to skip creating a token for current lexer rule and look for another token. nextToken() knows to keep looking when a lexer rule finishes with token set to SKIP_TOKEN. Recall that if token==null at end of any token rule, it creates one for you and emits it.

    Returns void

toStrings

  • A convenience method for use most often with template rewrites. Convert a list of to a list of .

    Parameters

    Returns List<string>

Generated using TypeDoc