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?

4 of 8 people (50%) answered Yes
Recently 4 of 8 people (50%) answered Yes

Entry

TSE: Parser: Syntax: Analysis: Language: Visual Basic: How to parse a function? [find]

Jun 20th, 2004 14:03
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 20 Juny 2004 - 08:04 pm -----------------------

TSE: Parser: Syntax: Analysis: Language: Visual Basic: How to parse a 
function? [find]

---

VISUAL BASIC: function: find: regular expression: string

 string basic_fun[] = "^{{friend}|{private}|{public}[ \t]+}?{function}|
{sub}|{property}[ \t]"

---

VISUAL BASIC: function: regular expression: in words

A Visual Basic function

 1. starts at the first character of the line

 2. possibly starts with 1 word 'friend' or 'private' or 'public'

    2.1 followed by 1 or more spaces or tabs,

 3. followed by 1 word 'function' or 'sub' or 'property'

 4. followed by 1 space or tab

---

VISUAL BASIC: function: example:


friend function TEST

private function TEST

public function TEST

friend sub TEST

private sub TEST

public sub TEST

friend property TEST

private property TEST

public property TEST

---

VISUAL BASIC: function: BNF: description:

function = begin_of_line [ ['friend' | 'private' | 'public'] (tab | 
space)+ ] ('function' | 'sub' | 'property') (tab | space)

---

VISUAL BASIC: function: BNF: syntax diagram:

 ->-(begin of line)-------->------------------------+
                                                    |
+---------------------------------------------------+
|
|
|   +---------------------->------------------------+
|   |                                               |
|   |   +->-(friend)->--+   +----<--------------+   |
|   |   |               |   |                   |   |
+->-+->-+->-(private)->-+->-+->-+->-[ ]->---+->-+->-+->-+
        |               |       |           |           |
        +->-(public)->--+       +->-[tab]->-+           |
                                                        |
    +----------------------<----------------------------+
    |
    |
    +->-+->-(function)->-+
        |                |
        +->-(sub)->------+->-+->-[ ]->---+->-
        |                |   |           |
        +->-(property)->-+   +->-[tab]->-+

---


VISUAL BASIC: function: syntax analysis:

PROC PROCLanguageCheckFunctionComputerVisualBasicSyntaxAnalysis()
 //
 // ---
 //
 // To run:
 //
 //  1. Compile this macro
 //
 //  2. Put the cursor on the first character of the function
 //
 //  3. Press <F12>
 //
 //  4. If the cursor then moves to the end of the function name,
 //     it is a valid name according to the given syntax
 //
 // ---
 //
 // Example of visual basic functions:
 //
 // friend function TEST
 //
 // private function TEST
 //
 // public function TEST
 //
 // friend sub TEST
 //
 // private sub TEST
 //
 // public sub TEST
 //
 // friend property TEST
 //
 // private property TEST
 //
 // public property TEST
 //
 // ---
 //
 // A visual basic function
 //
 //
 // 1. starts at the first character of the line
 //
 IF NOT ( CurrCol() == 1 )
  Warn( 'visual basic: function: function should start at the first 
position of this line' )
  RETURN()
 ENDIF
 //
 // 2. possibly starts with 1 word 'friend' or 'private' or 'public'
 //
 IF ( Getword() IN 'friend', 'private', 'public' )
 //
  // goto the end of the current word
  //
  EndWord()
  //
  // 2.1 followed by 1 or more spaces or tabs
  //
  WHILE ( Chr( CurrChar() ) IN ' ', Chr( 9 ) )
   NextChar()
  ENDWHILE
 //
 ENDIF
 //
 // 3. followed by 1 word 'function' or 'sub' or 'property'
 //
 IF NOT ( Getword() IN 'function', 'sub', 'property' )
  Warn( 'visual basic: function: word "function" or "sub" 
or "property" expected' )
 ENDIF
 //
 // goto the end of the current word
 //
 EndWord()
 //
 // 4. followed by 1 space or tab
 //
 IF NOT ( Chr( CurrChar() ) IN ' ', Chr( 9 ) )
  Warn( 'visual basic: function: at least 1 space or tab expected 
after the word "function" or "sub" or "property"' )
  RETURN()
 ENDIF
 //
 // goto the next character
 //
 NextChar()
 //
END

PROC Main()
 PROCLanguageCheckFunctionComputerVisualBasicSyntaxAnalysis()
END

<F12> Main()

---
---

Internet: see also:

---

TSE: Parser: Syntax: Analysis: Language: Function: Can you give 
overview of how to parse functions?
http://www.faqts.com/knowledge_base/view.phtml/aid/30300/fid/1236

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