27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
48
The final grammar can be built by
ANTLR
with k=2.
#token Q "\""
#token SVB "svb"
// "SET var BECOMES"
#token Qbar "[a-z A-Z]*"
#token AddOp "\+"
#token MulOp "\*"
#token WS "\ " <<skip();>>
#token NL "\n" <<skip();>>
repeat : ( command )+ "@";
command : SVB Q ( expr_suffix
| expr Q
| Q <<printf("null command\n");>>
| command Q <<printf("command\n");>>
);
expr_suffix : Qbar Q <<printf("The Qbar expr is (%s)\n",$1.text);>>
{ op expr };
expr : Q expr_suffix;
op : AddOp | MulOp ;
#12.
Processing counted strings in
DLG
Sometimes literals are preceded by a count field.
3abc identifier 4defg
This example works by storing the count which precedes the string in a local variable and then switching to a
#lexclass which accepts characters one at a time while decrementing a counter. When the counter reaches zero (or a
newline in this example) the
DLG
routine switches back to the usual #lexclass.
...
#lexaction <<static int count;>>
#token HOLLERITH "[0-9]*"
<<count=atoi(lextext());
printf("Count is %d\n",count);
mode(COUNT);
>>
#token Eof "@"
#token ID "[a-z]*" <<printf("ID is %s\n",lextext());>>
#token WS "\ " <<skip();>>
#token NL "\n"
#lexclass COUNT
#token STRING "~[]"
<<count--;
if (count == 0) {
mode(START);
printf ("Hollerith string is \"%s\"\n",lextext());
} else if (ch == '\n') {
mode(START);
printf("Hollerith string %s terminated by newline\n",
lextext());
} else {
more();
};
>>
class P {
statement : ( (HOLLERITH STRING | ID )* NL)+ "@";
}
See files in notes/hollerith/*