亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
樓主: oldbeginner
打印 上一主題 下一主題

編譯器學(xué)習(xí)筆記02(世界公民antlr)——2014_2_27 [復(fù)制鏈接]

論壇徽章:
1
午馬
日期:2013-08-23 23:39:47
11 [報(bào)告]
發(fā)表于 2014-03-03 20:26 |只看該作者
windows 上據(jù)說支持不好,不過這是好久得事了,現(xiàn)在不知道怎樣。不過微軟到現(xiàn)在好像也沒參與llvm。

Google搞llvm得頭說得, 2012年的事了。
http://channel9.msdn.com/Events/ ... y-s-Million-Monkeys

論壇徽章:
0
12 [報(bào)告]
發(fā)表于 2014-03-03 20:33 |只看該作者
本帖最后由 oldbeginner 于 2014-03-03 21:12 編輯



    多謝。我打算先學(xué)antlr ,然后linux,然后再 llvm(如果還有精力的話,并且如果進(jìn)展順利的話,并且如果第三次世界大戰(zhàn)沒有發(fā)生的話,并且如果兩會(huì)圓滿結(jié)束的話)。

因?yàn)閍ntlr 使用比較簡單,還有配套數(shù)據(jù),所以暫時(shí)學(xué)習(xí)antlr了。

論壇徽章:
0
13 [報(bào)告]
發(fā)表于 2014-03-03 21:18 |只看該作者
*************************************
4.4 Making Things Happen During the Parse

************************************



To demonstrate actions embedded in a grammar, let’s build a program that
prints out a specific column from rows of data.


編寫語法文件 和 java文件



The only
thing different here is that we’re passing in a column number to the parser
using a custom constructor and telling the parser not to build a tree.


然后,執(zhí)行


These actions extract and print values matched by the parser, but they don’t
alter the parse itself. Actions can also finesse how the parser recognizes input
phrases.


   

論壇徽章:
0
14 [報(bào)告]
發(fā)表于 2014-03-04 13:18 |只看該作者
*****************************
英語充電

*****************************

看英文 書籍 確實(shí)挺累,不習(xí)慣啊。

決定找些英文資料充充電,選擇 經(jīng)典演講 應(yīng)該不錯(cuò),最好能找到中國人的演講。運(yùn)氣真好,好像就上個(gè)星期,出了一篇精彩的評論,而且有心人認(rèn)認(rèn)真真翻譯成英文。

看這篇文章,即能學(xué)漢譯英,又能學(xué)英語,一石二鳥。

