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
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 ...
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ìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 432 1 0
-
24 trang 358 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 319 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 307 0 0 -
74 trang 303 0 0
-
96 trang 297 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 291 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 284 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0