Generating Software from Specifications WS 2013/14 - File TryScan.fw
@=~ ~p maximum_input_line_length = infinity The concrete grammar specifies a sequence of Elements separated by commas. The elements are named terminals. ~O~<TryScan.con~>~{ Specification: Sequence. Sequence: Sequence ',' Element / Element. Element: Ident / Number. ~} Two tokens are specified here. Replace them by your favorite token notations and test the generated scanner and parser: ~O~<TryScan.gla~>~{ Ident: $[a-zA-Z][a-zA-Z0-9]* [myToken] Number: $[0-9]+ [myToken] ~} The following three macros implement a little C module. It defines a function to be called as a token encoding function. In the present state it only prints some information on every accepted token: ~O~<TryScan.HEAD.phi~>~{ #include "TryScan.h" ~} ~O~<TryScan.h~>~{ extern void myToken (char *start, int length, int *class, int *intrinsic); ~} ~O~<TryScan.c~>~{ #include <stdio.h> #include "TryScan.h" int count = 0; void myToken (char *start, int length, int *class, int *intrinsic) { count++; printf ("token %d first char >%c<\n", count, *start); } ~}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 23.10.2013