Java Lexcial Structure

Lexical analysis

lexical analysis is the process of translation from a raw Unicode character stream to a sequence of tokens. The tokens are the terminal symbols of the syntactic grammar. A program that perform lexical analysis may be termed a lexer, tokenizer, or scanner, though scanner is also a term for the first stage of a lexer. In detail, there are three steps in turn :

  1. translate all Unicode escapes to the corresponding Unicode character, for example, translate \n to 0A
  2. recognize line terminators to separate the stream resulting from step 1 to the input characters and terminators, this step will save line numbers of source code so that you can debug your program by some error message with corresponding line number
  3. split result from step 2 to white space (including line terminator), comments and tokens , and then tokens are reserved

Tokens

Token is a very important concept in compiler. Java tokens contain :

  • Identifier
  • Keyword
  • Literal
  • Separator
  • Operator

The Tokens are non-terminal symbols of the lexical grammar with characters as terminal symbols, like this :

BooleanLiteral:
       true
       false

but the terminal symbols of the syntactic grammar. A parser which analyze the syntax of programming language uses token stream as input, and abstract syntax tree (AST) as output.

References

  1. https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html
  2. https://en.wikipedia.org/wiki/Lexical_analysis
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 燈紅酒綠 翩翩起舞的蝴蝶 通過風(fēng)傳來誘惑 而我只是與長頭發(fā)的楊柳一起 望著小河 夏天用雨用浪表達著熱情 我也希望心...
    舒嚴閱讀 178評論 0 0
  • 地表雞卵隨風(fēng)熟,遠方腳步無可阻。 碧海藍天暢遼闊,山青水秀載桃花。 普陀梵音響竹苑,禪寺孕婦沾圣水。 起早貪黑逐日...
    然1314閱讀 188評論 0 0
  • iPhone 8、X發(fā)布前,馬化騰帶領(lǐng)高管去了趟蘋果的總部,雖然不知道他們跟庫克聊了什么,但肯定是很愉快的。 上周...
    理想三旬_63d1閱讀 241評論 0 0
  • 今天才發(fā)現(xiàn)微信storage增加了“手機已用空間”的展示,剛看到時有一種“wow,真貼心真強大”的感覺,因為查看系...
    妖精王國的貓小姐閱讀 756評論 2 0

友情鏈接更多精彩內(nèi)容