*****************************
只挑精彩的閱讀,各段之間有省略(看原文 http://club.kdnet.net/dispbbs.asp?boardid=1&id=9881899 三樓)

Farewell, Gary LOCKE!
標(biāo)題很簡陋

文章一上來就是下馬威,有點(diǎn)普特勒風(fēng)格,
Gary Locke is a third generation Chinese American born in America. Like a banana, he’s yellow on the outside, but white on the inside. This character of his has been well exploited by the Obama administration for its diplomatic advantages

上面是翻譯后的,原文是這樣的,
駱家輝是一個(gè)在美國出生的第三代華裔,他的“黃皮白心”的香蕉人屬性成了奧巴馬外交的優(yōu)勢。

翻譯的人很辛苦,把 黃皮白心 詳細(xì)描述出來,中文的“香蕉人”這個(gè)單詞 即使對很多國人也是不熟悉的。

So above the table there you have a black hair, yellow skinned Chinese diaspora generating favourable impressions for the U.S.; but beneath such impression is the America’s effort to stir up storms and create tensions in the Asia-Pacific region.

感覺上面這句很難,看看原文,
當(dāng)美國在亞太不斷攪起漩渦、制造矛盾的時(shí)候,卻有一個(gè)表面上久居海外的游子、黑頭發(fā)黃皮膚的皮囊來為美 國叫好。

感覺翻譯有點(diǎn)問題,游子 和 皮囊 應(yīng)該 是兩個(gè)名稱,都翻譯成了 Chinese,不妥。

However, after a while, a banana will inevitably start to rot. Not only its “white core” deep inside will then be exposed, it will also have been rotted into a disgusting “black core”.

不明覺歷的樣子。
原文也比較酷,快趕上去年朝鮮判決書的質(zhì)量:
然而香蕉放久了“黃皮”總歸是要爛掉的,不但“白心”會(huì)露出來,也會(huì)變成反胃的“黑心”。

But Mr Locke, foreign to the words of his ancestors, unable to understand Chinese Laws, loved to interfere and lecture on China’s internal affairs.

但駱氏不但不認(rèn)祖先的文字,還看不懂中國法律,特喜歡對著中國的內(nèi)政指手畫腳。

看來,不懂漢字的外籍華人 都可以 用 不認(rèn)祖先的文字 來描述。

Mr Ambassador, do your ancestors know your “performances” [as an ambassador in China?] [I think] they’ll have you expelled from the family if they knew.

笑而不語,原文:
大使先生,您的“業(yè)績”,您祖上知道么?您祖上要是知道,可要把您逐出門戶了。

英語應(yīng)該沒有這種表達(dá)方法,這應(yīng)該是漢語和英語雙向影響的一種模式。

Farewell, smog; farewell, the plague; Farewell Gary LOCKE!

感覺中文更傳神,原文:
送霧霾,送瘟神。Farewell,駱氏家輝!


****************************************************

突然覺得,這篇文章寫得如此 明顯,高級黑的可能性占 7 成,作者 利用 負(fù)負(fù)得正 (物極必反的原理)的方式 來啟蒙大眾,原因你懂得。

****************************************

一天,韓國 恢復(fù)漢字運(yùn)動(dòng) 成員 找到語文老師 想學(xué)習(xí) 新的漢字用法,
語文老師隨口 武松打雞
他很興奮,聽完解釋后又很失望,韓國人用不到這個(gè)詞。
語文老師,香蕉人
他又很興奮,聽完解釋后打了語文老師一頓。


   

論壇徽章:
0
15 [報(bào)告]
發(fā)表于 2014-03-04 13:43 |只看該作者
********************************
語義 預(yù)測
Altering the Parse with Semantic Predicates
********************************

Let’s look at a grammar that reads in sequences of integers. The
trick is that part of the input specifies how many integers to group together.



The key in the following Data grammar is a special Boolean-valued action
called a semantic predicate: {$i<=$n}?. That predicate evaluates to true until
we surpass the number of integers requested by the sequence rule parameter
n.


準(zhǔn)備工作做好,


然后,



   

論壇徽章:
0
16 [報(bào)告]
發(fā)表于 2014-03-04 22:41 |只看該作者
************************
4.5 編譯 XML

***********************
一個(gè)xml文件和一個(gè)語法文件



xml很簡單


語法,
An XML parser treats everything other than tags and
entity references (such as &pound as text chunks. When the lexer sees <, it
switches to “inside” mode and switches back to the default mode when it sees
> or />.


然后,


論壇徽章:
0
17 [報(bào)告]
發(fā)表于 2014-03-05 15:50 |只看該作者
****************************
Rewriting the Input Stream

****************************


Let’s build a tool that processes Java source code to insert serialization
identifiers, serialVersionUID, for use with java.io.Serializable (like Eclipse does
automatically).

這個(gè) 語法文件 內(nèi)容太大,就不上玉照了。





The key is the TokenStreamRewriter object that knows how to give altered views
of a token stream without actually modifying the stream.




   

論壇徽章:
0
18 [報(bào)告]
發(fā)表于 2014-03-05 16:08 |只看該作者
本帖最后由 oldbeginner 于 2014-03-05 16:16 編輯

*************************************
慢下來,是為了走得更好

************************************



It’s time to slow down our pace and revisit all of the concepts explored in this
chapter with the goal of learning all of the details. Each chapter in the next
part of the book will take us another step toward becoming language implementers.
We’ll start by learning ANTLR notation and figuring out how to derive
grammars from examples and language reference manuals.



這張圖是配套2010年中國基尼系數(shù)0.6的(最近幾年都不敢調(diào)查了),很形象,但有一個(gè)致命的缺點(diǎn),就是分 “城” 和“鄉(xiāng)”是錯(cuò)誤的和誤導(dǎo)的,

最起碼應(yīng)該分”體制內(nèi)或和體制相關(guān)的“和”體制外且無關(guān)系的“

   

畫外音,這些圖片和antlr 有啥關(guān)系?

另一個(gè)畫外音,學(xué)antlr要慢下來,靜下來,否則會(huì)出現(xiàn)像某大國。。。。。


接地氣最厲害的不在天c,想接地氣,向非洲學(xué)習(xí)



真好,理解逐級接地氣了嗎?

論壇徽章:
0
19 [報(bào)告]
發(fā)表于 2014-03-06 15:43 |只看該作者
本帖最后由 oldbeginner 于 2014-03-06 15:59 編輯

******************************
第五章 designing grammars
那些年,漢字 還是 貴族
******************************




你天天韓國韓劇的,你祖上知道嗎?





Now we’re going to slow down and learn the details
needed to perform useful tasks such as building internal data structures,
extracting information, and generating a translation of the input. The first
step on our journey, though, is to learn how to build grammars.

The constraints of word order and dependency, derived from natural language,
blossom into four abstract computer language patterns.

• Sequence: This is a sequence of elements such as the values in an array
initializer.
• Choice: This is a choice between multiple, alternative phrases such as
the different kinds of statements in a programming language.
• Token dependence: The presence of one token requires the presence of
its counterpart elsewhere in a phrase such as matching left and right
parentheses.
• Nested phrase: This is a self-similar language construct such as nested
arithmetic expressions or nested statement blocks in a programming
language.

*******************************
5.1 Deriving Grammars from Language Samples

*******************************

Proper grammar design mirrors functional decomposition or top-down design
in the programming world. That means we work from the coarsest to the
finest level, identifying language structures and encoding them as grammatical
rules.

For example, “a comma-separated-value (CSV) file is a sequence of
rows terminated by newlines.” The essential word file to the left of is a is the
rule name, and everything to the right of is a becomes the «stuff» on the right
side of a rule definition.

Then we step down a level in granularity by describing the elements identified
on the right side of the start rule.

Stepping down another level of detail, we could say that a row is a sequence
of fields separated by commas. Then, a field is a number or string. Our
pseudocode looks like this:

file : «sequence of rows that are terminated by newlines» ;
row : «sequence of fields separated by commas» ;
field : «number or string» ;


***********************************

Let’s see how this technique works for describing some of the key structures
in a Java file. (We can make the rule names stand out by italicizing them.)
At the coarsest level, a Java compilation unit is an optional package specifier,
followed by one or more class definitions. Stepping down a level, a class definition
is keyword class, followed by an identifier, followed optionally by a
superclass specifier, followed optionally by an implements clause, followed by
a class body. A class body is a series of members enclosed in curly braces. A
member is a nested class definition, a field, or a method. From here, we would
describe fields and methods and then the statements within methods. You
get the idea. Start at the highest possible level and work your way down,
treating even large subphrases like Java class definitions as rules to define
later. In grammar pseudocode, we’d start out like this:

compilationUnit : «optional packageSpec then classDefinitions» ;
packageSpec : 'package' identifier ';' ;
classDefinition :
'class' «optional superclassSpec optional implementsClause classBody» ;
superclassSpec : 'super' identifier ;
implementsClause :
'implements' «one or more identifiers separated by comma» ;
classBody : '{' «zero-or-more members» '}' ;
member : «nested classDefinition or field or method» ;


***********************************
看出來了,作者寫的根本就不是 一本 關(guān)于 ANTLR4 入門 方面的書籍。

另外,感覺 作者好像不是很懂 龍書,因?yàn)榭此奈恼乱稽c(diǎn)不能幫助學(xué)習(xí)龍書;龍書上的知識也不能幫助學(xué)習(xí) ANTLR4。這難道就是傳說中的,理論脫離實(shí)際了嗎?

不過,龍書一定有必要嗎?不看龍書,微軟就不能開發(fā)windows了嗎?

   

論壇徽章:
0
20 [報(bào)告]
發(fā)表于 2014-03-06 17:29 |只看該作者
***********************
5.2 Using Existing Grammars as a Guide
***********************


沒啥意思,不過有句話倒是可以聽聽,
Identifying the grammar rules and expressing their right sides in pseudocode
is challenging at first but gets easier and easier as you build grammars for
more languages.


*******************************
5.3 Recognizing Common Language Patterns with ANTLR Grammars

*******************************

   
Now that we have a general top-down strategy for roughing out a grammar,
we need to focus on the common language patterns: sequence, choice, token
dependence, and nested phrase.

Pattern: Sequence

The structure you’ll see most often in computer languages is a sequence of
elements, such as the sequence of methods in a class definition.

Variations on this pattern include the sequence with terminator and sequence
with separator. CSV files demonstrate both nicely. Here’s how we can express
the pseudocode grammar from the previous section in ANTLR notation:

file : (row '\n')* ; // sequence with a '\n' terminator
row : field (',' field)* ; // sequence with a ',' separator
field: INT ; // assume fields are just integers


Rule file uses the list with terminator pattern to match zero or more row '\n'
sequences. The '\n' token terminates each element of the sequence. Rule row
uses the list with separator pattern by matching a field followed by zero or
more ',' field sequences. The ',' separates the fields. row matches sequences like
1 and 1,2 and 1,2,3, and so on.


Pattern: Choice (Alternatives)

To express the notion of choice in a language, we use | as the “or” operator
in ANTLR rules to separate grammatical choices called alternatives or productions.
Grammars are full of choices.

Returning to our CSV grammar, we can make a more flexible field rule by
allowing the choice of integers or strings.

field : INT | STRING ;

Any time you find yourself saying “l(fā)anguage structure x can be either this or
that,” then you’ve identified a choice pattern. Use | in rule x.


Pattern: Token Dependency

we need a way to express dependencies between tokens. If we see one symbol
in a sentence, we must find its matching counterpart elsewhere in the sentence.
To express this with a grammar, we use a sequence that specifies both
symbols, usually enclosing or grouping other elements. In this case, we
completely specify vectors like this:

vector : '[' INT+ ']' ; // [1], [1 2], [1 2 3], ...

Keep in mind that dependent symbols don’t necessarily have to match. Cderived
languages also have the a?b:c ternary operator where the ? sets up a
requirement to see : later in the phrase.



Pattern: Nested Phrase

A nested phrase has a self-similar language structure, one whose subphrases
conform to that same structure.

Let’s see how nesting works for code blocks. A while statement is the keyword
while followed by a condition expression in parentheses followed by a statement.
We can also treat multiple statements as a single block statement by wrapping
them in curly braces. Expressing that grammatically looks like this:

stat: 'while' '(' expr ')' stat // match WHILE statement
| '{' stat* '}' // match block of statements in curlies
... // and other kinds of statements

;

The looping statement, stat, of the while can be a single statement or a group
of statements if we enclose them in {...}. Rule stat is directly recursive because
it refers to itself in the first (and second) alternatives. If we moved the second
alternative to its own rule, rules stat and block would be mutually indirectly
recursive.

stat: 'while' '(' expr ')' stat // match WHILE statement
| block // match a block of statements
... // and other kinds of statements
;
block: '{' stat* '}' ; // match block of statements in curlies



**************************************************
**************************************************

For future reference, here’s a table summarizing ANTLR’s core grammar
notation:


And here is a table summarizing what we’ve learned so far about common
computer language patterns:















您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP