108 lines
2.3 KiB
Plaintext
108 lines
2.3 KiB
Plaintext
%{
|
|
/*
|
|
* The scanner definition for COOL.
|
|
*/
|
|
|
|
/*
|
|
* Stuff enclosed in %{ %} in the first section is copied verbatim to the
|
|
* output, so headers and global definitions are placed here to be visible
|
|
* to the code in the file. Don't remove anything that was here initially
|
|
*/
|
|
#include <cool-parse.h>
|
|
#include <stringtab.h>
|
|
#include <utilities.h>
|
|
|
|
/* The compiler assumes these identifiers. */
|
|
#define yylval cool_yylval
|
|
#define yylex cool_yylex
|
|
|
|
/* Max size of string constants */
|
|
#define MAX_STR_CONST 1025
|
|
#define YY_NO_UNPUT /* keep g++ happy */
|
|
|
|
extern FILE *fin; /* we read from this file */
|
|
|
|
/* define YY_INPUT so we read from the FILE fin:
|
|
* This change makes it possible to use this scanner in
|
|
* the Cool compiler.
|
|
*/
|
|
#undef YY_INPUT
|
|
#define YY_INPUT(buf,result,max_size) \
|
|
if ( (result = fread( (char*)buf, sizeof(char), max_size, fin)) < 0) \
|
|
YY_FATAL_ERROR( "read() in flex scanner failed");
|
|
|
|
char string_buf[MAX_STR_CONST]; /* to assemble string constants */
|
|
char *string_buf_ptr;
|
|
|
|
extern int curr_lineno;
|
|
extern int verbose_flag;
|
|
|
|
extern YYSTYPE cool_yylval;
|
|
|
|
/*
|
|
* Add Your own definitions here
|
|
*/
|
|
|
|
%}
|
|
|
|
/*
|
|
* Define names for regular expressions here.
|
|
*/
|
|
|
|
DARROW =>
|
|
DIGIT [0-9]
|
|
DIGITS {DIGIT}+
|
|
/* */
|
|
/* Keywords Definition*/
|
|
/* Except for the constants true and false, keywords are case insensitive */
|
|
K_CLASS (?i:class)
|
|
K_ELSE (?i:else)
|
|
K_FI (?i:fi)
|
|
K_IF (?i:if)
|
|
K_IN (?i:in)
|
|
K_INHERITS (?i:inherits)
|
|
K_ISVOID (?i:isvoid)
|
|
K_LET (?i:let)
|
|
K_LOOP (?i:loop)
|
|
K_POOL (?i:pool)
|
|
K_THEN (?i:then)
|
|
K_WHILE (?i:while)
|
|
K_CASE (?i:case)
|
|
K_ESAC (?i:esac)
|
|
K_NEW (?i:new)
|
|
K_OF (?i:of)
|
|
K_NOT (?i:not)
|
|
/* the first letter of true/false must be lowercase; the trailing may be upper or lower case. */
|
|
K_TRUE t(?i:rue)
|
|
K_FALSE f(?i:alse)
|
|
|
|
|
|
|
|
%%
|
|
|
|
/*
|
|
* Nested comments
|
|
*/
|
|
|
|
|
|
/*
|
|
* The multiple-character operators.
|
|
*/
|
|
{DARROW} { return (DARROW); }
|
|
|
|
/*
|
|
* Keywords are case-insensitive except for the values true and false,
|
|
* which must begin with a lower-case letter.
|
|
*/
|
|
|
|
|
|
/*
|
|
* String constants (C syntax)
|
|
* Escape sequence \c is accepted for all characters c. Except for
|
|
* \n \t \b \f, the result is c.
|
|
*
|
|
*/
|
|
|
|
|
|
%%
|