VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 147|回复: 10

高级语言的文法产生式

[复制链接]
发表于 2018-6-3 12:06:50 | 显示全部楼层 |阅读模式
SQL:
  1. sql_list → sql ';'
  2. | sql_list sql ';'

  3. sql → schema_element_list
  4. | view_def

  5. schema_element_list → schema_element
  6. | schema_element_list schema_element

  7. schema_element → base_table_def
  8. | create_index_def
  9. | drop_table
  10. | drop_index
  11. | add_column
  12. | table_rename
  13. | privilege_def
  14. | privilege_revoke
  15. | create_user_statement
  16. | delete_user_statement
  17. | set_pass
  18. | set_group_stmt

  19. base_table_def → CREATE TABLE new_table_name '(' base_table_element_commalist ')'

  20. base_table_element_commalist → base_table_element
  21. | base_table_element_commalist ',' base_table_element

  22. base_table_element → column_def
  23. | table_constraint_def

  24. column_def → column data_type column_def_opt_list

  25. references → REFERENCES q_table_name opt_column_commalist

  26. column_def_opt_list → ε
  27. | column_def_opt_list column_def_opt

  28. column_def_opt → NOT NULLX
  29. | IDENTITY
  30. | NOT NULLX PRIMARY KEY opt_index_option_list
  31. | DEFAULT literal
  32. | references

  33. table_constraint_def → UNDER q_table_name
  34. | PRIMARY KEY '(' index_column_commalist ')' opt_index_option_list
  35. | FOREIGN KEY '(' column_commalist ')' references

  36. column_commalist → column
  37. | column_commalist ',' column

  38. index_column_commalist → column opt_asc_desc
  39. | index_column_commalist ',' column opt_asc_desc

  40. index_option → CLUSTERED
  41. | UNIQUE

  42. index_option_list → index_option
  43. | index_option_list index_option

  44. opt_index_option_list → ε
  45. | index_option_list

  46. create_index_def → CREATE opt_index_option_list INDEX index
  47. ON new_table_name '(' index_column_commalist ')'

  48. drop_index → DROP INDEX NAME opt_table

  49. opt_table → ε
  50. | q_table_name

  51. drop_table → DROP TABLE q_table_name

  52. add_col_column_def_list → column_def
  53. | add_col_column_def_list ',' column_def

  54. add_col_column_list → column
  55. | add_col_column_list ',' column

  56. add_column → ALTER TABLE q_table_name ADD opt_col_add_column add_col_column_def_list
  57. | ALTER TABLE q_table_name DROP opt_col_add_column add_col_column_list
  58. | ALTER TABLE q_table_name MODIFY opt_col_add_column column_def

  59. table_rename → ALTER TABLE q_table_name RENAME new_table_name

  60. view_def → CREATE VIEW new_table_name opt_column_commalist
  61. AS query_exp opt_with_check_option

  62. opt_with_check_option → ε
  63. | WITH CHECK OPTION

  64. opt_column_commalist → ε
  65. | '(' column_commalist ')'

  66. priv_opt_column_commalist → ε
  67. | '(' column_commalist ')'

  68. privilege_def → GRANT ALL PRIVILEGES TO grantee
  69. | GRANT privileges ON table TO grantee_commalist opt_with_grant_option
  70. | GRANT grantee_commalist TO grantee_commalist opt_with_admin_option

  71. privilege_revoke → REVOKE ALL PRIVILEGES FROM grantee_commalist
  72. | REVOKE privileges ON table FROM grantee_commalist
  73. | REVOKE grantee_commalist FROM grantee_commalist

  74. opt_with_grant_option → ε
  75. | WITH GRANT OPTION

  76. opt_with_admin_option → ε
  77. | WITH ADMIN OPTION

  78. privileges → ALL PRIVILEGES
  79. | ALL
  80. | operation_commalist

  81. operation_commalist → operation
  82. | operation_commalist ',' operation

  83. operation → SELECT priv_opt_column_commalist
  84. | INSERT
  85. | DELETE
  86. | UPDATE priv_opt_column_commalist
  87. | EXECUTE

  88. grantee_commalist → grantee
  89. | grantee_commalist ',' grantee

  90. grantee → PUBLIC
  91. | user

  92. set_pass → SET PASSWORD NAME NAME

  93. create_user_statement → CREATE USER user
  94. | CREATE ROLE user

  95. delete_user_statement → DELETE USER user [CASCADE]
  96. | DROP ROLE user

  97. set_group_stmt → SET USER GROUP user user

  98. cursor_def → DECLARE NAME CURSOR FOR query_spec

  99. opt_order_by_clause → ε
  100. | ORDER BY ordering_spec_commalist

  101. ordering_spec_commalist → ordering_spec
  102. | ordering_spec_commalist ',' ordering_spec

  103. ordering_spec → INTNUM opt_asc_desc
  104. | column_ref opt_asc_desc
  105. | function_ref opt_asc_desc

  106. opt_asc_desc → ε
  107. | ASC
  108. | DESC

  109. sql → manipulative_statement

  110. manipulative_statement → query_exp
  111. | update_statement_positioned
  112. | update_statement_searched
  113. | insert_statement
  114. | delete_statement_positioned
  115. | delete_statement_searched
  116. | call_statement
  117. | admin_statement
  118. | use_statement

  119. use_statement → USE NAME

  120. close_statement → CLOSE cursor

  121. delete_statement_positioned → DELETE FROM table WHERE CURRENT OF cursor

  122. delete_statement_searched → DELETE FROM table opt_where_clause

  123. fetch_statement → FETCH cursor INTO target_commalist

  124. insert_mode → INTO
  125. | REPLACING
  126. | SOFT

  127. insert_statement → INSERT insert_mode table priv_opt_column_commalist values_or_query_spec

  128. values_or_query_spec → VALUES '(' insert_atom_commalist ')'
  129. | query_spec

  130. insert_atom_commalist → insert_atom
  131. | insert_atom_commalist ',' insert_atom

  132. insert_atom → scalar_exp

  133. cursor_option → EXCLUSIVE
  134. | PREFETCH INTNUM

  135. cursor_options_commalist → cursor_option
  136. | cursor_options_commalist ',' cursor_option

  137. opt_cursor_options_list → ε
  138. | '(' cursor_options_commalist ')'

  139. open_statement → OPEN cursor opt_cursor_options_list

  140. with_opt_cursor_options_list → ε
  141. | WITH opt_cursor_options_list

  142. select_statement → SELECT opt_all_distinct selection table_exp
  143. | SELECT opt_all_distinct selection
  144. INTO target_commalist table_exp with_opt_cursor_options_list

  145. opt_all_distinct → ε
  146. | ALL
  147. | DISTINCT

  148. update_statement_positioned → UPDATE table SET assignment_commalist WHERE CURRENT OF cursor

  149. assignment_commalist → ε
  150. | assignment
  151. | assignment_commalist ',' assignment

  152. assignment → column COMPARISON scalar_exp

  153. update_statement_searched → UPDATE table SET assignment_commalist opt_where_clause

  154. target_commalist → target
  155. | target_commalist ',' target

  156. target → column_ref

  157. opt_where_clause → ε
  158. | where_clause

  159. query_exp → query_term
  160. | query_exp UNION query_term
  161. | query_exp UNION ALL query_term

  162. query_term → query_spec
  163. | '(' query_exp ')'

  164. query_spec → SELECT opt_all_distinct selection table_exp

  165. selection → scalar_exp_commalist

  166. table_exp → from_clause opt_where_clause opt_group_by_clause opt_having_clause
  167. opt_order_by_clause opt_lock_mode

  168. from_clause → FROM table_ref_commalist

  169. table_ref_commalist → table_ref
  170. | table_ref_commalist ',' table_ref

  171. table_ref → table
  172. | '(' query_exp ')' NAME
  173. | joined_table

  174. table_ref_nj → table
  175. | subquery NAME

  176. opt_outer → ε
  177. | OUTER

  178. jtype → LEFT
  179. | RIGHT
  180. | INNER
  181. | FULL

  182. joined_table → table_ref jtype opt_outer JOIN table_ref_nj ON search_condition
  183. | BEGIN_OJ_X table_ref jtype opt_outer JOIN table_ref_nj
  184.   ON search_condition ENDX

  185. where_clause → WHERE search_condition

  186. opt_group_by_clause → ε
  187. | GROUP BY ordering_spec_commalist

  188. opt_having_clause → ε
  189. | HAVING search_condition

  190. opt_lock_mode → ε
  191. | FOR UPDATE

  192. search_condition → ε
  193. | search_condition OR search_condition
  194. | search_condition AND search_condition
  195. | NOT search_condition
  196. | '(' search_condition ')'
  197. | predicate

  198. predicate → comparison_predicate
  199. | between_predicate
  200. | like_predicate
  201. | test_for_null
  202. | in_predicate
  203. | all_or_any_predicate
  204. | existence_test
  205. | scalar_exp_predicate

  206. scalar_exp_predicate → scalar_exp

  207. comparison_predicate → scalar_exp COMPARISON scalar_exp
  208. | scalar_exp COMPARISON subquery

  209. between_predicate → scalar_exp NOT BETWEEN scalar_exp AND scalar_exp
  210. | scalar_exp BETWEEN scalar_exp AND scalar_exp

  211. like_predicate → scalar_exp NOT LIKE scalar_exp opt_escape
  212. | scalar_exp LIKE scalar_exp opt_escape

  213. opt_escape → ε
  214. | ESCAPE atom
  215. | BEGINX ESCAPE atom ENDX

  216. test_for_null → column_ref IS NOT NULLX
  217. | column_ref IS NULLX

  218. in_predicate → scalar_exp NOT IN subquery
  219. | scalar_exp IN subquery
  220. | scalar_exp NOT IN '(' scalar_exp_commalist ')'
  221. | scalar_exp IN '(' scalar_exp_commalist ')'

  222. all_or_any_predicate → scalar_exp COMPARISON any_all_some subquery

  223. any_all_some → ANY
  224. | ALL
  225. | SOME

  226. existence_test → EXISTS subquery

  227. subquery → '(' SELECT opt_all_distinct selection table_exp ')'

  228. scalar_exp → scalar_exp '+' scalar_exp
  229. | scalar_exp '-' scalar_exp
  230. | scalar_exp '*' scalar_exp
  231. | scalar_exp '/' scalar_exp
  232. | '+' scalar_exp %prec UMINUS
  233. | '-' scalar_exp %prec UMINUS
  234. | atom
  235. | column_ref
  236. | function_ref
  237. | '(' scalar_exp ')'
  238. | '(' scalar_exp ',' scalar_exp_commalist ')'
  239. | function_call
  240. | as_expression
  241. | assignment_statement
  242. | cvt_exp

  243. cvt_exp → CONVERT '(' data_type ',' scalar_exp ')'

  244. as_expression → scalar_exp AS NAME data_type
  245. | scalar_exp AS NAME

  246. opt_scalar_exp_commalist → ε
  247. | scalar_exp_commalist

  248. function_call → q_table_name '(' opt_scalar_exp_commalist ')'
  249. | BEGIN_FN_X NAME '(' opt_scalar_exp_commalist ')' ENDX
  250. | BEGIN_FN_X USER '(' opt_scalar_exp_commalist ')' ENDX
  251. | BEGIN_FN_X CHARACTER '(' opt_scalar_exp_commalist ')' ENDX
  252. | CALL '(' scalar_exp ')' '(' opt_scalar_exp_commalist ')'

  253. obe_literal → BEGINX NAME atom ENDX

  254. scalar_exp_commalist → scalar_exp
  255. | scalar_exp_commalist ',' scalar_exp

  256. atom → parameter_ref
  257. | literal
  258. | USER
  259. | obe_literal

  260. parameter_ref → parameter
  261. | parameter parameter
  262. | parameter INDICATOR parameter

  263. function_ref → AMMSC '(' '*' ')'
  264. | AMMSC '(' DISTINCT scalar_exp ')'
  265. | AMMSC '(' ALL scalar_exp ')'
  266. | AMMSC '(' scalar_exp ')'

  267. literal → STRING
  268. | INTNUM
  269. | APPROXNUM
  270. | NULLX

  271. q_table_name → NAME
  272. | NAME '.' NAME
  273. | NAME '.' NAME '.' NAME
  274. | NAME '.'  '.' NAME

  275. new_table_name → NAME
  276. | NAME '.' NAME
  277. | NAME '.' NAME '.' NAME
  278. | NAME '.'  '.' NAME

  279. table → q_table_name
  280. | q_table_name AS NAME
  281. | q_table_name NAME

  282. column_ref → NAME
  283. | NAME '.' NAME
  284. | NAME '.' NAME '.' NAME
  285. | NAME '.' NAME '.' NAME '.' NAME
  286. | NAME '.' '.' NAME '.' NAME
  287. | '*'
  288. | NAME '.' '*'
  289. | NAME '.' NAME '.' '*'
  290. | NAME '.' NAME '.' NAME '.' '*'
  291. | NAME '.' '.' NAME '.' '*'

  292. data_type → CHARACTER
  293. | VARCHAR
  294. | VARCHAR '(' INTNUM ')'
  295. | CHARACTER '(' INTNUM ')'
  296. | NUMERIC
  297. | NUMERIC '(' INTNUM ')'
  298. | NUMERIC '(' INTNUM ',' INTNUM ')'
  299. | DECIMAL
  300. | DECIMAL '(' INTNUM ')'
  301. | DECIMAL '(' INTNUM ',' INTNUM ')'
  302. | INTEGER
  303. | SMALLINT
  304. | FLOAT
  305. | FLOAT '(' INTNUM ')'
  306. | REAL
  307. | DOUBLE PRECISION
  308. | LONG VARCHAR
  309. | LONG VARBINARY
  310. | TIMESTAMP
  311. | DATETIME
  312. | TIME
  313. | DATE
  314. | OWNER

  315. column → NAME

  316. index → NAME

  317. cursor → NAME

  318. parameter → PARAMETER

  319. user → NAME

  320. opt_log → ε
  321. | scalar_exp

  322. comma_opt_log → ε
  323. | ',' scalar_exp

  324. admin_statement → CHECKPOINT opt_log
  325. | SHUTDOWN opt_log
  326. | SET REPLICATION atom
  327. | LOG OFF
  328. | LOG ON

  329. sql → routine_declaration
  330. | trigger_def
  331. | drop_trigger

  332. routine_declaration → CREATE routine_head new_table_name rout_parameter_list
  333. opt_return compound_statement
  334.      

  335. routine_head → FUNCTION
  336. | PROCEDURE

  337. opt_return → ε
  338. | RETURNS data_type

  339. rout_parameter_list → '(' parameter_commalist ')'

  340. parameter_commalist → rout_parameter
  341. | parameter_commalist ',' rout_parameter

  342. rout_parameter → parameter_mode column_ref data_type

  343. parameter_mode → IN
  344. | OUT
  345. | INOUT

  346. routine_statement → select_statement
  347. | update_statement_positioned
  348. | update_statement_searched
  349. | insert_statement
  350. | delete_statement_positioned
  351. | delete_statement_searched
  352. | close_statement
  353. | fetch_statement
  354. | open_statement
  355. | commit_statement
  356. */
  357. | ';'

  358. compound_statement → BEGINX statement_list ENDX

  359. statement_list → statement_in_cs
  360. | statement_list statement_in_cs

  361. statement_in_cs → local_declaration ';'
  362. | compound_statement
  363. | routine_statement ';'
  364. | control_statement
  365. | NAME '→' statement

  366. statement → routine_statement ';'
  367. | control_statement
  368. | compound_statement

  369. local_declaration → cursor_def
  370. | variable_declaration
  371. | handler_declaration

  372. variable_declaration → DECLARE variable_list data_type

  373. variable_list → NAME
  374. | variable_list ',' NAME

  375. condition → NOT FOUND
  376. | SQLSTATE STRING

  377. handler_declaration → WHENEVER condition GOTO NAME
  378. | WHENEVER condition GO TO NAME

  379. control_statement → call_statement ';'
  380. | return_statement ';'
  381. | assignment_statement ';'
  382. | if_statement
  383. | goto_statement ';'
  384. | while_statement

  385. assignment_statement → lvalue EQUALS scalar_exp

  386. lvalue → column_ref

  387. if_statement → IF '(' search_condition ')' statement opt_else

  388. opt_else → ε
  389. | ELSE statement

  390. call_statement → CALL q_table_name '(' opt_scalar_exp_commalist ')'
  391. | function_call

  392. goto_statement → GOTO NAME
  393. | GO TO NAME

  394. return_statement → RETURN scalar_exp
  395. | RETURN

  396. while_statement → WHILE '(' search_condition ')' statement

  397. trigger_def → CREATE TRIGGER NAME action_time event ON q_table_name
  398. opt_old_ref compound_statement

  399. action_time → BEFORE
  400. | AFTER

  401. event → INSERT
  402. | UPDATE
  403. | DELETE

  404. opt_old_ref → ε
  405. | REFERENCING old_commalist

  406. old_commalist → old_alias
  407. | old_commalist ',' old_alias

  408. old_alias → OLD AS NAME
  409. | NEW AS NAME

  410. drop_trigger → DROP TRIGGER q_table_name
复制代码
发表于 2018-6-6 18:43:49 | 显示全部楼层
VBProFan 发表于 2018-6-4 07:47
有道理,LISP的语法太简单了,或者说它是一门3-型语言,其他是2-型的

什么叫3-型语言?是正则语言吗?Lisp要求括号配对,这是正则语言不能描述的。
用Lisp其实就是在手写抽象语法树。

点评

介于2、3之间的语言,哈哈  发表于 2018-6-7 21:29
有道理  发表于 2018-6-7 21:28
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2018-6-3 12:07:23 | 显示全部楼层
C:
  1. program → external_declaration | program external_declaration

  2. external_declaration → function_definition | declaration
  3.    
  4. function_definition → type_specifier declarator compound_statement

  5. type_specifier → VOID
  6. | CHAR
  7. | INT
  8. | FLOAT

  9. declarator → pointer direct_declarator | direct_declarator

  10. pointer → '*' | '*' pointer

  11. direct_declarator → IDENTIFIER
  12. | direct_declarator '[' ']'
  13. | direct_declarator '[' constant_expression ']'
  14. | IDENTIFIER '(' parameter_list ')'
  15. | IDENTIFIER '(' ')'
  16. | direct_declarator ',' identifier_list

  17. identifier_list → IDENTIFIER | identifier_list ',' IDENTIFIER

  18. constant_expression → conditional_expression

  19. parameter_list → parameter_declaration | parameter_list ',' parameter_declaration

  20. parameter_declaration  → declaration_specifiers IDENTIFIER

  21. compound_statement → '{' '}'
  22. | '{' statement_list '}'
  23. | '{' declaration_list statement_list '}'

  24. declaration_list → declaration
  25. | declaration_list declaration

  26. declaration → init_declarator
  27. | init_declarator_list ',' init_declarator

  28. init_declarator → declarator
  29. | declarator '=' initializer

  30. initializer → assignment_expression
  31. | '{' initializer_list '}'
  32. | '{' initializer_list ',' '}'

  33. initializer_list → initializer
  34. | initializer_list ',' initializer

  35. statement_list → statement | statement_list statement

  36. statement → compound_statement
  37. | expression_statement
  38. | selection_statement
  39. | iteration_statement
  40. | jump_statement

  41. expression_statement → ';' | expression ';'

  42. selection_statement → IF '(' expression ')' statement
  43. | IF '(' expression ')' statement ELSE statement

  44. iteration_statement → WHILE '(' expression ')' statement
  45. | FOR '(' expression_statement expression_statement ')' statement
  46. | FOR '(' expression_statement expression_statement expression ')' statement

  47. jump_statement → CONTINUE ';'
  48. | BREAK ';'
  49. | RETURN ';'
  50. | RETURN expression ';'

  51. expression → assignment_expression
  52. | expression ',' assignment_expression

  53. assignment_expression → conditional_expression
  54. | unary_expression assignment_operator assignment_expression

  55. conditional_expression → logical_or_expression
  56. | logical_or_expression '?' expression ':' conditional_expression

  57. logical_or_expression → logical_and_expression
  58. | logical_or_expression OR_OP logical_and_expression

  59. logical_and_expression → inclusive_or_expression
  60. | logical_and_expression AND_OP inclusive_or_expression

  61. inclusive_or_expression → exclusive_or_expression
  62. | inclusive_or_expression '|' exclusive_or_expression

  63. exclusive_or_expression → and_expression
  64. | exclusive_or_expression '^' and_expression

  65. and_expression → equality_expression
  66. | and_expression '&' equality_expression

  67. equality_expression → relational_expression
  68. | equality_expression EQ_OP relational_expression
  69. | equality_expression NE_OP relational_expression

  70. relational_expression → shift_expression
  71. | relational_expression '<' shift_expression
  72. | relational_expression '>' shift_expression
  73. | relational_expression LE_OP shift_expression
  74. | relational_expression GE_OP shift_expression

  75. shift_expression → additive_expression
  76. | shift_expression LEFT_OP additive_expression
  77. | shift_expression RIGHT_OP additive_expression

  78. additive_expression → multiplicative_expression
  79. | additive_expression '+' multiplicative_expression
  80. | additive_expression '-' multiplicative_expression

  81. multiplicative_expression → cast_expression
  82. | multiplicative_expression '*' cast_expression
  83. | multiplicative_expression '/' cast_expression
  84. | multiplicative_expression '%' cast_expression

  85. cast_expression → unary_expression
  86. | '(' type_name ')' cast_expression

  87. unary_expression → postfix_expression
  88. | INC_OP unary_expression
  89. | DEC_OP unary_expression
  90. | unary_operator cast_expression
  91. | SIZEOF unary_expression
  92. | SIZEOF '(' type_name ')'

  93. postfix_expression → primary_expression
  94. | postfix_expression '[' expression ']'
  95. | postfix_expression '(' ')'
  96. | postfix_expression '(' argument_expression_list ')'
  97. | postfix_expression '.' IDENTIFIER
  98. | postfix_expression PTR_OP IDENTIFIER
  99. | postfix_expression INC_OP
  100. | postfix_expression DEC_OP

  101. primary_expression → IDENTIFIER
  102. | CONSTANT
  103. | STRING_LITERAL
  104. | '(' expression ')'

  105. argument_expression_list → assignment_expression
  106. | argument_expression_list ',' assignment_expression

  107. unary_operator → '&'
  108. | '*'
  109. | '+'
  110. | '-'
  111. | '~'
  112. | '!'

  113. assignment_operator → '='
  114. | MUL_ASSIGN
  115. | DIV_ASSIGN
  116. | MOD_ASSIGN
  117. | ADD_ASSIGN
  118. | SUB_ASSIGN
  119. | LEFT_ASSIGN
  120. | RIGHT_ASSIGN
  121. | AND_ASSIGN
  122. | XOR_ASSIGN
  123. | OR_ASSIGN

  124. storage_class_specifier → TYPEDEF
  125. | EXTERN
  126. | STATIC
  127. | AUTO
  128. | REGISTER

  129. struct_or_union_specifier → struct_or_union IDENTIFIER '{' struct_declaration_list '}'
  130. | struct_or_union '{' struct_declaration_list '}'
  131. | struct_or_union IDENTIFIER

  132. struct_or_union → STRUCT | UNION

  133. struct_declaration_list → struct_declaration | struct_declaration_list struct_declaration

  134. struct_declaration → specifier_qualifier_list struct_declarator_list ';'

  135. specifier_qualifier_list → type_specifier specifier_qualifier_list
  136. | type_specifier
  137. | type_qualifier specifier_qualifier_list
  138. | type_qualifier
  139.    
  140. struct_declarator_list → struct_declarator | struct_declarator_list ',' struct_declarator
  141.    
  142. struct_declarator → declarator
  143. | ':' constant_expression
  144. | declarator ':' constant_expression
  145.    
  146. enum_specifier → ENUM '{' enumerator_list '}'
  147. | ENUM IDENTIFIER '{' enumerator_list '}'
  148. | ENUM IDENTIFIER
  149.    
  150. enumerator_list → enumerator
  151. | enumerator_list ',' enumerator
  152.    
  153. Enumerator → IDENTIFIER | IDENTIFIER '=' constant_expression
  154.    
  155. type_qualifier → CONST | VOLATILE
  156.    
  157. type_qualifier_list → type_qualifier | type_qualifier_list type_qualifier
  158.    
  159. parameter_type_list → parameter_list | parameter_list ',' ELLIPSIS
  160.    
  161. parameter_list → parameter_declaration
  162. | parameter_list ',' parameter_declaration
  163.    
  164. type_name → specifier_qualifier_list
  165. | specifier_qualifier_list abstract_declarator
  166.    
  167. abstract_declarator → pointer
  168. | direct_abstract_declarator
  169. | pointer direct_abstract_declarator
  170.    
  171. direct_abstract_declarator → '(' abstract_declarator ')'
  172. | '[' ']'
  173. | '[' constant_expression ']'
  174. | direct_abstract_declarator '[' ']'
  175. | direct_abstract_declarator '[' constant_expression ']'
  176. | '(' ')'
  177. | '(' parameter_type_list ')'
  178. | direct_abstract_declarator '(' ')'
  179. | direct_abstract_declarator '(' parameter_type_list ')'
  180.    
  181. labeled_statement → IDENTIFIER ':' statement
  182. | CASE constant_expression ':' statement
  183. | DEFAULT ':' statement
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-3 12:08:17 | 显示全部楼层
Python:
  1. # Grammar for Python

  2. # NOTE WELL: You should also follow all the steps listed at
  3. # https://devguide.python.org/grammar/

  4. # Start symbols for the grammar:
  5. #       single_input is a single interactive statement;
  6. #       file_input is a module or sequence of commands read from an input file;
  7. #       eval_input is the input for the eval() functions.
  8. # NB: compound_stmt in single_input is followed by extra NEWLINE!
  9. single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
  10. file_input: (NEWLINE | stmt)* ENDMARKER
  11. eval_input: testlist NEWLINE* ENDMARKER

  12. decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
  13. decorators: decorator+
  14. decorated: decorators (classdef | funcdef | async_funcdef)

  15. async_funcdef: ASYNC funcdef
  16. funcdef: 'def' NAME parameters ['->' test] ':' suite

  17. parameters: '(' [typedargslist] ')'
  18. typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
  19.         '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
  20.       | '**' tfpdef [',']]]
  21.   | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
  22.   | '**' tfpdef [','])
  23. tfpdef: NAME [':' test]
  24. varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
  25.         '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
  26.       | '**' vfpdef [',']]]
  27.   | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
  28.   | '**' vfpdef [',']
  29. )
  30. vfpdef: NAME

  31. stmt: simple_stmt | compound_stmt
  32. simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
  33. small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
  34.              import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
  35. expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
  36.                      ('=' (yield_expr|testlist_star_expr))*)
  37. annassign: ':' test ['=' test]
  38. testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
  39. augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
  40.             '<<=' | '>>=' | '**=' | '//=')
  41. # For normal and annotated assignments, additional restrictions enforced by the interpreter
  42. del_stmt: 'del' exprlist
  43. pass_stmt: 'pass'
  44. flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
  45. break_stmt: 'break'
  46. continue_stmt: 'continue'
  47. return_stmt: 'return' [testlist]
  48. yield_stmt: yield_expr
  49. raise_stmt: 'raise' [test ['from' test]]
  50. import_stmt: import_name | import_from
  51. import_name: 'import' dotted_as_names
  52. # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
  53. import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
  54.               'import' ('*' | '(' import_as_names ')' | import_as_names))
  55. import_as_name: NAME ['as' NAME]
  56. dotted_as_name: dotted_name ['as' NAME]
  57. import_as_names: import_as_name (',' import_as_name)* [',']
  58. dotted_as_names: dotted_as_name (',' dotted_as_name)*
  59. dotted_name: NAME ('.' NAME)*
  60. global_stmt: 'global' NAME (',' NAME)*
  61. nonlocal_stmt: 'nonlocal' NAME (',' NAME)*
  62. assert_stmt: 'assert' test [',' test]

  63. compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
  64. async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
  65. if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
  66. while_stmt: 'while' test ':' suite ['else' ':' suite]
  67. for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
  68. try_stmt: ('try' ':' suite
  69.            ((except_clause ':' suite)+
  70.             ['else' ':' suite]
  71.             ['finally' ':' suite] |
  72.            'finally' ':' suite))
  73. with_stmt: 'with' with_item (',' with_item)*  ':' suite
  74. with_item: test ['as' expr]
  75. # NB compile.c makes sure that the default except clause is last
  76. except_clause: 'except' [test ['as' NAME]]
  77. suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT

  78. test: or_test ['if' or_test 'else' test] | lambdef
  79. test_nocond: or_test | lambdef_nocond
  80. lambdef: 'lambda' [varargslist] ':' test
  81. lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
  82. or_test: and_test ('or' and_test)*
  83. and_test: not_test ('and' not_test)*
  84. not_test: 'not' not_test | comparison
  85. comparison: expr (comp_op expr)*
  86. # <> isn't actually a valid comparison operator in Python. It's here for the
  87. # sake of a __future__ import described in PEP 401 (which really works :-)
  88. comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
  89. star_expr: '*' expr
  90. expr: xor_expr ('|' xor_expr)*
  91. xor_expr: and_expr ('^' and_expr)*
  92. and_expr: shift_expr ('&' shift_expr)*
  93. shift_expr: arith_expr (('<<'|'>>') arith_expr)*
  94. arith_expr: term (('+'|'-') term)*
  95. term: factor (('*'|'@'|'/'|'%'|'//') factor)*
  96. factor: ('+'|'-'|'~') factor | power
  97. power: atom_expr ['**' factor]
  98. atom_expr: [AWAIT] atom trailer*
  99. atom: ('(' [yield_expr|testlist_comp] ')' |
  100.        '[' [testlist_comp] ']' |
  101.        '{' [dictorsetmaker] '}' |
  102.        NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
  103. testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
  104. trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
  105. subscriptlist: subscript (',' subscript)* [',']
  106. subscript: test | [test] ':' [test] [sliceop]
  107. sliceop: ':' [test]
  108. exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
  109. testlist: test (',' test)* [',']
  110. dictorsetmaker: ( ((test ':' test | '**' expr)
  111.                    (comp_for | (',' (test ':' test | '**' expr))* [','])) |
  112.                   ((test | star_expr)
  113.                    (comp_for | (',' (test | star_expr))* [','])) )

  114. classdef: 'class' NAME ['(' [arglist] ')'] ':' suite

  115. arglist: argument (',' argument)*  [',']

  116. # The reason that keywords are test nodes instead of NAME is that using NAME
  117. # results in an ambiguity. ast.c makes sure it's a NAME.
  118. # "test '=' test" is really "keyword '=' test", but we have no such token.
  119. # These need to be in a single rule to avoid grammar that is ambiguous
  120. # to our LL(1) parser. Even though 'test' includes '*expr' in star_expr,
  121. # we explicitly match '*' here, too, to give it proper precedence.
  122. # Illegal combinations and orderings are blocked in ast.c:
  123. # multiple (test comp_for) arguments are blocked; keyword unpackings
  124. # that precede iterable unpackings are blocked; etc.
  125. argument: ( test [comp_for] |
  126.             test '=' test |
  127.             '**' test |
  128.             '*' test )

  129. comp_iter: comp_for | comp_if
  130. comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
  131. comp_if: 'if' test_nocond [comp_iter]

  132. # not used in grammar, but may appear in "node" passed from Parser to Compiler
  133. encoding_decl: NAME

  134. yield_expr: 'yield' [yield_arg]
  135. yield_arg: 'from' test | testlist
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-3 12:10:32 | 显示全部楼层
网上就只能找到这三种了。我还对以下语言感兴趣:BASIC, Pascal, Matlab, Java, PHP, asp, jsp, prolog, LISP, C++, C#, sed, awk……
谁知道哪里可以找到它们的文法产生式啊?
回复 支持 反对

使用道具 举报

发表于 2018-6-3 19:10:53 | 显示全部楼层
找不到的话就自己写吧。另外,Lisp不需要语法分析,根本就用不着这些。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-4 07:47:30 | 显示全部楼层
Apple_0 发表于 2018-6-3 19:10
找不到的话就自己写吧。另外,Lisp不需要语法分析,根本就用不着这些。

有道理,LISP的语法太简单了,或者说它是一门3-型语言,其他是2-型的
回复 支持 反对

使用道具 举报

 楼主| 发表于 5 天前 | 显示全部楼层
Apple_0 发表于 2018-6-6 18:43
什么叫3-型语言?是正则语言吗?Lisp要求括号配对,这是正则语言不能描述的。
用Lisp其实就是在手写抽象 ...

感觉 LISP 就是对二叉语法树进行一个前序遍历(根、左、右)
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2018-6-18 06:16

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表