关闭

c++正则表达式,python

474人阅读 评论(0) 收藏 举报
一个python中国列表的朋友给的
------------------------------------------------------------------------------------------------------------------------------------------
C++ grammar summary

Execution parts:

////////////////////////Well-known definitions: (They do only their business, any stuff not belong to them will be not processed)
blank: /s*
strictblank: /s+
number: OR:
           r"[/d]+",r"[.][/d]+",r"[/d]+[.][/d]*",
             r"[/d]+[.]?e(?:[+]|-|)[/d]+",r"[.]?[/d]+(?:e|E)(?:[+]|-|)[/d]+",
             r"[/d]+[.][/d]*e(?:[+]|-|)[/d]+",
             r"0[xX][0-9a-fA-F]+", #Hex number
             r"0[0-8]+", #Octal number
             r"'[^']+'"
string: "(?:[^//]|//.)+"
value: [bool|number|string]
literal: [a-zA-Z_][0-9a-zA-Z_]*
bool: [true|false]

////////////////////////Semi-atom level definitions: (iterates will process all begin blank but no after blanks will be processed)
type: literal (blank :: blank literal)*
valueiterate: (blank(operators|operator,|value|literal| [(] strictvalueiterate blank [)]))*
strictvalueiterate: (blank(operators|operator,|value|literal| [(] strictvalueiterate blank [)]))+
passvalueiterate: (blank(operators|value|literal| [(] strictvalueiterate blank [)]))*
strictpassvalueiterate: (blank(operators|value|literal| [(] strictvalueiterate blank [)]))+
operators: OR:
               "new","delete","delete" blank [ blank ],"++","--","<<",">>",
               "!","&&","||",">=","<=",">","<","!=","==",
               "+=","-=","*=","/=","%=",
               "^=","&=","|=",
               "->",",",
               ".","::",
               "^","&","|","~",             
               "+","-","*","/","%",
               "[","]","(",")"

assignname: (blank [*|&])* blank literal (blank [ blank /d* blank ] )*

assignvaluector: blank [(] (blank strictpassvalueiterate (blank , blank strictpassvalueiterate)+)? [)]
assignvaluecopy: blank = blank strictpassvalueiterate
assignvaluevoid:
assignvalue: ( assignvaluector | assignvaluecopy | )
valuesingledefinition: blank type blank assignname (assignvaluector | assignvaluevoid)

functionspecifier: (blank [inline|virtual|explicit|auto|register|static|extern|mutable|extern|static])*

////////////////////////Atom level definitions: (Every thing that can be treated as a language sentence) (only begin either)
valueblock: valueiterate blank ;
if: blank "if/b" blank ( strictvalueiterate blank ) [sentencelite|sentenceblock]
for: blank "for/b" blank ( [valuesingledefinition|passvalueiterate] blank ; passvalueiterate blank ; passvalueiterate blank ) [sentencelite|sentenceblock]
while: blank "while/b" blank ( strictvalueiterate blank ) [sentencelite|sentenceblock]
do: blank "do/b" blank sentenceblock blank while blank ( strictvalueiterate blank ) blank ;
break: blank "break/b" blank ;
return: blank "return/b" [strictvalueiterate|] blank ;

sentencelite: blank [break|return|valueiterate blank ;]
valueassign: blank type blank assignname assignvalue (blank , assignname assignvalue)* blank ;
sentence: [sentencelite|valueassign]

////////////////////////Segments: (only begin either)
sentenceblock: blank { blank (sentence)* blank }
structblock: blank { blank [public:|private:|valueassign|function|struct|structdef] blank }

////////////////////////First class objects:
function: blank functionspecifier blank type blank ( blank (valuesingledefinition (blank , valuesingledefinition)* )? blank )
          [(blank : blank type blank "(" sentence blank ")" (blank , blank type blank "(" sentence blank ")")*)? sentenceblock|;|= blank 0 blank ;]
namespace: blank "namespace" blank literal blank { blank document blank }
usenamespace: blank use blank "namespace" blank literal blank ;
struct: blank ["struct"|class|union] blank literal [blank : (blank [public|private|protected|] blank literal (blank , blank [public|private|protected|] blank literal)*)? structblock ( blank assignname assignvalue (blank , assignname assignvalue)*)? blank ;
structdef: blank ["struct"|class|union] blank literal blank ;
document: (blank [ valueassign|function|namespace|struct|structdef ])* 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:250265次
    • 积分:4010
    • 等级:
    • 排名:第7716名
    • 原创:149篇
    • 转载:43篇
    • 译文:0篇
    • 评论:32条
    文章分类