diff options
[CI/PA1] Initial testing structure for lexer
1 files changed, 31 insertions, 24 deletions
| -rw-r--r-- | Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex | 55 |
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; +*/ -%% - - /* - * Nested comments - */ - - - /* - * The multiple-character operators. - */ -{DARROW} { return (DARROW); } +OCBRACE \{ +CCBRACE \} +ORBRACE \( +CRBRACE \) +COLUMN \: +SEMICOLUMN \; - /* - * 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; } %% |
