L10_Verb_and_verb_phrase
- 格式:ppt
- 大小:511.50 KB
- 文档页数:30
English grammarEnglish grammar is the body of rules that describe the structure of expressions in the English language. This includes the structure of words, phrases, clauses, and sentences.There are historical, social, and regional variations of English. Divergences from the grammar described here occur in some dialects of English. This article describes a generalized present-day Standard English, the form of speech found in types of public discourse including broadcasting, education, entertainment, government, and news reporting, including both formal and informal speech. There are certain differences in grammar between the standard forms of British English, American English, and Australian English, although these are inconspicuous compared with the lexical and pronunciation differences.Contents[hide]∙ 1 Word classes and phraseso 1.1 Nouns▪ 1.1.1 Noun phraseso 1.2 Determinerso 1.3 Pronouns▪ 1.3.1 Personal pronouns▪ 1.3.2 Demonstrative and interrogative pronouns▪ 1.3.3 Relative pronouns▪ 1.3.4 There as pronoun▪ 1.3.5 Other pronounso 1.4 Verbs▪ 1.4.1 Verb phraseso 1.5 Adjectives▪ 1.5.1 Comparison▪ 1.5.2 Adjective phraseso 1.6 Adverbs▪ 1.6.1 Adverb phraseso 1.7 Prepositionso 1.8 Conjunctions∙ 2 Negation∙ 3 Clause and sentence structureo 3.1 Questionso 3.2 Dependent clauseso 3.3 Other uses of inversiono 3.4 Imperativeso 3.5 Elliptical constructions∙ 4 History of English grammars∙ 5 See also∙ 6 Notes and references∙7 Bibliographyo7.1 Grammar bookso7.2 Monographs∙8 External links[edit] Word classes and phrasesThere are eight word classes, or parts of speech, that are distinguished in English: nouns, determiners, pronouns, verbs, adjectives, adverbs, prepositions, and conjunctions. (Determiners, traditionally classified along with adjectives, have not always been regarded as a separate part of speech.) Interjections are another word class, but these are not described here as they do not form part of the clause and sentence structure of the language.[1]Nouns, verbs, adjectives, and adverbs form open classes– word classes that readily accept new members, such as the noun celebutante(a celebrity who frequents the fashion circles), the adverb 24/7 (as in I am working on it 24/7), and similar relatively new words.[1] The others are regarded as closed classes. For example, it is rare for a new pronoun to be admitted to the language.English words are not generally marked for word class. It is not usually possible to tell from the form of a word which class it belongs to except, to some extent, in the case of words with inflectional endings or derivational suffixes. On the other hand, some words belong to more than one word class. For example run can serve as either a verb or a noun (these are regarded as two different lexemes).[2] Lexemes may be inflected to express different grammatical categories. The lexeme run has the forms runs, ran, and running.[2]Words in one class can sometimes be derived from those in another. This has the potential to give rise to new words. The noun aerobics has recently given rise to the adjective aerobicized.[2]Words combine to form phrases. A phrase typically serves the same function as a word from some particular word class.[2] For example, my very goodfriend Peter is a phrase that can be used in a sentence as if it were a noun, and is therefore called a noun phrase. Similarly, adjective phrases and adverb phrases function as if they were adjectives or adverbs, but with other types of phrases the terminology has different implications. For example, a verb phrase consists of a verb together with any objects and other dependents; a prepositional phrase consists of a preposition together with its complement (and is therefore usually a type of adverb phrase); and a determiner phrase is a type of noun phrase containing a determiner.[edit] NounsNouns form the largest English word class. There are many common suffixes used to form nouns from other nouns or from other types of words, such as -age(as in shrinkage), -hood(as in sisterhood), and so on,[2]although many nouns are base forms not containing any such suffix (such as cat, grass, France). Nouns are also often created by conversion of verbs or adjectives, as with the words talk and reading(a boring talk, the assigned reading).Unlike in many related languages, English nouns do not have grammatical gender(although many nouns refer specifically to male or female persons or animals, like mother, father, bull, tigress; see Gender in English). Nouns are sometimes classified semantically (by their meanings) as proper nouns and common nouns(Cyrus, China vs. frog, milk) or as concrete nouns and abstract nouns (book, laptop vs. heat, prejudice).[3] A grammatical distinction is often made between count (countable) nouns such as clock and city, and non-count (uncountable) nouns such as milk and decor.[4]Some nouns can function to be either countable or uncountable such the word "wine" (This is a good wine, I prefer red wine).Countable nouns generally have singular and plural forms.[3]In most cases the plural is formed from the singular by adding -[e]s(as in dogs, bushes), although there are also irregular forms (woman/women, medium/media, etc.), including cases where the two forms are identical (sheep, series). For more details, see English plural.Certain nouns can take plural verbs even though they are singular in form, as in The government were ...(where the government is considered to refer to the people constituting the government). This, a form of synesis, is more common in British than American English. See English plural: Singulars with collective meaning treated as plural.English nouns are not marked for case as they are in some languages, but they have possessive forms, formed by the addition of -'s (as in John's, children's), or just an apostrophe (with no change in pronunciation) in the case of -[e]s plurals and sometimes other words ending with -s (the dogs' owners, Jesus' love). More generally, the ending can be applied to noun phrases (as in the man you saw yesterday's sister); see below. The possessive form can be used either as a determiner (John's cat) or as a noun phrase (John's is the one next to Jane's). For details, see English possessive.[edit] Noun phrasesNoun phrases are phrases that function grammatically as nouns within sentences, for example as the subject or object of a verb. Most noun phrases have a noun as their head.[4]An English noun phrase typically takes the following form (not all elements need be present):D ETERMINER + P RE-MODIFIERS + NOUN + P OSTMODIFIERS/C OMPLEMENTIn this structure:∙the determiner may be an article (the, a[n]) or other equivalent word, as described in the following section. In many contexts it is required for a noun phrase to include some determiner.∙pre-modifiers include adjectives and some adjective phrases (such as red, really lovely), and noun adjuncts (such as college in the phrase the college student). Adjectival modifiers usually comebefore noun adjuncts.∙ a complement or postmodifier[4]may be a prepositional phrase (... of London), a relative clause (like ...which we saw yesterday),certain adjective or participial phrases (... sitting on the beach), or a dependent clause or infinitive phrase appropriate to the noun (like ... that the world is round after a noun such as fact orstatement, or ... to travel widely after a noun such as desire). An example of a noun phrase that includes all of the above-mentioned elements is that rather attractive young college student that you were talking to. Here that is the determiner, rather attractive and young are adjectival pre-modifiers, college is a noun adjunct, student is the noun serving as the head of the phrase, and that you were talking to is a post-modifier (a relative clause in this case). Notice the order of thepre-modifiers; the determiner that must come first and the noun adjunct college must come after the adjectival modifiers.Coordinating conjunctions such as and, or, and but can be used at various levels in noun phrases, as in John, Paul, and Mary; the matching green coat and hat; a dangerous but exciting ride; a person sitting down or standing up. See Conjunctions below for more explanation.Noun phrases can also be placed in apposition (where two consecutive phrases refer to the same thing), as in that president, Abraham Lincoln, ...(where that president and Abraham Lincoln are in apposition). In some contexts the same can be expressed by a prepositional phrase, as in the twin curses of famine and pestilence (meaning "the twin curses" that are "famine and pestilence").Particular forms of noun phrases include:∙phrases formed by the determiner the with an adjective, as in the homeless, the English (these are plural phrases referring tohomeless people or English people in general);∙phrases with a pronoun rather than a noun as the head (see below);∙phrases consisting just of a possessive;∙infinitive and gerund phrases, in certain positions;∙certain clauses, such as that clauses and relative clauses like what he said, in certain positions.[edit] DeterminersMain articles: English determiners and English articlesEnglish determiners constitute a relatively small class of words. They include the articles the, a[n] (and in some contexts some), certain demonstrative and interrogative words such as this, that, and which, possessives such as my and whose(the role of determiner can also be played by noun possessive forms such as John's and the girl's), various quantifying words like all, many, various, and numerals(one, two, etc.). There are also many phrases (such as a couple of) that can play the role of determiners.Determiners are used in the formation of noun phrases (see above). Many words that serve as determiners can also be used as pronouns (this, that, many, etc.)Determiners can be used in certain combinations, such as all the water and the many problems .In many contexts, it is required for a noun phrase to be completed with an article or some other determiner. It is not grammatical to say just cat sat on table ; one must say my cat sat on the table . The most common situations in which a complete noun phrase can be formed without a determiner are when it refers generally to a whole class or concept (as in dogs are dangerous and beauty is subjective ) and when it is a name (Jane , Spain , etc.) This is discussed in more detail at English articles and Zero article in English .[edit ] Pronouns Pronouns are a relatively small, closed class of words that function in the place of nouns or noun phrases. They include personal pronouns , demonstrative pronouns , relative pronouns , interrogative pronouns , and some others, mainly indefinite pronouns .[edit ] Personal pronounsMain article: English personal pronounsThe personal pronouns of modern standard English, and the corresponding possessive forms, are as follows:Nominative Oblique Reflexive Possessive determiner Possessive pronoun 1st pers. sing.I me myself my mine 2nd pers. sing./pl. you you yourself/yourselves youryours 3rd pers. sing. she , he , it her , him , itherself , himself , itself her , his , its hers , his , (rare: its ) 1st pers. pl.we us ourselves our ours 3rd pers. pl. they themthemselves their theirs The second-person forms such as you are used with both singular and plural reference. (An archaic set of pronouns used for singular reference is thou, thee, thyself, thy, thine .) You can also be used as an indefinite pronoun ,referring to a person in general (see generic you) compared to the more formal alternative, one (reflexive oneself, possessive one's).The third-person singular forms are differentiated according to the sex of the referent. For example, she can be used to refer to a female person, sometimes a female animal, and sometimes an object to which female characteristics are attributed, such as a ship or a country. A male person, and sometimes a male animal, is referred to using he. In other cases it can be used. (See Gender in English.) The word it can also be used as a dummy subject, in sentences like It is going to be sunny this afternoon.The third-person plural forms such as they are sometimes used with singular reference, as a gender-neutral pronoun, as in each employee should ensure they tidy their desk. This usage is sometimes considered ungrammatical. (See singular they.)The possessive deteminers such as my are used as determiners together with nouns, as in my old man, some of his friends. The second possessive forms like mine are used when they do not qualify a noun: as pronouns, as in mine is bigger than yours, and as predicates, as in this one is mine. Note also the construction a friend of mine(meaning "someone who is my friend"). See English possessive for more details.[edit] Demonstrative and interrogative pronounsThe demonstrative pronouns of English are this (plural these), and that (plural those), as in these are good, I like that. Note that all four words can also be used as determiners (followed by a noun), as in those cars. They can also then form the alternative pronominal expressions this/that one, these/those ones.The interrogative pronouns are who, what, and which(all of them can take the suffix -ever for emphasis). The pronoun who refers to a person or people; it has an oblique form whom(though in informal contexts this is usually replaced by who), and a possessive form (pronoun or determiner) whose. The pronoun what refers to things or abstracts. The word which is used to ask about alternatives from what is seen as a closed set: which (of the books) do you like best? (It can also be an interrogative determiner: which book?; this can form the alternative pronominal expressions which one and which ones.) Which, who, and what can be either singular or plural, although who and what often take a singular verb regardless of any supposed number. For more information see who.All the interrogative pronouns can also be used as relative pronouns; see below for more details.[edit] Relative pronounsMain article: English relative clauses. For "who/whom" and related forms, see also Who (pronoun).The main relative pronouns in English are who(with its derived forms whom and whose), which, and that.[5]The relative pronoun which refers to things rather than persons, as in the shirt, which used to be red, is faded. For persons, who is used (the man who saw me was tall). The oblique case form of who is whom, as in the man whom I saw was tall, although in informal registers who is commonly used in place of whom.The possessive form of who is whose (the man whose car is missing ...); however the use of whose is not restricted to persons (one can say an idea whose time has come).The word that as a relative pronoun is normally found only in restrictive relative clauses (unlike which and who, which can be used in both restrictive and unrestrictive clauses). It can refer to either persons or things, and cannot follow a preposition. For example, one can say the song that [or which] I listened to yesterday, but the song to which [not to that] I listened yesterday. The relative pronoun that is usually pronounced with a reduced vowel (schwa), and hence differently from the demonstrative that(see Weak and strong forms in English). If that is not the subject of the relative clause, it can be omitted (the song I listened to yesterday).The word what can be used to form a free relative clause– one that has no antecedent and that serves as a complete noun phrase in itself, as in I like what he likes. The words whatever and whichever can be used similarly, in the role of either pronouns (whatever he likes) or determiners (whatever book he likes). When referring to persons, who(ever) (and whom(ever)) can be used in a similar way (but not as determiners).[edit] There as pronounThe word there is used as a pronoun in some sentences, playing the role of a dummy subject, normally of an intransitive verb. The "logical subject" of the verb then appears as a complement after the verb.This use of there occurs most commonly with forms of the verb be in existential clauses, to refer to the presence or existence of something. For example: There is a heaven; There are two cups on the table; Therehave been a lot of problems lately. It can also be used with other verbs: There exist two major variants; There occurred a very strange incident.The dummy subject takes the number (singular or plural) of the logical subject (complement), hence it takes a plural verb if the complement is plural. In colloquial English, however, the contraction there's is often used where there are would be expected.The dummy subject can undergo inversion, Is there a test today?and Never has there been a man such as this. It can also appear without a corresponding logical subject, in short sentences and question tags: There wasn't a discussion, was there? There was.The word there in such sentences has sometimes been analyzed as an adverb, or as a dummy predicate, rather than as a pronoun.[6] However, its identification as a pronoun is most consistent with its behavior in inverted sentences and question tags as described above.Because the word there can also be a deictic adverb (meaning "at/to that place"), a sentence like There is a river could have either of two meanings: "a river exists" (with there as a pronoun), and "a river is in that place" (with there as an adverb). In speech, the adverbial there would be given stress, while the pronoun would not – in fact the pronoun is often pronounced as a weak form, /ðə(r)/.[edit] Other pronounsOther pronouns in English are often identical in form to determiners (especially quantifiers), such as many, a little, etc. Sometimes the pronoun form is different, as with none(corresponding to the determiner no), nothing, everyone, somebody, etc. Many examples are listed at Indefinite pronoun.[edit] VerbsMain article: English verbsVerbs form the second largest word class after nouns. The basic form of an English verb is not generally marked by any ending, although there are certain suffixes that are frequently used to form verbs, such as -ate (formulate), -fy (electrify), and -ise/ize (realise/realize).[7] Many verbs also contain prefixes, such un- (unmask), out- (outlast), over-(overtake), and under-(undervalue).[7]Verbs can also be formed from nouns and adjectives by conversion, as with the verbs snare, nose, dry, and calm.Most verbs have three or four inflected forms: a third-person singular present tense form in -s (writes), a present participle and gerund form in -ing (writing), a past tense (wrote), and – though often identical to the past tense form –a past participle(written). Regular verbs have identical past tense and past participle forms in -ed, but there are 100 or so irregular English verbs with different forms (see list). The verbs have, do and say also have irregular third-person present tense forms (has, does/dʌz/, says/sɛz/). The verb be has the largest number of irregularforms (am, is, are in the present tense, was, were in the past tense, been for the past participle).Most of what are often referred to as verb tenses (or sometimes aspects) in English are formed using auxiliary verbs. Apart from what are called the simple present(write, writes) and simple past(wrote), there are also continuous (progressive) forms (am/is/are/was/were writing), perfect forms (have/has/had written, and the perfect continuous have/has/had been writing), future forms (will write, will be writing, will have written, will have been writing), and conditionals (also called "future in the past") with would in place of will. The auxiliaries shall and should sometimes replace will and would in the first person. For the uses of these various verb forms, see English verbs and English clause syntax.The infinitive is the basic form of the verb (be, write, play), although there is also a "to-infinitive" (to be, to write, to play) used in many syntactical constructions. There are also infinitives corresponding to other aspects: (to) have written, (to) be writing, (to) have been writing. The second-person imperative is identical to the (basic) infinitive; other imperative forms may be made with let (let us go, or let's go; let them eat cake).A form identical to the infinitive can be used as a present subjunctive in certain contexts: It is important that he follow them or ... that he be committed to the cause. There is also a past subjunctive (distinct from the simple past only in the possible use of were instead of was), used in some conditional sentences and similar: if I were (or was) rich ...; were he to arrive now ...; I wish she were(or was) here. For details see English subjunctive.The passive voice is formed using the verb be (in the appropriate tense or form) with the past participle of the verb in question: cars are driven, he was killed, I am being tickled, it is nice to be pampered, etc. Theperformer of the action may be introduced in a prepositional phrase with by (as in they were killed by the invaders).The English modal verbs consist of the core modals can, could, may, might, must, shall, should, will, would, as well as ought (to), had better, and in some uses dare and need.[8]These do not inflect for person or number,[8] and do not have infinitive or participle forms (except synonyms, as with be/being/been able (to) for the modals can/could). The modals are used with the basic infinitive form of a verb (I can swim, he may be killed, we dare not move, need they go?), except for ought, which takes to (you ought to go).The copula be, along with the modal verbs and the other auxiliaries, form a distinct class, sometimes called "special verbs" or simply "auxiliaries".[9]These have different syntax from ordinary lexical verbs, especially in that they make their interrogative forms by plain inversion with the subject, and their negative forms by adding not after the verb (could I ...? I could not ...). Apart from those already mentioned, this class may also include used to (although the forms did he use to? and he didn't use to are also found), and sometimes have even when not an auxiliary (forms like have you a sister?and he hadn't a clue are possible, though becoming less common). It also includes the auxiliary do (does, did); this is used with the basic infinitive of other verbs (those not belonging to the "special verbs" class) to make their question and negation forms, as well as emphatic forms (do I like you?; he doesn't speak English; we did close the fridge). For more details of this, seedo-support.Some forms of the copula and auxiliaries often appear as contractions, as in I'm for I am, you'd for you would or you had, and John's for John is. Their negated forms with following not are also often contracted (see Negation below). For detail see English auxiliaries and contractions.[edit] Verb phrasesA verb together with its dependents, excluding its subject, may be identified as a verb phrase (although this concept is not acknowledged in all theories of grammar[10]). A verb phrase headed by a finite verb may also be called a predicate. The dependents may be objects, complements, and modifiers (adverbs or adverbial phrases). In English, objects and complements nearly always come after the verb; a direct object precedes other complements such as prepositional phrases, but if there is an indirect object as well, expressed without a preposition, then that precedes the direct object: give me the book, but give the book to me. Adverbial modifiers generally follow objects, although other positionsare possible (see under Adverbs below). Certain verb–modifier combinations, particularly when they have independent meaning (such as take on and get up), are known as "phrasal verbs".For details of possible patterns, see English clause syntax. See the Non-finite clauses section of that article for verb phrases headed by non-finite verb forms, such as infinitives and participles.[edit] AdjectivesEnglish adjectives, as with other word classes, cannot in general be identified as such by their form,[11]although many of them are formed from nouns or other words by the addition of a suffix, such as -al(habitual), -ful(blissful), -ic(atomic), -ish(impish, youngish), -ous(hazardous), etc.; or from other adjectives using a prefix: disloyal, irredeemable, unforeseen, overtired.Adjectives may be used attributively, as part of a noun phrase (nearly always preceding the noun they modify), as in the big house, or predicatively, as in the house is big. Certain adjectives are restricted to one or other use; for example, drunken is attributive (a drunken sailor), while drunk is usually predicative (the sailor was drunk).[edit] ComparisonMany adjectives have comparative and superlative forms in -er and -est,[12] such as faster and fastest(from the positive form fast). Spelling rules which maintain pronunciation apply to suffixing adjectives just as they do for similar treatment of regular past tense formation; these cover consonant doubling (as in bigger and biggest, from big) and the change of y to i after consonants (as in happier and happiest, from happy).The adjectives good and bad have the irregular forms better, best and worse, worst; also far becomes farther, farthest or further, furthest. The adjective old(for which the regular older and oldest are usual) also has the irregular forms elder and eldest, these generally being restricted to use in comparing siblings and in certain independent uses. For the comparison of adverbs, see Adverbs below.Many adjectives, however, particularly those that are longer and less common, do not have inflected comparative and superlative forms. Instead, they can be qualified with more and most, as in beautiful, more beautiful, most beautiful (this construction is also sometimes used even for adjectives for which inflected forms do exist).Certain adjectives are classed as ungradable.[12] These represent properties that cannot be compared on a scale; they simply apply or do not, as with pregnant, dead, unique. Consequently, comparative and superlative forms of such adjectives are not normally used, except in a figurative, humorous or imprecise context. Similarly, such adjectives are not normally qualified with modifiers of degree such as very and fairly, although with some of them it is idiomatic to use adverbs such as completely. Another type of adjectives sometimes considered ungradable is those that represent an extreme degree of some property, such as delicious and terrified; the same point about modifiers applies to these, although it is not rare to find them in comparative or superlative form.[edit] Adjective phrasesAn adjective phrase is a group of words that plays the role of an adjective in a sentence. It usually has a single adjective as its head, to which modifiers and complements may be added.[13]Adjectives can be modified by a preceding adverb or adverb phrase, as in very warm, truly imposing, more than a little excited. Some can also be preceded by a noun or quantitative phrase, as in fat-free, two-metre-long.Complements following the adjective may include:∙prepositional phrases: proud of him, angry at the screen, keen on breeding toads;∙infinitive phrases: anxious to solve the problem, easy to pick up;∙content clauses, i.e. that clauses and certain others: certain that he was right, unsure where they are;∙after comparatives, phrases or clauses with than: better than you, smaller than I had imagined.An adjective phrase may include both modifiers before the adjective and a complement after it, as in very difficult to put away.Adjective phrases containing complements after the adjective cannot normally be used as attributive adjectives before a noun. Sometimes they are used attributively after the noun, as in a woman proud of being a midwife (where they may be converted into relative clauses: a woman who is proud of being a midwife), but it is wrong to say *a proud of being a midwife woman. Exceptions include very brief and often established phrases such as easy-to-use. (Certain complements can be moved to after the noun, leaving the adjective before the noun, as in a better man than you, a hard nut to crack.)。
PL0语言语法分析器实验报告一、引言编译器是一种用于把高级语言程序转换成机器可执行代码的软件工具。
编译器由多个组件构成,其中语法分析器是编译器中的重要组成部分,其主要功能是对输入的源代码进行解析,并生成一个语法树。
本实验旨在通过使用BNF(巴科斯范式)描述PL0语言的语法规则,并通过实现PL0语言的语法分析器,来深入理解语法分析的原理和过程。
二、PL0语言的语法规则1.程序结构:<程序>::=[<常量说明部分>][<变量说明部分>][<过程说明部分>]<语句>2.常量说明部分:<常量说明部分> ::= const <常量定义> { , <常量定义> };<常量定义>::=<标识符>=<无符号整数>3.变量说明部分:<变量说明部分> ::= var <标识符> { , <标识符> };4.过程说明部分:<过程说明部分>::=<过程首部><分程序>;<过程首部> ::= procedure <标识符> ;5.语句:<语句> ::= <赋值语句> , <if语句> , <while语句> , <调用语句> , <复合语句> , <读语句> , <写语句> , <空><赋值语句>::=<标识符>:=<表达式><if语句> ::= if <条件> then <语句> else <语句><while语句> ::= while <条件> do <语句><调用语句> ::= call <标识符><复合语句> ::= begin <语句> { ; <语句> } end<读语句> ::= read ( <标识符> )<写语句> ::= write ( <表达式> )6.表达式:<表达式>::=[+,-]<项>{(+,-)<项>}<项>::=<因子>{(*,/)<因子>}<因子>::=<标识符>,<无符号整数>,(<表达式>)7.条件:<条件>::=<表达式><关系运算符><表达式><关系运算符>::==,<>,<,<=,>,>=三、PL0语言的语法分析器设计与实现1.设计思路本次实验中,我们将使用自顶向下的递归下降分析法,来对PL0语言进行语法分析。
第二版新视野大学英语读写教程第一册语言点U3U 3 The topic of each partPara 1-2 I was embarrassed to be seen with my father.Para 3-4 How my father went to work.Para 5-7 What my father looked for was a good heart, not pity.Para 8-11 My father participated in many things in some way.Para 12-13 I miss my father very much.lean vi. 1. rest on sth. in a listing position for support 倚;靠Don't lean out of the window. 别把身子探出窗外。
lean on depend on依靠They lean on each other for support. 他们相互依靠,相互支持。
They always lean on us when they are in trouble.(L2) cripple vt. 1. make a person unable to walk or move properly because of damage to the back or legs 使跛;使残废crippled by disease/ car crash 因患疾病(车祸)而跛足的He has been crippled with pain. 他因疼痛而走路一瘸一拐。
2. damage or reduce the strength of (sth.) seriously 严重地损坏;削弱The ship was crippled by a storm. 这只船被暴风雨严重损坏了。
编译原理(清华⼤学-第2版)课后习题答案第三章N=>D=> {0,1,2,3,4,5,6,7,8,9}N=>ND=>NDDL={a |a(0|1|3..|9)n且 n>=1}(0|1|3..|9)n且 n>=1{ab,}a nb n n>=1第6题.(1) <表达式> => <项> => <因⼦> => i(2) <表达式> => <项> => <因⼦> => (<表达式>) => (<项>)=> (<因⼦>)=>(i)(3) <表达式> => <项> => <项>*<因⼦> => <因⼦>*<因⼦> =i*i(4) <表达式> => <表达式> + <项> => <项>+<项> => <项>*<因⼦>+<项>=> <因⼦>*<因⼦>+<项> => <因⼦>*<因⼦>+<因⼦> = i*i+i (5) <表达式> => <表达式>+<项>=><项>+<项> => <因⼦>+<项>=i+<项> => i+<因⼦> => i+(<表达式>) => i+(<表达式>+<项>)=> i+(<因⼦>+<因⼦>)=> i+(i+i)(6) <表达式> => <表达式>+<项> => <项>+<项> => <因⼦>+<项> => i+<项> => i+<项>*<因⼦> => i+<因⼦>*<因⼦> = i+i*i第7题第9题语法树ss s* s s+aa a推导: S=>SS*=>SS+S*=>aa+a*11. 推导:E=>E+T=>E+T*F语法树:E+T*短语: T*F E+T*F直接短语: T*F句柄: T*F12.短语:直接短语:句柄:13.(1)最左推导:S => ABS => aBS =>aSBBS => aBBS=> abBS => abbS => abbAa => abbaa 最右推导:S => ABS => ABAa => ABaa => ASBBaa => ASBbaa => ASbbaa => Abbaa => a1b1b2a2a3 (2) ⽂法:S → ABSS → AaS →εA → aB → b(3) 短语:a1 , b1 , b2, a2 , , bb , aa , abbaa,直接短语: a1 , b1 , b2, a2 , ,句柄:a114 (1)S → ABA → aAb | εB → aBb | ε(2)S → 1S0S → AA → 0A1 |ε第四章1. 1. 构造下列正规式相应的DFA (1)1(0|1)*101NFA(2) 1(1010*|1(010)*1)*0NFA(3)NFA(4)NFA2.解:构造DFA 矩阵表⽰b其中0 表⽰初态,*表⽰终态⽤0,1,2,3,4,5分别代替{X} {Z} {X,Z} {Y} {X,Y} {X,Y,Z} 得DFA状态图为:3.解:构造DFA矩阵表⽰构造DFA的矩阵表⽰其中表⽰初态,*表⽰终态替换后的矩阵4.(1)解构造状态转换矩阵:{2,3} {0,1}{2,3}a={0,3}{2},{3},{0,1}{0,1}a={1,1} {0,1}b={2,2}(2)解:⾸先把M的状态分为两组:终态组{0},和⾮终态组{1,2,3,4,5} 此时G=( {0},{1,2,3,4,5} ) {1,2,3,4,5}a={1,3,0,5} {1,2,3,4,5}b={4,3,2,5}由于{4}a={0} {1,2,3,5}a={1,3,5}因此应将{1,2,3,4,5}划分为{4},{1,2,3,5}G=({0}{4}{1,2,3,5}){1,2,3,5}a={1,3,5}{1,2,3,5}b={4,3,2}因为{1,5}b={4} {23}b={2,3}所以应将{1,2,3,5}划分为{1,5}{2,3}G=({0}{1,5}{2,3}{4}){1,5}a={1,5} {1,5}b={4} 所以{1,5} 不⽤再划分{2,3}a={1,3} {2,3}b={3,2}因为 {2}a={1} {3}a={3} 所以{2,3}应划分为{2}{3}所以化简后为G=( {0},{2},{3},{4},{1,5})7.去除多余产⽣式后,构造NFA如下G={(0,1,3,4,6),(2,5)} {0,1,3,4,6}a={1,3}{0,1,3,4,6}b={2,3,4,5,6}所以将{0,1,3,4,6}划分为 {0,4,6}{1,3} G={(0,4,6),(1,3),(2,5)}{0,4,6}b={3,6,4} 所以划分为{0},{4,6} G={(0),(4,6),(1,3),(2,5)}不能再划分,分别⽤ 0,4,1,2代表各状态,构造DFA 状态转换图如下;b8.代⼊得S = 0(1S|1)| 1(0S|0) = 01(S|ε) | 10(S|ε) = (01|10)(S|ε)= (01|10)S | (01|10)= (01|10)*(01|10)构造NFA由NFA可得正规式为(01|10)*(01|10)=(01|10)+9.状态转换函数不是全函数,增加死状态8,G={(1,2,3,4,5,8),(6,7)}(1,2,3,4,5,8)a=(3,4,8) (3,4)应分出(1,2,3,4,5,8)b=(2,6,7,8)(1,2,3,4,5,8)c=(3,8)(1,2,3,4,5,8)d=(3,8)所以应将(1,2,3,4,5,8)分为(1,2,5,8), (3,4)G={(1,2,5,8),(3,4),(6,7)}(1,2,5,8)a=(3,4,8) 8应分出(1,2,5,8)b=(2,8)(1,2,5,8)c=(8)(1,2,5,8)d=(8)G={(1,2,5),(8),(3,4),(6,7)}(1,2,5)a=(3,4,8) 5应分出G={(1,2), (3,4),5, (6,7) ,(8) }去掉死状态8,最终结果为 (1,2) (3,4) 5,(6,7) 以1,3,5,6代替,最简DFA为b正规式:b*a(da|c)*bb*第五章1.S->a | ^ |( T )(a,(a,a))S => ( T ) => ( T , S ) => ( S , S ) => ( a , S) => ( a, ( T )) =>(a , ( T , S ) ) => (a , ( S , S )) => (a , ( a , a ) ) S=>(T) => (T,S) => (S,S) => ( ( T ) , S ) => ( ( T , S ) , S ) => ( ( T , S , S ) , S ) => ( ( S , S , S ) , S )=> ( ( ( T ) , S , S ) , S ) => ( ( ( T , S ) , S , S ) , S ) =>( ( ( S , S ) , S , S ) , S ) => ( ( ( a , S ) , S , S ) , S ) => ( ( ( a , a ) , S , S ) , S ) => ( ( ( a , a ) , ^ , S ) , S ) => ( ( ( a , a ) , ^ , ( T ) ) , S )=> ( ( ( a , a ) , ^ , ( S ) ) , S ) => ( ( ( a , a ) , ^ , ( a ) ) , S ) => ( ( ( a , a ) , ^ , ( a ) ) , a )S->a | ^ |( T )T -> T , ST -> S消除直接左递归:S->a | ^ |( T )T -> S T’T’ -> , S T’ | ξSELECT ( S->a) = {a}SELECT ( S->^) = {^}SELECT ( S->( T ) ) = { ( }SELECT ( T -> S T’) = { a , ^ , ( }SELECT ( T’ -> , S T’ ) = { , }SELECT ( T’ ->ξ) = FOLLOW ( T’ ) = FOLLOW ( T ) = { )}构造预测分析表分析符号串( a , a )#分析栈剩余输⼊串所⽤产⽣式#S ( a , a) # S -> ( T )# ) T ( ( a , a) # ( 匹配# ) T a , a ) # T -> S T’# ) T’ S a , a ) # S -> a# ) T’ a a , a ) # a 匹配# ) T’,a) # T’ -> , S T’# ) T’ S , , a ) # , 匹配# ) T’ S a ) # S->a# ) T’ a a ) # a匹配# ) T’) # T’ ->ξ# ) ) # )匹配# # 接受2.E->TE’E’->+E E’->ξT->FT’T’->T T’->ξF->PF’F’->*F’F’->ξP->(E) P->a P->b P->∧SELECT(E->TE’)=FIRST(TE’)=FIRST(T)= {(,a,b,^)SELECT(E’->+E)={+}SELECT(E’->ε)=FOLLOW(E’)= {#,)}SELECT(T->FT’)=FIRST(F)= {(,a,b,^}SELECT(T’ —>T)=FIRST(T)= {(,a,b,^)SELECT(T’->ε)=FOLLOW(T’)= {+,#,)}SELECT(F ->P F’)=FIRST(F)= {(,a,b,^}SELECT(F’->*F’)={*}SELECT(F’->ε)=FOLLOW(F’)= {(,a,b,^,+,#,)}3. S->MH S->a H->Lso H->ξK->dML K->ξL->eHf M->K M->bLM FIRST ( S ) =FIRST(MH)= FIRST ( M ) ∪FIRST ( H ) ∪{ξ}∪{a}= {a, d , b , e ,ξ} FIRST( H ) = FIRST ( L ) ∪{ξ}= { e , ξ}FIRST( K ) = { d , ξ}FIRST( M ) = FIRST ( K ) ∪{ b } = { d , b ,ξ}FOLLOW ( S ) = { # , o }FOLLOW ( H ) = FOLLOW ( S ) ∪{ f } = { f , # , o }FOLLOW ( K ) = FOLLOW ( M ) = { e , # , o }FOLLOW ( L ) ={ FIRST ( S ) –{ξ} } ∪{o} ∪FOLLOW ( K )∪{ FIRST ( M ) –{ξ} } ∪FOLLOW ( M )= {a, d , b , e , # , o }FOLLOW ( M ) ={ FIRST ( H ) –{ξ} } ∪FOLLOW ( S )∪{ FIRST ( L ) –{ξ} } = { e , # , o }SELECT ( S-> M H) = ( FIRST ( M H) –{ξ} ) ∪FOLLOW ( S )= ( FIRST( M ) ∪FIRST ( H ) –{ξ} ) ∪FOLLOW ( S )= { d , b , e , # , o }SELECT ( S-> a ) = { a }SELECT ( H->L S o ) = FIRST(L S o) = { e }SELECT ( H ->ξ) = FOLLOW ( H ) = { f , # , o }SELECT ( K->ξ) = FOLLOW ( K ) = { e , # , o }SELECT ( L-> e H f ) = { e }SELECT ( M->K ) = ( FIRST( K ) –{ξ} ) ∪FOLLOW ( M ) = {d,e , # , o }SELECT ( M -> b L M )= { b }4 . ⽂法含有左公因式,变为S->C $ { b, a }C-> b A { b }C-> a B { a }A -> b A A { b }A-> a A’ { a }A’-> ξ{ $ , a, b }A’-> C { a , b }B->a B B { a }B -> b B’ { b }B’->ξ{ $ , a , b }B’-> C { a, b }5. <程序> --- S <语句表>――A <语句>――B <⽆条件语句>――C <条件语句>――D <如果语句>――E <如果⼦句> --FS->begin A end S->begin A end { begin }A-> B A-> B A’ { a , if }A-> A ; B A’-> ; B A’ { ; }A’->ξ{ end }B-> C B-> C { a } B-> D B-> D { if }C-> a C-> a { a }D-> E D-> E D’ { if }D-> E else B D’-> else B { else }D’->ξ{; , end } E-> FC E-> FC { if }F-> if b then F-> if b then { if }⾮终结符是否为空S-否A-否A’-是B-否C-否D-否D’-是E-否F-否FIRST(S) = { begin }FIRST(A) = FIRST(B) ∪FIRST(A’) ∪{ξ} = {a , if , ; , ξ} FIRST(A’) ={ ; , ξ}FIRST(B) = FIRST(C) ∪FIRST(D) ={ a , if }FIRST(C) = {a}FIRST(D) = FIRST(E)= { if }FIRSR(D’) = {else , ξ}FIRST(E) = FIRST(F) = { if }FIRST(F) = { if }FOLLOW(S) = {# }FOLLOW(A) = {end}FOLLOW(A’) = { end }FOLLOW(B) = {; , end }FOLLOW (C) = {; , end , else }FOLLOW(D) = {; , end }FOLLOW( D’ ) = { ; , end }FOLLOW(E) = { else , ; end }FOLLOW(F) = { a }S A A’ B C D D’ E F if then else begin end a b ;6. 1.(1) S -> A | B(2) A -> aA|a(3)B -> bB |b提取(2),(3)左公因⼦(1) S -> A | B(2) A -> aA’(3) A’-> A|ξ(4) B -> bB’(5) B’-> B |ξ2.(1) S->AB(2) A->Ba|ξ(3) B->Db|D(4) D-> d|ξ提取(3)左公因⼦(1) S->AB(2) A->Ba|ξ(3) B->DB’(4) B’->b|ξ(5) D-> d|ξ3.(1) S->aAaB | bAbB(2) A-> S| db(3) B->bB|a4(1)S->i|(E)(2)E->E+S|E-S|S提取(2)左公因⼦(1)S->i|(E)(2)E->SE’(3)E’->+SE’|-SE’ |ξ5(1)S->SaA | bB(2)A->aB|c(3)B->Bb|d消除(1)(3)直接左递归(1)S->bBS’(2)S’->aAS’|ξ(3)A->aB | c(4) B -> dB’(5)B’->bB’|ξ6.(1) M->MaH | H(2) H->b(M) | (M) |b消除(1)直接左递归,提取(2)左公因⼦(1)M-> HM’(2)M’-> aHM’ |ξ(3)H->bH’ | ( M )(4)H’->(M) |ξ7. (1)1)A->baB4)B->a将1)、2)式代⼊3)式1)A->baB2)A->ξ3)B->baBbb4)B->bb5)B->a提取3)、4)式左公因⼦1)A->baB2)A->ξ3)B->bB’4)B’->aBbb | b5)B->a(3)1)S->Aa2)S->b3)A->SB4)B->ab将3)式代⼊1)式1)S->SBa2)S->b3)A->SB4)B->ab消除1)式直接左递归1)S->bS’2)S’->BaS’ |ξ3)S->b4)A->SB5)B->ab删除多余产⽣式4)1)S->bS’(5)1)S->Ab2)S->Ba3)A->aA4)A->a5)B->a提取3)4)左公因⼦1)S->Ab4)A’-> A |ξ5)B->a将3)代⼊1)5)代⼊21)S->aA’b2)S->aa3)A->aA’4)A’-> A |ξ5)B->a提取1)2)左公因⼦1)S-> aS’2)S’->A’b | a3)A->aA’4)A’-> A |ξ5)B->a删除多余产⽣式5)1)S-> aS’2)S’->A’b | a3)A->aA’4)A’-> A |ξA A’S’S将3)代⼊4)1)S-> aS’2)S’->A’b | a3)A->aA ’4)A’-> aA’ |ξ3)S’->a4)S’->b5)A->aA ’6)A’-> aA’ |ξ对2)3)提取左公因⼦1)S->aS’2)S’->aS’’3)S’’->A’b|ξ4)S’->b5)A->aA ’6)A’-> aA’ |ξ删除多余产⽣式5)1)S->aS’2)S’->aS’’3)S’’->A’b|ξ4)S’->b第六章1S → a | ∧ | ( T )T → T , S | S解:(1) 增加辅助产⽣式 S’→#S#求 FIRSTVT集FIRSTVT(S’)= {#}FIRSTVT(S)= {a ∧ ( }= { a ∧ ( } FIRSTVT (T) = {,} ∪ FIRSTVT( S ) = { , a ∧ ( }求 LASTVT集LASTVT(S’)= { # }LASTVT(S)= { a ∧ )}LASTVT (T) = { , a ∧ )}(2)因为任意两终结符之间⾄多只有⼀种优先关系成⽴,所以是算符优先⽂法(3)a ∧( ) , #F 1 1 1 1 1 1g 1 1 1 1 1 1f 2 2 1 3 2 1g 2 2 2 1 2 1f 3 3 1 3 3 1g 4 4 4 1 2 1f 3 3 1 3 3 1g 4 4 4 1 2 1(4)栈优先关系当前符号剩余输⼊串移进或规约#<·( a,a)# 移进#( <· a ,a)# 移进#(T <·, a)# 移进#(T,<· a )# 移进#(T,a ·> ) # 规约#(T,T ·> ) # 规约#(T =·) # 移进#(T) ·> #规约#T =·#接受4.扩展后的⽂法S’→#S# S→S;G S→G G→G(T) G→H H→a H→(S)T→T+S T→S(1)FIRSTVT(S)={;}∪FIRSTVT(G) = {; , a , ( }FIRSTVT(G)={ ( }∪FIRSTVT(H) = {a , ( }FIRSTCT(H)={a , ( }FIRSTVT(T) = {+} ∪FIRSTVT(S) = {+ , ; , a , ( }LASTVT(S) = {;} ∪LASTVT(G) = { ; , a , )}LASTVT(G) = { )} ∪LASTVT(H) = { a , )}LASTVT(H) = {a, )}LASTVT(T) = {+ } ∪LASTVT(S) = {+ , ; , a , ) }构造算符优先关系表因为任意两终结符之间⾄多只有⼀种优先关系成⽴,所以是算符优先⽂法(2)句型a(T+S);H;(S)的短语有:a(T+S);H;(S) a(T+S);H a(T+S) a T+S (S) H直接短语有: a T+S H (S)句柄: a素短语:a T+S (S)最左素短语:a(3)(4)不能⽤最右推导推导出上⾯的两个句⼦。
毕业设计(论文)-基于LLVM的编译器的设计与实现题目:基于LLVM的编译器的设计与实现设计人:指导教师:所属系部:计算机科学与技术学院专业班级:计算机082001班2012年 6月 4日太原科技大学毕业设计(论文)任务书学院: 计算机科学与技术学院学生姓名学号 200820010114 专业班级计算机082001 同组人无任务下发时间 2012年3月任务完成时间 2012年6月设计(论文)题目基于LLVM的编译器的设计与实现设计高质量应用软件的开发,需要高效的编程语言和编译器的支持。
目的为了加深学生对编程语言和编译器的理解,要求学生设计一个类似C要求的小源语言,然后利用LLVM实现该语言的编译器。
在深刻理解编译原理,掌握文法设计和编译器构造方法,并且熟悉LLVM的基础上,完成编程语言和编译器的设计。
主要内容包括: 设计 (1)设计源语言,要求包括变量声明,基本赋值语句,数组访问,主要条件分支语句,循环语句,函数定义,和函数调用等。
内容 (2)学习LLVM,完成词法分析,语法分析,和语法制导翻译(翻译成LLVM IR)工作,最后利用LLVM实现代码优化和代码生成功能。
设计毕业论文提交外文资料翻译资料编译器软件学生签名指导教师签名系主任签名主管院长签名太原科技大学学士学位论文中文摘要开发高性能的应用软件,除了一个良好的软件架构外,还需要高效的编程语言和高质量的编译器的支持。
现有语言的改动和新语言的创造,都会带来编译器的开发需求。
本文设计了一门新的编程语言leechee,定义了此种语言的文法结构、词法规则,并在linux环境下实现了leechee编程语言的编译器。
具体实现方式为首先利用Flex完成词法分析,而后使用Bison完成文法设计、语法分析和语法制导翻译,把源代码翻译成LLVM IR,最后利用LLVM实现代码优化和代码生成功能。
关键字:编程语言;编译器;语法制导翻译;LLVM IR;代码优化太原科技大学学士学位论文The Design and Implementation ofLLVM based CompilerAuthor: Liang Guanlin Tutor: Liu AiqinABSTRACTIn addition to a good software-architecture, the development of high-performance applications also needs the support of an efficient programming language and a high-quality compiler. Changes to existing languages and creation of new languages, will bring the developmentneeds of the compilers. This paper designs a new programming language leechee, defines its grammaticalstructures, lexical rules, and implements its compiler under Linux environment. The specific approach is, first, finishes the scanner with Flex, and then completes the grammar design, parser, syntax directed translation with Bison, implements the translation to LLVM IR, andfinally use the LLVM to do the code optimization and code generation.Keywords: programming language; compiler; syntax directed translation; LLVM IR; code optimizationI太原科技大学学士学位论文目录第一章绪论 ....................................................................0 1.1 什么是编译器 ........................................................... 0 1.2 总会有编译器的开发需求 . 01.3 为什么做这个项目 ....................................................... 1 第二章设计什么样的编译器和语言 (3)2.1 做一个什么样的编译器 (3)2.1.1 利用LLVM实现一门新语言 (3)2.1.2 利用flex和bison完成词法分析和语法分析 (4)2.2 设计一个什么样的语言 (5)2.2.1 计算机可以做什么 (5)2.2.2 本设计的语言——leechee ......................................... 6 第三章相关技术的介绍 .......................................................... 7 3.1Flex ...................................................................73.1.1 Flex输入文件的格式 .............................................. 7 3.2Bison ..................................................................83.2.1 Bison的语法文件 (8)3.2.2 文法规则的语法 (9)3.2.3 文法设计需要注意的问题 ......................................... 10 3.3LLVM ..................................................................113.3.1 LLVMIR (11)3.3.2 LLVM对三段式设计的实现 (12)3.3.3 利用LLVM完成代码优化 .......................................... 14 第四章语言和编译器的设计 ..................................................... 16 4.1 语言设计 .. (16)4.1.1 leechee的数据组成 (16)4.1.2 leechee的文法规则 (17)II太原科技大学学士学位论文4.1.3 leechee的词法规则 (24)4.1.4 leechee的输入输出 (26)4.2 抽象语法树 (27)4.2.1 抽象语法树的用处 (27)4.2.2 leechee语法树的设计 (28)4.3 语法制导翻译 (30)4.3.1 利用Bison实现语法制导翻译方案 (31)4.3.2 均分代码生成工作 ............................................... 31 第五章编译器的实现 .. (32)5.1 抽象语法树的实现 (32)5.1.1NodeAST (32)5.1.2 类型 (33)5.1.3 表达式 (35)5.1.4 语句 (41)5.1.5 声明 (45)5.2 符号表 (49)5.3 分析栈 (50)5.4 中间代码生成的上下文 (51)5.5 输入输出 (52)5.6 代码优化 .............................................................. 54 第六章用例说明 (55)6.1 用例程序 (55)6.2 使用步骤 .............................................................. 57 结束语 ..................................................................... ... 58 致谢 ..................................................................... ..... 59 参考文献 ......................................................................60 附录 ..................................................................... .. (61)附录? 英文资料翻译 (61)III太原科技大学学士学位论文附录? 程序代码 (73)IV太原科技大学学士学位论文第一章绪论1.1 什么是编译器编译器(compiler)也是一个计算机程序,它把用某种编程语言(源语言)编写的代码转变成另一种计算机语言(目标语言,通常是二进制形式的目标代码)。
英语语法PPT之动词和动词短语verbverbphrase幻灯片1Verb & Verb Phrase幻灯片2Classification of verbs●SV●SVO●SVOC●SVOO●SVC●SV A●SVOA●He died.●He loves music.●He found her interesting.●He gave them a glance.●He keeps silent.●He will live in Beijing.●He treats the cat badly.幻灯片3●Students occasionally allege illness as the reason for absence.●He that makes himself a sheep shall be eaten by the wolf.●The weather held fine during the last days.●The boy looks every inch a good actor.●Y ou may keep the book as long as you need it.●We happen to hold the same view.●●幻灯片4●According to their meanings and syntactical functions, verbs may be divided into twoclasses:●Main / Notional V.●*T ransitive V.●*Intransitive V.●*Linking V.●Auxiliary V.●*Primary Aux.●*Modal Aux.●*Semi-aux.幻灯片5Main / Notional verbs●Vt:●The prime suspect admitted having kidnapped the boy.●He is so conceited as to disdain to listen attentively to anyone’s view s.●In no time he acknowledged it to have been done the day before.●The leader from the central government is supervising the workers building the railwayline.●She began to wish her marriage finished in no time.幻灯片6●Vi:●He discriminates in favor of his relatives.●他对自己的亲属另眼看待。