Notes on compilation principles

Source: Internet
Author: User
ArticleDirectory
    • 2.2.1 definition of Regular Expressions
    • 2.2.2 extensions to regular expressions Regular Expression Extension
    • 2.2.3 Regular Expressions for programming lanaguage tokens
Chapter 2

Language generated by regular expression is written as L (r ).

This language depends on the character set that is available. Set elements are

Reffered as symbols. This set of legal symbols is called the alphabet and is usually

Written as the Greek symbol Sigma.

 

2.2.1 definition of Regular Expressions

1. Basic Regular Expression

2. Choice of alternatives: |

3. concatenation: Rs

4. Repetition: Kleene closure R *

5. Parentheses :()

 

Anban

Pumping Lemma

 

2.2.2 extensions to regular expressions Regular Expression Extension

1. One or more one or more repetitions: +

2. Any character any character :.

3. character range: a range of characters: [A-Z]

4. Any character not in a given set: [^ ABC]

5. Optional?

 

2.2.3 Regular Expressions for programming lanaguage tokens

1. Reserved Words, keywords: while, if

2. special symbols: ++,: =

3. Identifiers: sequences of letters and digits begin with a letter

4. literals: Numeric constants, 42, 3.14159, string literals, "Hello, world", 'A'

 

1) numbers:

Nat = [0-9] +

Signednat = (+ | -)? Nat

Number = signednat ("." nat )? (E signednat )?

 

2) Reserved Words and identifiers

Reserved = if | while | Do |...

 

Letter = [A-Za-Z]

Digit = [0-9]

Identifier = letter (letter | digit )*

 

3) comments:

/**/Ad hoc method

(* This is (* A Modula-2 *) Comment *)

We have noted in expample 2.3 that regular expressions

Cannot express counting operations. In practice, we use a simple Conter

As an ad hoc solution to this problem (see the exercises ).

4) ambiguity, white space, and lookahead

1. disambiguating rules

 

Principle of longest substring

Token delimiters

Free format, fixed format, offside rule (use indent to format)

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.