Danh mục

Beginning SQL Server Modeling- P3

Số trang: 20      Loại file: pdf      Dung lượng: 1.24 MB      Lượt xem: 11      Lượt tải: 0    
tailieu_vip

Hỗ trợ phí lưu trữ khi tải xuống: 20,000 VND Tải xuống file đầy đủ (20 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu beginning sql server modeling- p3, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Beginning SQL Server Modeling- P3 CHAPTER 3  DOMAIN-SPECIFIC LANGUAGES 101: LOLA’S LUNCH COUNTERFigure 3-10. Interleaving whitespace Lola: “So, you’re pretty much back to where you started. I need something that’s going to work withmore than pastrami on rye! How are you going to get there from here?” Norm: “Right. So how do you define a sandwich, anyway? At the simplest level, it’s some kind oflunchmeat on some kind of bread. So let’s change the main syntax definition to something like that.” Norm changes the DSL Grammar code to reflect his thinking, along the lines shown in Figure 3-11.Of course, the grammar processor (center pane) has no idea what the terms Lunchmeat and Bread arebecause they are undefined.Defining TokensFigure 3-11. First cut at making the SandwichOrders syntax rule more general Norm has redefined the Main syntax, but now he needs to define Lunchmeat and Bread as tokens. Toget started, he’d like the processor to accept any string for Lunchmeat, followed by the preposition on,and any string for Bread, with a period at the end. Right now, anything from “foo on bar” to “Brecht onBrecht” would mean some progress in Lola’s eyes. So Norm adds a couple of token statements to thegrammar definition to define Lunchmeat and Bread as tokens within the grammar that can contain anysequence of characters. Figure 3-12 shows the result. Again, the grammar works with this and shows no error. The two tokenstatements define Lunchmeat and Bread in exactly the same way: They can be a single contiguous string of 41 Download from Wow! eBook CHAPTER 3  DOMAIN-SPECIFIC LANGUAGES 101: LOLA’S LUNCH COUNTER one or more characters, a through z or A through Z. But I’ve introduced a number of new M language forms: a..z” means a single alpha character anywhere in the range from a to z. Similarly, A..Z means a single capitalized alpha character anywhere in the range from A to Z. A pipe character (|) is the logical OR operator. A plus sign (+) is a postfix Kleene operator, meaning “one or more of this entity.” So given this syntax, (a..z | A..Z)+ means “any sequence of one or more alpha characters, upper- or lowercase.” So Rye and rAzzLeDaZZle both qualify, and rAzzLeDaZZle on Rye would be a valid sandwich order, according to the newly defined DSL Grammar code. This removes one of the constraints of the extremely limited Pastrami on Rye straight jacket, but you’re still a long way from anything resembling a useful sandwich order system. Figure 3-12. Defining the Lunchmeat and Bread tokens as arbitrary strings Enabling Multiple DSL Statements Lola: “Okay, say I just had another customer order a ham on 9-grain wheat sandwich. Will your system handle that?” Norm: “I don’t think so, but let’s try it and see where it breaks.” Figure 3-13 shows the results of adding the ham on 9-grain order.42 Download from Wow! eBook CHAPTER 3  DOMAIN-SPECIFIC LANGUAGES 101: LOLA’S LUNCH COUNTERFigure 3-13. Errors generated by adding a second sandwich order in the DSL The Error List pane indicates that a carriage return and line feed were unexpected, so you need toadd these to the Whitespace rule. Lola: “But why the first error in the list? Doesn’t that order conform to the syntax you’ve defined?” Norm: “In a sense, yes. The new statement itself conforms to the grammar, but the syntax really isvalid for only one statement.”Figure 3-14. One remaining error after carriage return, and new-line are added to ignorable whitespace In Figure 3-14, Norm has added the carriage return (the UTF8 encoding for this is written as )and new line (written as ) to the interleave rule. After this, the only remaining error is theunexpected Lunchmeat token, which is really caused by the unexpected second order statement. To fixthis problem, Norm encloses the Main syntax phrase on the right side of the equals sign (=) inparentheses and adds a postfix + to indicate that one or more instances of the conforming statement areexpected (Figure 3-15). [Similar operators, called Kleene operators, are an asterisk (*) to indicate zero ormore occurrences, and question mark (?) to indicate zero or one occurrence.] 43 Download from Wow! eBook CHAPTER 3  DOMAIN-SPECIFIC LANGUAGES 101: LOLA’S LUNCH COUNTER Figure 3-15. Testing for unanticipated characters in the B ...

Tài liệu được xem nhiều: