p2l.ypp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. %{
  2. /*
  3. * grammar.y
  4. *
  5. * Pascal grammar in Yacc format, based originally on BNF given
  6. * in "Standard Pascal -- User Reference Manual", by Doug Cooper.
  7. * This in turn is the BNF given by the ANSI and ISO Pascal standards,
  8. * and so, is PUBLIC DOMAIN. The grammar is for ISO Level 0 Pascal.
  9. * The grammar has been massaged somewhat to make it LALR, and added
  10. * the following extensions.
  11. *
  12. * constant expressions
  13. * otherwise statement in a case
  14. * productions to correctly match else's with if's
  15. * beginnings of a separate compilation facility
  16. *
  17. * Retrieved from a web page by samiam@moorecad.com,
  18. * http://www.moorecad.com/standardpascal/yacclex.html
  19. * which was reached via a link saying it had a range of free
  20. * grammars.
  21. *
  22. * $Id$
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include "p2l.h"
  27. int yylex();
  28. int yyparse();
  29. void yyerror(const char *message);
  30. void yyerror(const char *message)
  31. { printf("\nParse error '%s'\n", message);
  32. exit(1);
  33. }
  34. #define YYSTYPE node *
  35. %}
  36. %token AND ARRAY ASSIGNMENT CASE CHARACTER_STRING COLON COMMA CONST DIGSEQ
  37. %token DIV DO DOT DOTDOT DOWNTO ELSE END EQUAL EXTERNAL FOR FORWARD FUNCTION
  38. %token GE GOTO GT IDENTIFIER IF IN LABEL LBRAC LE LPAREN LT MINUS MOD NIL NOT
  39. %token NOTEQUAL OF OR OTHERWISE PACKED PBEGIN PFILE PLUS PROCEDURE PROGRAM RBRAC
  40. %token REALNUMBER RECORD REPEAT RPAREN SEMICOLON SET SLASH STAR STARSTAR THEN
  41. %token TO TYPE UNTIL UPARROW VAR WHILE WITH
  42. %%
  43. file : program { prnode($1); printf("\n"); }
  44. | module { prnode($1); printf("\n"); }
  45. ;
  46. program : program_heading semicolon block DOT
  47. { $$ = item("program", $1, $3); }
  48. ;
  49. program_heading : PROGRAM identifier
  50. { $$ = item("heading", $2, NULL); }
  51. | PROGRAM identifier LPAREN identifier_list RPAREN
  52. { $$ = item("heading", $2, $4); }
  53. ;
  54. identifier_list : identifier_list comma identifier
  55. { $$ = item("idlist_append", $1, $3); }
  56. | identifier { $$ = item("idlist_append", NULL, $1); }
  57. ;
  58. block : label_declaration_part
  59. constant_definition_part
  60. type_definition_part
  61. variable_declaration_part
  62. procedure_and_function_declaration_part
  63. statement_part
  64. { $$ = item("block", $1, $2, $3, $4, $5, $6); }
  65. ;
  66. module : constant_definition_part
  67. type_definition_part
  68. variable_declaration_part
  69. procedure_and_function_declaration_part
  70. { $$ = item("module", $1, $2, $3, $4); }
  71. ;
  72. label_declaration_part : LABEL label_list semicolon
  73. { $$ = item("labeldec", $2); }
  74. |
  75. { $$ = NULL; }
  76. ;
  77. label_list : label_list comma label
  78. { $$ = item("lablistappend", $1, $3); }
  79. | label { $$ = item("lablistappend", NULL, $1); }
  80. ;
  81. label : DIGSEQ { $$ = symbol("label", yytext); }
  82. ;
  83. constant_definition_part : CONST constant_list
  84. { $$ = $2; }
  85. | { $$ = NULL; }
  86. ;
  87. constant_list : constant_list constant_definition
  88. { $$ = item("constlist_append", $1, $2); }
  89. | constant_definition
  90. { $$ = item("constlist_append", NULL, $1); }
  91. ;
  92. constant_definition : identifier EQUAL cexpression semicolon
  93. { $$ = item("constdef", $1, $3); }
  94. ;
  95. /*constant : cexpression ; /* good stuff! */
  96. cexpression : csimple_expression
  97. { $$ = $1; }
  98. | csimple_expression relop csimple_expression
  99. { $$ = item("csimple", $2, $1, $3); }
  100. ;
  101. csimple_expression : cterm
  102. { $$ = $1; }
  103. | csimple_expression addop cterm
  104. { $$ = item("cterm", $2, $1, $3); }
  105. ;
  106. cterm : cfactor
  107. { $$ = $1; }
  108. | cterm mulop cfactor
  109. { $$ = item("cfactor", $2, $1, $3); }
  110. ;
  111. cfactor : sign cfactor
  112. { $$ = item("signedcfactor", $1, $2); }
  113. | cexponentiation
  114. { $$ = $1; }
  115. ;
  116. cexponentiation : cprimary
  117. { $$ = $1; }
  118. | cprimary STARSTAR cexponentiation
  119. { $$ = item("cexpon", $1, $3); }
  120. ;
  121. cprimary : identifier
  122. { $$ = $1; }
  123. | LPAREN cexpression RPAREN
  124. { $$ = $2; }
  125. | unsigned_constant
  126. { $$ = $1; }
  127. | NOT cprimary
  128. { $$ = item("not", $2); }
  129. ;
  130. constant : non_string
  131. { $$ = $1; }
  132. | sign non_string
  133. { $$ = item("signedconstant", $1, $2); }
  134. | CHARACTER_STRING
  135. { $$ = string(yytext); }
  136. ;
  137. sign : PLUS { $$ = symbol("plus"); }
  138. | MINUS { $$ = symbol("minus"); }
  139. ;
  140. non_string : DIGSEQ
  141. { $$ = symbol("sdigseq", yytext); }
  142. | identifier
  143. { $$ = $1; }
  144. | REALNUMBER
  145. ;
  146. type_definition_part : TYPE type_definition_list
  147. { $$ = $2; }
  148. | {$$ = NULL; }
  149. ;
  150. type_definition_list : type_definition_list type_definition
  151. { $$ = item("typedeflist", $1, $2); }
  152. | type_definition { $$ = $1; }
  153. ;
  154. type_definition : identifier EQUAL type_denoter semicolon
  155. { $$ = item("typedef", $1, $3); }
  156. ;
  157. type_denoter : identifier
  158. { $$ = $1; }
  159. | new_type { $$ = $1; }
  160. ;
  161. new_type : new_ordinal_type
  162. { $$ = $1; }
  163. | new_structured_type
  164. { $$ = $1; }
  165. | new_pointer_type
  166. { $$ = $1; }
  167. ;
  168. new_ordinal_type : enumerated_type
  169. { $$ = $1; }
  170. | subrange_type
  171. { $$ = $1; }
  172. ;
  173. enumerated_type : LPAREN identifier_list RPAREN
  174. { $$ = item("emumeratedtype", $2); }
  175. ;
  176. subrange_type : constant DOTDOT constant
  177. { $$ = item("subrangetype", $1, $3); }
  178. ;
  179. new_structured_type : structured_type
  180. { $$ = $1; }
  181. | PACKED structured_type
  182. { $$ = item("packedtype", $2); }
  183. ;
  184. structured_type : array_type
  185. { $$ = $1; }
  186. | record_type
  187. { $$ = $1; }
  188. | set_type
  189. { $$ = $1; }
  190. | file_type
  191. { $$ = $1; }
  192. ;
  193. array_type : ARRAY LBRAC index_list RBRAC OF component_type
  194. { $$ = item("arraytype", $3, $6); }
  195. ;
  196. index_list : index_list comma index_type
  197. { $$ = item("indexlist", $1, $3); }
  198. | index_type
  199. { $$ = $1; }
  200. ;
  201. index_type : ordinal_type
  202. { $$ = $1; }
  203. ;
  204. ordinal_type : new_ordinal_type
  205. { $$ = $1; }
  206. | identifier
  207. { $$ = $1; }
  208. ;
  209. component_type : type_denoter
  210. { $$ = $1; }
  211. ;
  212. record_type : RECORD record_section_list END
  213. { $$ = item("recordtype", $2, NULL); }
  214. | RECORD record_section_list semicolon variant_part END
  215. { $$ = item("recordtype", $2, $4); }
  216. | RECORD variant_part END
  217. { $$ = item("recordtype", NULL, $2); }
  218. ;
  219. record_section_list : record_section_list semicolon record_section
  220. { $$ = item("recseclist", $1, $3); }
  221. | record_section
  222. { $$ = $1; }
  223. ;
  224. record_section : identifier_list COLON type_denoter
  225. { $$ = item("recsec", $1, $3); }
  226. ;
  227. variant_part : CASE variant_selector OF variant_list semicolon
  228. { $$ = item("varpart", $2, $4); }
  229. | CASE variant_selector OF variant_list
  230. { $$ = item("varpart", $2, $4); }
  231. | { $$ = NULL; }
  232. ;
  233. variant_selector : tag_field COLON tag_type
  234. { $$ = item("varsel", $1, $3); }
  235. | tag_type
  236. { $$ = $1; }
  237. ;
  238. variant_list : variant_list semicolon variant
  239. { $$ = item("varlist", $1, $3); }
  240. | variant
  241. { $$ = $1; }
  242. ;
  243. variant : case_constant_list COLON LPAREN record_section_list RPAREN
  244. { $$ = item("variant", $1, $4, NULL); }
  245. | case_constant_list COLON LPAREN record_section_list semicolon
  246. variant_part RPAREN
  247. { $$ = item("variant", $1, $4, $6); }
  248. | case_constant_list COLON LPAREN variant_part RPAREN
  249. { $$ = item("variant", $1, NULL, $4); }
  250. case_constant_list : case_constant_list comma case_constant
  251. { $$ = item("appendcaseconstant", $1, $3); }
  252. | case_constant
  253. { $$ = $1; }
  254. ;
  255. case_constant : constant { $$ = $1; }
  256. | constant DOTDOT constant { $$ = item("range", $1, $3); }
  257. ;
  258. tag_field : identifier
  259. { $$ = $1; }
  260. ;
  261. tag_type : identifier
  262. { $$ = $1; }
  263. ;
  264. set_type : SET OF base_type
  265. { $$ = item("setof", $3); }
  266. ;
  267. base_type : ordinal_type
  268. { $$ = $1; }
  269. ;
  270. file_type : PFILE OF component_type
  271. { $$ = item("filetype", $3); }
  272. ;
  273. new_pointer_type : UPARROW domain_type
  274. { $$ = item("newpointertype", $2); }
  275. ;
  276. domain_type : identifier
  277. { $$ = $1; }
  278. ;
  279. variable_declaration_part : VAR variable_declaration_list semicolon
  280. { $$ = item("vardecpart", $2); }
  281. | { $$ = NULL; }
  282. ;
  283. variable_declaration_list :
  284. variable_declaration_list semicolon variable_declaration
  285. { $$ = item("vardeclist", $1, $3); }
  286. | variable_declaration
  287. { $$ = NULL; }
  288. ;
  289. variable_declaration : identifier_list COLON type_denoter
  290. { $$ = item("vardec", $1, $3); }
  291. ;
  292. procedure_and_function_declaration_part :
  293. proc_or_func_declaration_list semicolon
  294. { $$ = $1; }
  295. | { $$ = NULL; }
  296. ;
  297. proc_or_func_declaration_list :
  298. proc_or_func_declaration_list semicolon proc_or_func_declaration
  299. { $$ = item("procdeflist", $1, $3); }
  300. | proc_or_func_declaration
  301. { $$ = item("procdeflist", NULL, $1); }
  302. ;
  303. proc_or_func_declaration : procedure_declaration
  304. { $$ = $1; }
  305. | function_declaration
  306. { $$ = $1; }
  307. ;
  308. procedure_declaration : procedure_heading semicolon directive
  309. { $$ = item("procdecdir", $1, $3); }
  310. | procedure_heading semicolon procedure_block
  311. { $$ = item("procdecblock", $1, $3); }
  312. ;
  313. procedure_heading : procedure_identification
  314. { $$ = item("prochead", $1, NULL); }
  315. | procedure_identification formal_parameter_list
  316. { $$ = item("prochead", $1, $2); }
  317. ;
  318. directive : FORWARD { $$ = symbol("forward"); }
  319. | EXTERNAL { $$ = symbol("external"); }
  320. ;
  321. formal_parameter_list : LPAREN formal_parameter_section_list RPAREN
  322. { $$ = $2; }
  323. ;
  324. formal_parameter_section_list : formal_parameter_section_list semicolon formal_parameter_section
  325. { $$ = item("formallist", $1, $3); }
  326. | formal_parameter_section
  327. { $$ = item("formallist", NULL, $1); }
  328. ;
  329. formal_parameter_section : value_parameter_specification
  330. { $$ = $1; }
  331. | variable_parameter_specification
  332. { $$ = $1; }
  333. | procedural_parameter_specification
  334. { $$ = $1; }
  335. | functional_parameter_specification
  336. { $$ = $1; }
  337. ;
  338. value_parameter_specification : identifier_list COLON identifier
  339. { $$ = item("valparam", $1, $3); }
  340. ;
  341. variable_parameter_specification : VAR identifier_list COLON identifier
  342. { $$ = item("varparam", $2, $4); }
  343. ;
  344. procedural_parameter_specification : procedure_heading
  345. { $$ = item("procparam", $1); }
  346. ;
  347. functional_parameter_specification : function_heading
  348. { $$ = item("funcparam", $1); }
  349. ;
  350. procedure_identification : PROCEDURE identifier
  351. { $$ = item("procid", $2); }
  352. ;
  353. procedure_block : block
  354. { $$ = $1; }
  355. ;
  356. function_declaration : function_heading semicolon directive
  357. { $$ = item("fiunheaddir", $1, $3); }
  358. | function_identification semicolon function_block
  359. { $$ = item("funidblock", $1, $3); }
  360. | function_heading semicolon function_block
  361. { $$ = item("funheadblock", $1, $3); }
  362. ;
  363. function_heading : FUNCTION identifier COLON result_type
  364. { $$ = item("funhead", $2, NULL, $4); }
  365. | FUNCTION identifier formal_parameter_list COLON result_type
  366. { $$ = item("funhead", $2, $3, $5); }
  367. ;
  368. result_type : identifier
  369. { $$ = $1; }
  370. ;
  371. function_identification : FUNCTION identifier
  372. { $$ = $2; }
  373. ;
  374. function_block : block
  375. { $$ = $1; }
  376. ;
  377. statement_part : compound_statement
  378. { $$ = $1; }
  379. ;
  380. compound_statement : PBEGIN statement_sequence END
  381. { $$ = $2; }
  382. ;
  383. statement_sequence : statement_sequence semicolon statement
  384. { $$ = item("statementsequence", $1, $3); }
  385. | statement
  386. { $$ = item("statementsequence", NULL, $1); }
  387. ;
  388. statement : open_statement
  389. { $$ = $1; }
  390. | closed_statement
  391. { $$ = $1; }
  392. ;
  393. open_statement : label COLON non_labeled_open_statement
  394. { $$ = item("labelled", $1, $3); }
  395. | non_labeled_open_statement
  396. { $$ = $1; }
  397. ;
  398. closed_statement : label COLON non_labeled_closed_statement
  399. { $$ = item("labelled", $1, $3); }
  400. | non_labeled_closed_statement
  401. { $$ = $1; }
  402. ;
  403. non_labeled_closed_statement : assignment_statement
  404. { $$ = $1; }
  405. | procedure_statement
  406. { $$ = $1; }
  407. | goto_statement
  408. { $$ = $1; }
  409. | compound_statement
  410. { $$ = $1; }
  411. | case_statement
  412. { $$ = $1; }
  413. | repeat_statement
  414. { $$ = $1; }
  415. | closed_with_statement
  416. { $$ = $1; }
  417. | closed_if_statement
  418. { $$ = $1; }
  419. | closed_while_statement
  420. { $$ = $1; }
  421. | closed_for_statement
  422. { $$ = $1; }
  423. |
  424. { $$ = NULL; }
  425. ;
  426. non_labeled_open_statement : open_with_statement
  427. { $$ = $1; }
  428. | open_if_statement
  429. { $$ = $1; }
  430. | open_while_statement
  431. { $$ = $1; }
  432. | open_for_statement
  433. { $$ = $1; }
  434. ;
  435. repeat_statement : REPEAT statement_sequence UNTIL boolean_expression
  436. { $$ = item("repeat", $2, $4); }
  437. ;
  438. open_while_statement : WHILE boolean_expression DO open_statement
  439. { $$ = item("while", $2, $4); }
  440. ;
  441. closed_while_statement : WHILE boolean_expression DO closed_statement
  442. { $$ = item("while", $2, $4); }
  443. ;
  444. open_for_statement : FOR control_variable ASSIGNMENT initial_value direction
  445. final_value DO open_statement
  446. { $$ = item("for", $2, $4, $5, $6, $8); }
  447. ;
  448. closed_for_statement : FOR control_variable ASSIGNMENT initial_value direction
  449. final_value DO closed_statement
  450. { $$ = item("for", $2, $4, $5, $6, $8); }
  451. ;
  452. open_with_statement : WITH record_variable_list DO open_statement
  453. { $$ = item("with", $2, $4); }
  454. ;
  455. closed_with_statement : WITH record_variable_list DO closed_statement
  456. { $$ = item("with", $2, $4); }
  457. ;
  458. open_if_statement : IF boolean_expression THEN statement
  459. { $$ = item("if", $2, $4, NULL); }
  460. | IF boolean_expression THEN closed_statement ELSE open_statement
  461. { $$ = item("if", $2, $4, $6); } ;
  462. closed_if_statement : IF boolean_expression THEN closed_statement
  463. ELSE closed_statement
  464. { $$ = item("if", $2, $4, $6); }
  465. ;
  466. assignment_statement : variable_access ASSIGNMENT expression
  467. { $$ = item("setq", $1, $3); }
  468. ;
  469. variable_access : identifier
  470. { $$ = $1; }
  471. | indexed_variable
  472. { $$ = $1; }
  473. | field_designator
  474. { $$ = $1; }
  475. | variable_access UPARROW
  476. { $$ = item("uparrow", $1); }
  477. ;
  478. indexed_variable : variable_access LBRAC index_expression_list RBRAC
  479. { $$ = item("indexed", $1, $3); }
  480. ;
  481. index_expression_list : index_expression_list comma index_expression
  482. { $$ = item("indexlist", $1, $3); }
  483. | index_expression
  484. { $$ = $1; }
  485. ;
  486. index_expression : expression
  487. { $$ = $1; }
  488. ;
  489. field_designator : variable_access DOT identifier
  490. { $$ = item("fielddesignator", $1, $3); }
  491. ;
  492. procedure_statement : identifier params
  493. { $$ = item("procstat", $1, $2); }
  494. | identifier
  495. { $$ = item("procstat", $1, NULL); }
  496. ;
  497. params : LPAREN actual_parameter_list RPAREN
  498. { $$ = $2; }
  499. ;
  500. actual_parameter_list : actual_parameter_list comma actual_parameter
  501. { $$ = item("paramlist", $1, $3); }
  502. | actual_parameter
  503. { $$ = item("paramlist", NULL, $1); }
  504. ;
  505. /*
  506. * this forces you to check all this to be sure that only write and
  507. * writeln use the 2nd and 3rd forms, you really can't do it easily in
  508. * the grammar, especially since write and writeln aren't reserved
  509. */
  510. actual_parameter : expression
  511. { $$ = $1; }
  512. | expression COLON expression
  513. { $$ = item("xcolon", $1, $3, NULL); }
  514. | expression COLON expression COLON expression
  515. { $$ = item("xcolon", $1, $3, $5); }
  516. ;
  517. goto_statement : GOTO label
  518. { $$ = item("goto", $2); }
  519. ;
  520. case_statement : CASE case_index OF case_list_element_list END
  521. { $$ = item("case", $2, $4, NULL); }
  522. | CASE case_index OF case_list_element_list SEMICOLON END
  523. { $$ = item("case", $2, $4, NULL); }
  524. | CASE case_index OF case_list_element_list semicolon
  525. otherwisepart statement END
  526. { $$ = item("case", $2, $4, $7); }
  527. | CASE case_index OF case_list_element_list semicolon
  528. otherwisepart statement SEMICOLON END
  529. { $$ = item("case", $2, $4, $7); }
  530. ;
  531. case_index : expression
  532. { $$ = $1; }
  533. ;
  534. case_list_element_list : case_list_element_list semicolon case_list_element
  535. { $$ = item("caseeltlist", $1, $3); }
  536. | case_list_element
  537. { $$ = $1; }
  538. ;
  539. case_list_element : case_constant_list COLON statement
  540. { $$ = item("caseelt", $1, $3); }
  541. ;
  542. otherwisepart : OTHERWISE
  543. { $$ = symbol("otherwise"); }
  544. | OTHERWISE COLON
  545. { $$ = symbol("otherwisecolon"); }
  546. ;
  547. control_variable : identifier
  548. { $$ = $1; }
  549. ;
  550. initial_value : expression
  551. { $$ = $1; }
  552. ;
  553. direction : TO
  554. { $$ = symbol("to"); }
  555. | DOWNTO
  556. { $$ = symbol("downto"); }
  557. ;
  558. final_value : expression
  559. { $$ = $1; }
  560. ;
  561. record_variable_list : record_variable_list comma variable_access
  562. { $$ = item("recordvarlist", $1, $3); }
  563. | variable_access
  564. { $$ = $1; }
  565. ;
  566. boolean_expression : expression
  567. { $$ = $1; }
  568. ;
  569. expression : simple_expression
  570. { $$ = $1; }
  571. | simple_expression relop simple_expression
  572. { $$ = item("relop", $2, $1, $3); }
  573. ;
  574. simple_expression : term
  575. { $$ = $1; }
  576. | simple_expression addop term
  577. { $$ = item("addop", $2, $1, $3); }
  578. ;
  579. term : factor
  580. { $$ = $1; }
  581. | term mulop factor
  582. { $$ = item("term", $2, $1, $3); }
  583. ;
  584. factor : sign factor
  585. { $$ = item("factor", $1, $2); }
  586. | exponentiation
  587. { $$ = $1; }
  588. ;
  589. exponentiation : primary
  590. { $$ = $1; }
  591. | primary STARSTAR exponentiation
  592. { $$ = item("power", $1, $3); }
  593. ;
  594. primary : variable_access
  595. { $$ = $1; }
  596. | unsigned_constant
  597. { $$ = $1; }
  598. | function_designator
  599. { $$ = $1; }
  600. | set_constructor
  601. { $$ = $1; }
  602. | LPAREN expression RPAREN
  603. { $$ = $2; }
  604. | NOT primary
  605. { $$ = item("not", $2); }
  606. ;
  607. unsigned_constant : unsigned_number
  608. { $$ = $1; }
  609. | CHARACTER_STRING
  610. { $$ = string(yytext); }
  611. | NIL { $$ = item("nil"); }
  612. ;
  613. unsigned_number : unsigned_integer
  614. { $$ = $1; }
  615. | unsigned_real { $$ = $1; }
  616. ;
  617. unsigned_integer : DIGSEQ
  618. { $$ = symbol("unsignedinteger",yytext); }
  619. ;
  620. unsigned_real : REALNUMBER
  621. { $$ = symbol("realnumber", yytext); }
  622. ;
  623. /* functions with no params will be handled by plain identifier */
  624. function_designator : identifier params
  625. { $$ = item("function_designator", $1, $2); }
  626. ;
  627. set_constructor : LBRAC member_designator_list RBRAC
  628. { $$ = item("set", $2); }
  629. | LBRAC RBRAC { $$ = item("emptyset"); }
  630. ;
  631. member_designator_list : member_designator_list comma member_designator
  632. { $$ = item("member_append", $1, $3); }
  633. | member_designator
  634. { $$ = $1; }
  635. ;
  636. member_designator : member_designator DOTDOT expression
  637. { $$ = item("range", $1, $3); }
  638. | expression { $$ = $1; }
  639. ;
  640. addop: PLUS { $$ = symbol("plus"); }
  641. | MINUS { $$ = symbol("difference"); }
  642. | OR { $$ = symbol("logor"); }
  643. ;
  644. mulop : STAR { $$ = symbol("times"); }
  645. | SLASH { $$ = symbol("quotient"); }
  646. | DIV { $$ = symbol("quot"); }
  647. | MOD { $$ = symbol("mod"); }
  648. | AND { $$ = symbol("logand"); }
  649. ;
  650. relop : EQUAL { $$ = symbol("equal"); }
  651. | NOTEQUAL { $$ = symbol("neq"); }
  652. | LT { $$ = symbol("lessp"); }
  653. | GT { $$ = symbol("greaterp"); }
  654. | LE { $$ = symbol("leq"); }
  655. | GE { $$ = symbol("geq"); }
  656. | IN { $$ = symbol("in"); }
  657. ;
  658. identifier : IDENTIFIER
  659. { $$ = symbol(yytext); }
  660. ;
  661. semicolon : SEMICOLON
  662. { $$ = NULL; }
  663. ;
  664. comma : COMMA
  665. { $$ = NULL; }
  666. ;
  667. %%
  668. int main(int argc, char *argv[])
  669. { yyparse();
  670. return 0;
  671. }