home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pccts.zip / antlr / parser.dlg < prev    next >
Text File  |  1992-12-08  |  8KB  |  595 lines

  1. <<
  2. /* parser.dlg -- DLG Description of scanner
  3.  *
  4.  * Generated from: antlr.g
  5.  *
  6.  * Terence Parr, Hank Dietz and Will Cohen: 1989-1992
  7.  * Purdue University Electrical Engineering
  8.  * ANTLR Version 1.06
  9.  */
  10. #include <stdio.h>
  11. #include "set.h"
  12. #include <ctype.h>
  13. #include "syn.h"
  14. #include "hash.h"
  15. #include "generic.h"
  16. #define zzcr_attr(attr,tok,t)
  17. #include "antlr.h"
  18. #include "tokens.h"
  19. #include "dlgdef.h"
  20. LOOKAHEAD
  21. void zzerraction()
  22. {
  23.     (*zzerr)("invalid token");
  24.     zzadvance();
  25.     zzskip();
  26. }
  27. >>
  28.  
  29.  
  30. %%START
  31.  
  32. @
  33.     <<
  34.         NLA = Eof;
  35.         /* L o o k  F o r  A n o t h e r  F i l e */
  36.         {
  37.             FILE *new_input;
  38.             new_input = NextFile();
  39.             if ( new_input == NULL ) return;
  40.             fclose( input );
  41.             input = new_input;
  42.             zzrdstream( input );
  43.             /*zzadvance();    /* Get 1st char of this file */
  44.             zzskip();    /* Skip the Eof (@) char i.e continue */
  45.         }
  46.     >>
  47.  
  48. [\t\ ]+
  49.     <<
  50.         NLA = 42;
  51.         zzskip();   
  52.     >>
  53.  
  54. [\n\r]
  55.     <<
  56.         NLA = 43;
  57.         zzline++; zzskip();   
  58.     >>
  59.  
  60. \[
  61.     <<
  62.         NLA = 44;
  63.         zzmode(ACTIONS); zzmore();
  64.         istackreset();
  65.         pushint(']');   
  66.     >>
  67.  
  68. \<\<
  69.     <<
  70.         NLA = 45;
  71.         action_file=CurFile; action_line=zzline;
  72.         zzmode(ACTIONS); zzmore();
  73.         istackreset();
  74.         pushint('>');   
  75.     >>
  76.  
  77. \"
  78.     <<
  79.         NLA = 46;
  80.         zzmode(STRINGS); zzmore();   
  81.     >>
  82.  
  83. /\*
  84.     <<
  85.         NLA = 47;
  86.         zzmode(COMMENTS); zzskip();   
  87.     >>
  88.  
  89. \*/
  90.     <<
  91.         NLA = 48;
  92.         warn("Missing /*; found dangling */"); zzskip();   
  93.     >>
  94.  
  95. \>\>
  96.     <<
  97.         NLA = 49;
  98.         warn("Missing <<; found dangling \\>\\>"); zzskip();   
  99.     >>
  100.  
  101. #header
  102.     <<
  103.         NLA = 50;
  104.     >>
  105.  
  106. !
  107.     <<
  108.         NLA = 52;
  109.     >>
  110.  
  111. \<
  112.     <<
  113.         NLA = 53;
  114.     >>
  115.  
  116. \>
  117.     <<
  118.         NLA = 54;
  119.     >>
  120.  
  121. :
  122.     <<
  123.         NLA = 55;
  124.     >>
  125.  
  126. ;
  127.     <<
  128.         NLA = 56;
  129.     >>
  130.  
  131. #lexaction
  132.     <<
  133.         NLA = 57;
  134.     >>
  135.  
  136. #lexclass
  137.     <<
  138.         NLA = 58;
  139.     >>
  140.  
  141. #errclass
  142.     <<
  143.         NLA = 60;
  144.     >>
  145.  
  146. \{
  147.     <<
  148.         NLA = 61;
  149.     >>
  150.  
  151. \}
  152.     <<
  153.         NLA = 62;
  154.     >>
  155.  
  156. #token
  157.     <<
  158.         NLA = 63;
  159.     >>
  160.  
  161. \|
  162.     <<
  163.         NLA = 64;
  164.     >>
  165.  
  166. ^
  167.     <<
  168.         NLA = 65;
  169.     >>
  170.  
  171. \(
  172.     <<
  173.         NLA = 66;
  174.     >>
  175.  
  176. \)
  177.     <<
  178.         NLA = 67;
  179.     >>
  180.  
  181. \*
  182.     <<
  183.         NLA = 68;
  184.     >>
  185.  
  186. \+
  187.     <<
  188.         NLA = 69;
  189.     >>
  190.  
  191. [a-z] [A-Za-z0-9_]*
  192.     <<
  193.         NLA = NonTerminal;
  194.     >>
  195.  
  196. [A-Z] [A-Za-z0-9_]*
  197.     <<
  198.         NLA = TokenTerm;
  199.     >>
  200.  
  201. #[A-Za-z0-9_]*
  202.     <<
  203.         NLA = 70;
  204.         warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip();   
  205.     >>
  206.  
  207.  
  208. %%STRINGS
  209.  
  210. @
  211.     <<
  212.         NLA = Eof;
  213.     >>
  214.  
  215. \"
  216.     <<
  217.         NLA = QuotedTerm;
  218.         zzmode(START);   
  219.     >>
  220.  
  221. \\\"
  222.     <<
  223.         NLA = 3;
  224.         zzmore();   
  225.     >>
  226.  
  227. \n
  228.     <<
  229.         NLA = 4;
  230.         zzline++;
  231.         warn("eoln found in string (in user action)");
  232.         zzskip();
  233.     >>
  234.  
  235. \\~[\"]
  236.     <<
  237.         NLA = 5;
  238.         zzmore();   
  239.     >>
  240.  
  241. ~[\n\"\\]+
  242.     <<
  243.         NLA = 6;
  244.         zzmore();   
  245.     >>
  246.  
  247.  
  248. %%COMMENTS
  249.  
  250. @
  251.     <<
  252.         NLA = Eof;
  253.     >>
  254.  
  255. \*/
  256.     <<
  257.         NLA = 7;
  258.         zzmode(START); zzskip();   
  259.     >>
  260.  
  261. \*
  262.     <<
  263.         NLA = 8;
  264.         zzskip();   
  265.     >>
  266.  
  267. \n
  268.     <<
  269.         NLA = 9;
  270.         zzline++; zzskip();   
  271.     >>
  272.  
  273. ~[\n\*]+
  274.     <<
  275.         NLA = 10;
  276.         zzskip();   
  277.     >>
  278.  
  279.  
  280. %%ACTIONS
  281.  
  282. @
  283.     <<
  284.         NLA = Eof;
  285.     >>
  286.  
  287. \>\>
  288.     <<
  289.         NLA = Action;
  290.         /* these do not nest */
  291.         zzmode(START);
  292.         NLATEXT[0] = ' ';
  293.         NLATEXT[1] = ' ';
  294.         zzbegexpr[0] = ' ';
  295.         zzbegexpr[1] = ' ';
  296.         if ( zzbufovf ) {
  297.             warn( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
  298.         }
  299.     >>
  300.  
  301. \>\>?
  302.     <<
  303.         NLA = Pred;
  304.         /* these do not nest */
  305.         zzmode(START);
  306.         NLATEXT[0] = ' ';
  307.         NLATEXT[1] = ' ';
  308.         zzbegexpr[0] = ' ';
  309.         zzbegexpr[1] = ' ';
  310.         zzbegexpr[2] = ' ';
  311.         if ( zzbufovf ) {
  312.             warn( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
  313.         }
  314.     >>
  315.  
  316. \]
  317.     <<
  318.         NLA = PassAction;
  319.         if ( topint() == ']' ) {
  320.             popint();
  321.             if ( istackempty() )    /* terminate action */
  322.             {
  323.                 zzmode(START);
  324.                 NLATEXT[0] = ' ';
  325.                 zzbegexpr[0] = ' ';
  326.                 if ( zzbufovf ) {
  327.                     warn( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
  328.                 }
  329.             }
  330.             else {
  331.                 /* terminate zzconstr_attr(..) and zzmk_ast(zzastnew(),..) */
  332.                 zzreplstr(")");
  333.                 zzmore();
  334.             }
  335.         }
  336.         else if ( topint() == '|' ) { /* end of simple [...] */
  337.             popint();
  338.             zzmore();
  339.         }
  340.         else zzmore();
  341.     >>
  342.  
  343. \n
  344.     <<
  345.         NLA = 14;
  346.         zzline++; zzmore();   
  347.     >>
  348.  
  349. \>
  350.     <<
  351.         NLA = 15;
  352.         zzmore();   
  353.     >>
  354.  
  355. $
  356.     <<
  357.         NLA = 16;
  358.         zzmore();   
  359.     >>
  360.  
  361. $$
  362.     <<
  363.         NLA = 17;
  364.         zzreplstr("zzaRet"); zzmore();   
  365.     >>
  366.  
  367. $\[\]
  368.     <<
  369.         NLA = 18;
  370.         zzreplstr("zzempty_attr"); zzmore();   
  371.     >>
  372.  
  373. $\[
  374.     <<
  375.         NLA = 19;
  376.         pushint(']');
  377.         zzreplstr("zzconstr_attr(");
  378.         zzmore();
  379.     >>
  380.  
  381. $[0-9]+
  382.     <<
  383.         NLA = 20;
  384.         {
  385.             static char buf[100];
  386.             if ( strlen(zzbegexpr)>85 )
  387.             fatal(" i attrib ref too big");
  388.             sprintf(buf,"zzaArg(zztasp%d,%s)",
  389.             BlkLevel-1,zzbegexpr+1);
  390.             zzreplstr(buf);
  391.             zzmore();
  392.         }
  393.     >>
  394.  
  395. $[0-9]+.
  396.     <<
  397.         NLA = 21;
  398.         {
  399.             static char buf[100];
  400.             if ( strlen(zzbegexpr)>85 )
  401.             fatal(" i.field attrib ref too big");
  402.             zzbegexpr[strlen(zzbegexpr)-1] = ' ';
  403.             sprintf(buf,"zzaArg(zztasp%d,%s).",
  404.             BlkLevel-1,zzbegexpr+1);
  405.             zzreplstr(buf);
  406.             zzmore();
  407.         }
  408.     >>
  409.  
  410. $[0-9]+.[0-9]+
  411.     <<
  412.         NLA = 22;
  413.         {
  414.             static char buf[100];
  415.             static char i[20], j[20];
  416.             char *p,*q;
  417.             if (strlen(zzbegexpr)>85) fatal(" i.j attrib ref too big");
  418.             for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
  419.                 if ( q == &i[20] ) fatalFL("i of  i.j attrib ref too big", FileStr[CurFile], zzline );
  420.                 *q++ = *p;
  421.             }
  422.             *q = '\0';
  423.             for (p++, q= &j[0]; *p!='\0'; p++) {
  424.                 if ( q == &j[20] ) fatalFL("j of  i.j attrib ref too big", FileStr[CurFile], zzline );
  425.                 *q++ = *p;
  426.             }
  427.             *q = '\0';
  428.             sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
  429.             zzreplstr(buf);
  430.             zzmore();
  431.         }
  432.     >>
  433.  
  434. $[_a-zA-Z][_a-zA-Z0-9]*
  435.     <<
  436.         NLA = 23;
  437.         { static char buf[300];
  438.             zzbegexpr[0] = ' ';
  439.             if ( CurRule != NULL &&
  440.             strcmp(CurRule, &zzbegexpr[1])==0 ) {
  441.                 zzreplstr("zzaRet");
  442.             }
  443.             else if ( CurRetDef != NULL ) {
  444.                 if ( strmember(CurRetDef, &zzbegexpr[1]) ) {
  445.                     if ( HasComma( CurRetDef ) ) {
  446.                         require (strlen(zzbegexpr)<=285,
  447.                         " retval attrib ref too big");
  448.                         sprintf(buf,"_retv.%s",&zzbegexpr[1]);
  449.                         zzreplstr(buf);
  450.                     }
  451.                     else zzreplstr("_retv");
  452.                 }
  453.                 else if ( CurParmDef != NULL ) {
  454.                 if ( !strmember(CurParmDef, &zzbegexpr[1]) )
  455.                 warn(eMsg1("$%s not parameter or return value",&zzbegexpr[1]));
  456.             }
  457.             else warn(eMsg1("$%s not parameter or return value",&zzbegexpr[1]));
  458.         }
  459.     }
  460.     zzmore();
  461.     >>
  462.  
  463. #0
  464.     <<
  465.         NLA = 24;
  466.         zzreplstr("(*_root)"); zzmore();   
  467.     >>
  468.  
  469. #\[\]
  470.     <<
  471.         NLA = 25;
  472.         zzreplstr("zzastnew()"); zzmore();   
  473.     >>
  474.  
  475. #\(\)
  476.     <<
  477.         NLA = 26;
  478.         zzreplstr("NULL"); zzmore();   
  479.     >>
  480.  
  481. #[0-9]+
  482.     <<
  483.         NLA = 27;
  484.         {
  485.             static char buf[100];
  486.             if ( strlen(zzbegexpr)>85 )
  487.             fatal("#i AST ref too big");
  488.             sprintf(buf,"zzastArg(%s)",zzbegexpr+1);
  489.             zzreplstr(buf);
  490.             zzmore();
  491.         }
  492.     >>
  493.  
  494. #\[
  495.     <<
  496.         NLA = 28;
  497.         pushint(']');
  498.         zzreplstr("zzmk_ast(zzastnew(),");
  499.         zzmore();
  500.     >>
  501.  
  502. #\(
  503.     <<
  504.         NLA = 29;
  505.         pushint('}');
  506.         zzreplstr("zztmake(");
  507.         zzmore();
  508.     >>
  509.  
  510. #
  511.     <<
  512.         NLA = 30;
  513.         zzmore();   
  514.     >>
  515.  
  516. \)
  517.     <<
  518.         NLA = 31;
  519.         if ( istackempty() )
  520.         zzmore();
  521.         else if ( topint()==')' ) {
  522.             popint();
  523.         }
  524.         else if ( topint()=='}' ) {
  525.             popint();
  526.             /* terminate zztmake(.., NULL) */
  527.             zzreplstr(", NULL)");
  528.         }
  529.         zzmore();
  530.     >>
  531.  
  532. \[
  533.     <<
  534.         NLA = 32;
  535.         pushint('|');    /* look for '|' to terminate simple [...] */
  536.         zzmore();
  537.     >>
  538.  
  539. \(
  540.     <<
  541.         NLA = 33;
  542.         pushint(')');
  543.         zzmore();
  544.     >>
  545.  
  546. \\\]
  547.     <<
  548.         NLA = 34;
  549.         zzreplstr("]");  zzmore();   
  550.     >>
  551.  
  552. \\\)
  553.     <<
  554.         NLA = 35;
  555.         zzreplstr(")");  zzmore();   
  556.     >>
  557.  
  558. \\>
  559.     <<
  560.         NLA = 36;
  561.         zzreplstr(">");  zzmore();   
  562.     >>
  563.  
  564. \\$
  565.     <<
  566.         NLA = 37;
  567.         zzreplstr("$");  zzmore();   
  568.     >>
  569.  
  570. \\#
  571.     <<
  572.         NLA = 38;
  573.         zzreplstr("#");  zzmore();   
  574.     >>
  575.  
  576. \\\\
  577.     <<
  578.         NLA = 39;
  579.         zzmore();   
  580.     >>
  581.  
  582. \\~[\]\)>$#\\]
  583.     <<
  584.         NLA = 40;
  585.         zzmore();   
  586.     >>
  587.  
  588. ~[\n\)\(\\$#\>\]\[]+
  589.     <<
  590.         NLA = 41;
  591.         zzmore();   
  592.     >>
  593.  
  594. %%
  595.