Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SCANNER oberon_scan
- EXPORT {
- /* code to be put intp Scanner.h */
- # include "Position.h"
- /* Token Attributes.
- * For each token with user defined attributes, we need a typedef for the
- * token attributes.
- * LPP extracts the token-attribute declaration from the parser specification.
- * They are inserted here.
- */
- INSERT tScanAttribute
- }
- GLOBAL {
- /* code to be put into Scanner.c */
- # include <stdlib.h>
- # include "Errors.h"
- /* Insert the routine computing "error-values" of attributes, in case the
- * parser decides during error repair to insert a token.
- */
- INSERT ErrorAttribute
- }
- LOCAL {
- /* user-defined local variables of the generated GetToken routine */
- # define MAX_STRING_LEN 2048
- char string[MAX_STRING_LEN];
- int len;
- }
- DEFAULT {
- /* What happens if no scanner rule matches the input */
- MessageI ("Illegal character",
- xxError, oberon_scan_Attribute.Position,
- xxCharacter, oberon_scan_TokenPtr);
- }
- EOF {
- /* What should be done if the end-of-input-file has been reached? */
- /* E.g.: check hat strings and comments are closed. */
- switch (yyStartState) {
- case STD:
- /* ok */
- break;
- default:
- Message ("OOPS: that should not happen!!",
- xxFatal, oberon_scan_Attribute.Position);
- break;
- }
- /* implicit: return the EofToken */
- }
- DEFINE /* some abbreviations */
- digit = {0-9} .
- hexdigit = {0-9A-F} .
- character = {A-Za-z} .
- strchrs = - {"\\\n\r\f} .
- A = {Aa}.
- B = {Bb}.
- C = {Cc}.
- D = {Dd}.
- E = {Ee}.
- F = {Ff}.
- G = {Gg}.
- H = {Hh}.
- I = {Ii}.
- J = {Jj}.
- K = {Kk}.
- L = {Ll}.
- M = {Mm}.
- N = {Nn}.
- O = {Oo}.
- P = {Pp}.
- Q = {Qq}.
- R = {Rr}.
- S = {Ss}.
- T = {Tt}.
- U = {Uu}.
- V = {Vv}.
- W = {Ww}.
- X = {Xx}.
- Y = {Yy}.
- Z = {Zz}.
- START OBSTR
- RULES
- /*####################################*/
- INSERT RULES #STD#
- /*####################################*/
- /**********************************************************************/
- #STD# character (character | digit)* :
- {
- oberon_scan_Attribute.tok_identifier.Value = malloc(oberon_scan_TokenLength + 1);
- oberon_scan_GetWord (oberon_scan_Attribute.tok_identifier.Value);
- return tok_identifier;
- }
- /**********************************************************************/
- /* integer */
- #STD# digit* | digit hexdigit* "H":
- {
- oberon_scan_GetWord (string);
- oberon_scan_Attribute.int_const.Value = atol (string);
- return int_const;
- }
- /**********************************************************************/
- /* real digit */
- #STD# digit digit* "." digit* (("E"|"D") ("+"|"-")? digit+ )?:
- {
- oberon_scan_GetWord (string);
- oberon_scan_Attribute.real_const.Value = atof (string);
- return real_const;
- }
- /**********************************************************************/
- /* char constant */
- #STD# digit hexdigit* "X" :
- {
- oberon_scan_GetWord (string);
- oberon_scan_Attribute.char_const.Value = (char) strtol(string, (void*)0, 0);
- return char_const;
- }
- #STD# \" character \" :
- {
- oberon_scan_GetWord (string);
- oberon_scan_Attribute.char_const.Value = string[1]; /* Not sure ... */
- return char_const;
- }
- /**********************************************************************/
- /* string */
- #STD# \" :
- {
- yyStart (OBSTR);
- len = 0;
- }
- #OBSTR# strchrs* :
- {
- len += oberon_scan_GetWord (&string[len]);
- }
- #OBSTR# \" :
- {
- yyStart(STD);
- string[len] = '\0';
- oberon_scan_Attribute.string_const.Value = malloc (len);
- strcpy (oberon_scan_Attribute.string_const.Value, string);
- return string_const;
- }
- #OBSTR# \\ \" :
- {
- string[len++] = '"';
- }
- #OBSTR# \\ n :
- {
- string[len++] = '\n';
- }
- #OBSTR# \\ :
- {
- string[len++] = '\\';
- }
- #OBSTR# \n :
- {
- yyStart(STD);
- yyEol (0);
- oberon_scan_Attribute.string_const.Value = "";
- return string_const;
- }
- /**********************************************************************/
- /**********************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement