From 4c603cf7417c83d38a517430b3feca6ba039a197 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 18 Oct 2023 19:46:32 +0300 Subject: [CI/PA1] Initial testing structure for lexer --- .../coolc-spim/my-code/coursework/pa1/cool.flex | 55 ++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex index acb7d8a..e7e0674 100644 --- a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex +++ b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex @@ -49,32 +49,39 @@ extern YYSTYPE cool_yylval; * Define names for regular expressions here. */ -DARROW => +/* +Info from /usr/class/cs143/cool/include/PA2/cool-parse.h +Token: +CLASS ELSE FI IF IN INHERITS LET LOOP POOL THEN WHILE CASE ESAC OF DARROW NEW ISVOID STR_CONST INT_CONST BOOL_CONST TYPEID OBJECTID ASSIGN NOT LE ERROR +yylval types: + Boolean boolean; + Symbol symbol; + Program program; + Class_ class_; + Classes classes; + Feature feature; + Features features; + Formal formal; + Formals formals; + Case case_; + Cases cases; + Expression expression; + Expressions expressions; + char *error_msg; +*/ + +OCBRACE \{ +CCBRACE \} +ORBRACE \( +CRBRACE \) +COLUMN \: +SEMICOLUMN \; %% - /* - * 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. - * - */ - +"=>" { return (DARROW); } +"class" { return (CLASS); } +[A-Z][a-z]* { cool_yylval.symbol = inttable.add_string(yytext); return (TYPEID); } +\{|\}|\(|\)|:|; { return *yytext; } %% -- cgit v1.3.1-26-gb76a