6 #define uploc { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }
7 /*#define YY_DECL int yylex (YYSTYPE *yylval_param)*/
12 %option bison-locations
15 %option case-insensitive
19 while ((c = input())) {
23 yylloc->first_line = yylloc->last_line = yylineno;
24 yylloc->first_column = 1;
25 yylloc->last_column = 0;
26 } else if (c == EOF) {
28 "[Error] unexpected EOF inside comment "
35 "program" { uploc; return T_PROGRAM; }
36 "var" { uploc; return T_VAR; }
37 "integer"|"boolean"|"char" { uploc;
38 yylval->type = type_get_from_lexeme(yytext);
39 return TYPE_IDENTIFIER;
42 "procedure" { uploc; return T_PROCEDURE; }
43 "function" { uploc; return T_FUNCTION; }
44 "begin" { uploc; return T_BEGIN; }
45 "end" { uploc; return T_END; }
47 "printInt" { uploc; return T_PRINT_INT; }
48 "printBoolean" { uploc; return T_PRINT_BOOL; }
49 "printChar" { uploc; return T_PRINT_CHAR; }
50 "println" { uploc; return T_PRINT_LINE; }
52 "if" { uploc; return T_IF; }
53 "then" { uploc; return T_THEN; }
54 "else" { uploc; return T_ELSE; }
55 "while" { uploc; return T_WHILE; }
56 "for" { uploc; return T_FOR; }
57 "to" { uploc; return T_TO; }
58 "do" { uploc; return T_DO; }
60 ":=" { uploc; return T_ASSIGNMENT; }
61 "(" { uploc; return T_LPAR; }
62 ")" { uploc; return T_RPAR; }
63 "+" { uploc; yylval->lexeme=strdup(yytext);
66 "-" { uploc; yylval->lexeme=strdup(yytext);
69 "*" { uploc; yylval->lexeme=strdup(yytext);
72 "/" { uploc; yylval->lexeme=strdup(yytext);
75 "and" { uploc; yylval->lexeme=strdup(yytext);
78 "or" { uploc; yylval->lexeme=strdup(yytext);
81 "not" { uploc; yylval->lexeme=strdup(yytext);
84 ">" { uploc; yylval->lexeme=strdup(yytext);
87 "<" { uploc; yylval->lexeme=strdup(yytext);
90 "=" { uploc; yylval->lexeme=strdup(yytext);
93 "<>" { uploc; yylval->lexeme=strdup(yytext);
96 ">=" { uploc; yylval->lexeme=strdup(yytext);
97 return T_GREATEREQUAL;
99 "<=" { uploc; yylval->lexeme=strdup(yytext);
100 return T_LESSEREQUAL;
103 ";" { uploc; return T_SEMICOLON; }
104 ":" { uploc; return T_COLON; }
105 "." { uploc; return T_DOT; }
106 "," { uploc; return T_COMMA; }
108 "true"|"false" { uploc; yylval->boolean=strcmp(yytext, "False");
111 "'"."'" { uploc; yylval->character=yytext[1];
114 [0-9]+ { uploc; yylval->integer=atoi(yytext);
117 [A-Za-z][A-Za-z0-9]* { uploc; yylval->lexeme=strdup(yytext);
121 [ \t]+ /* ignora whitespace */;
122 [\n] { yylloc->first_line = yylloc->last_line = yylineno;
123 yylloc->first_column = 1;
124 yylloc->last_column = 0;
129 "%d: syntax error: unexpected character '%s'\n",
130 yylloc->first_line, yytext);