Compiler construction 代码vb6.0识别标识符包含字母和数字

Compiler construction 代码vb6.0识别标识符包含字母和数字,compiler-construction,vb6,Compiler Construction,Vb6,我正在尝试设计简单的编译器(扫描器)我需要知道如何编写代码,识别标识符包含字母和数字,例如id45,并打印它,如果您想检查字符串是否以字母开头,并且在这之后可能包含字母或数字,则可以使用正则表达式 Function IsVar(txt as string) as Boolean 'txt ="id45" IsVar = False Dim re1 As String re1 ="((?:[a-z][a-z0-9_]*))" Dim r As New RegExp r.Pattern

我正在尝试设计简单的编译器(扫描器)我需要知道如何编写代码,识别标识符包含字母和数字,例如id45,并打印它,如果您想检查字符串是否以字母开头,并且在这之后可能包含字母或数字,则可以使用正则表达式

Function IsVar(txt as string) as Boolean
  'txt ="id45"

IsVar = False

Dim re1 As String
re1 ="((?:[a-z][a-z0-9_]*))"

Dim r As New RegExp
  r.Pattern = re1
  r.IgnoreCase = True

  bX = re.Test(sSendLine)
  If bX = True Then
IsVar = True
  End If

End Function
基本上,常规指令“说”

如果我们有一个字符串“id45”

如果您不需要下划线,只需在正则表达式中去掉下划线即可

希望这有帮助
Charlie

您需要向我们展示一些我们可以评论的代码。
[a-z] match a single character present in the list
   a-z a single character in the range between a and z (case sensitive)
[a-z0-9_]* match a single character present in the list
   a-z a single character in the range between a and z (case sensitive)
   0-9 or a single character in the range between 0 and 9
   _   or the character _ (underscore)
* do the previous match from zero to unlimited times (as many times as possible) [greedy]
the first character is an I -- first instruction successful (next)
character 2 = d             -- second instruction successful (repeat)
character 3 = 4             -- second instruction successful (repeat)
character 4 = 5             -- second instruction successful (repeat)
no more characters          -- return true