diff options
| Commit | 4c603cf7417c83d38a517430b3feca6ba039a197 (patch) | |
|---|---|---|
| Author | 2023-10-18 19:46:32 +0300 | |
| Committer | 2023-10-18 19:46:55 +0300 | |
| Files | 5a0c50f639e162fcc2517cdd73b56b7577329283 | |
| uni-projects-4c603cf7417c83d38a517430b3feca6ba039a197.tar uni-projects-4c603cf7417c83d38a517430b3feca6ba039a197.tar.gz uni-projects-4c603cf7417c83d38a517430b3feca6ba039a197.zip | ||
| Parent | cb15f80ab6702bd0fada18a2ec5fba23c76520b6 (diff) | |
[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; } %% |
