faqts : Computers : Programming : Languages : Tse : Parser

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: Parser:Syntax:Structure:Parallel:Occurrence: |: How create parser for 1 or more parallel cases?

Oct 20th, 2003 17:28
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 25 September 2003 - 01:40 am ------------------

TSE: Parser:Syntax:Structure:Parallel:Occurrence: |: How create parser 
for 1 or more parallel cases?

How to possibly parse one or more cases (e.g. a string, a paragraph, a 
file, ...):

---

e.g. Suppose you define text as either a string, a paragraph, a 
file, ...

---
---

In words:

Text is either a string, a paragraph or a file.

---
---

In Backus Naur Form:

[text] = [string] | [paragraph] | [file]

---
---

In Backus Naur Form: in general:

[something] = [case1] | [case2] | [case3] | ... | [caseN]

---
---

In Backus Naur Form diagram:

 'text' = -->-+->--[string]-->--------+
              |                       |
              |                       |
              +->--[paragraph]-->-----+-->--
              |                       |
              |                       |
              +->--[file]-->----------+

---
---

In Backus Naur Form diagram: in general

        = -->-+->--[case1]-->--------+
              |                      |
              +->--[case2]-->--------+-->--
              |                      |
              +->--[case3]-->--------+-->--
              |                      |
              +->--...------>--------+
              |                      |
              +->--[caseN]-->--------+-->--

---
---


In pseudo code:

case:
 when 'string'
  get 'string'
 when 'paragraph'
  get 'paragraph'
 when 'file'
  get 'file'
 otherwise
  error 'unknown case'

---
---

In pseudo code: in general:

case:
 when 'case1'
  get 'case1'
 when 'case2'
  get 'case2'
 when 'case3'
  get 'case3'
 ...
 when 'caselast'
  get 'caselast'
 otherwise
  error 'unknown case'
 endcase

---
---

As regular expression:

{{string}|{paragraph}|{file}}

---
---

As regular expression: if a group of individual characters: in general:

Use a class:

 [<character1><character2><character3>...<characterN>]

---

e.g.

 [abcdfgh\-\~.]

---
---

As regular expression: if words: in general:

{{case1}|{case2}|{case3}|...|{caseN}}

---
---

Note: So you use a CASE or SWITCH, because of this corresponds also to
a situation where you have to choose between 1 or more possibilities.

---
---

Internet: see also:


TSE: Parser: Syntax: Structure: Serial: Occurrence: &: And: How create 
parser for serial occurrence?
http://www.faqts.com/knowledge_base/view.phtml/aid/24710/fid/1236

---

TSE: Parser: Syntax: Structure: If: Occurrence: ?: How to create a 
parser for 0 or 1 occurrences?
http://www.faqts.com/knowledge_base/view.phtml/aid/24708/fid/1236

---

TSE: Parser: Syntax:Structure:Repeat: Occurrence: +: How to create 
parser for 1 or more occurrences?
http://www.faqts.com/knowledge_base/view.phtml/aid/24703/fid/1236

---

TSE: Parser: Syntax: Structure: While: Occurrence: *: How create 
parser for 0 or more occurrences?
http://www.faqts.com/knowledge_base/view.phtml/aid/24700/fid/1236

----------------------------------------------------------------------