6 #define uploc { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }
8 #define CAST_BOOLEAN(strb) strcasecmp(strb, "False") ? TRUE : FALSE
9 /*#define YY_DECL int yylex (YYSTYPE *yylval_param)*/
14 %option bison-locations
17 %option case-insensitive
21 while ((c = input())) {
25 yylloc->first_line = yylloc->last_line = yylineno;
26 yylloc->first_column = 1;
27 yylloc->last_column = 0;
28 } else if (c == EOF) {
30 "Error: unexpected EOF inside comment "
37 "program" { uploc; return T_PROGRAM; }
38 "var" { uploc; return T_VAR; }
39 "integer"|"boolean"|"char" { uploc;
40 yylval->type = type_get_from_lexeme(yytext);
41 return TYPE_IDENTIFIER;
44 "procedure" { uploc; return T_PROCEDURE; }
45 "function" { uploc; return T_FUNCTION; }
46 "begin" { uploc; return T_BEGIN; }
47 "end" { uploc; return T_END; }
49 "printInt" { uploc; return T_PRINT_INT; }
50 "printBool" { uploc; return T_PRINT_BOOL; }
51 "printChar" { uploc; return T_PRINT_CHAR; }
52 "println" { uploc; return T_PRINT_LINE; }
54 "if" { uploc; return T_IF; }
55 "then" { uploc; return T_THEN; }
56 "else" { uploc; return T_ELSE; }
57 "while" { uploc; return T_WHILE; }
58 "for" { uploc; return T_FOR; }
59 "to" { uploc; return T_TO; }
60 "do" { uploc; return T_DO; }
62 ":=" { uploc; return T_ASSIGNMENT; }
63 "(" { uploc; return T_LPAR; }
64 ")" { uploc; return T_RPAR; }
65 "+" { uploc; yylval->lexeme=strdup(yytext);
68 "-" { uploc; yylval->lexeme=strdup(yytext);
71 "*" { uploc; yylval->lexeme=strdup(yytext);
74 "/" { uploc; yylval->lexeme=strdup(yytext);
77 "and" { uploc; yylval->lexeme=strdup(yytext);
80 "or" { uploc; yylval->lexeme=strdup(yytext);
83 "not" { uploc; yylval->lexeme=strdup(yytext);
86 ">" { uploc; yylval->lexeme=strdup(yytext);
89 "<" { uploc; yylval->lexeme=strdup(yytext);
92 "=" { uploc; yylval->lexeme=strdup(yytext);
95 "<>" { uploc; yylval->lexeme=strdup(yytext);
98 ">=" { uploc; yylval->lexeme=strdup(yytext);
99 return T_GREATEREQUAL;
101 "<=" { uploc; yylval->lexeme=strdup(yytext);
102 return T_LESSEREQUAL;
105 ";" { uploc; return T_SEMICOLON; }
106 ":" { uploc; return T_COLON; }
107 "." { uploc; return T_DOT; }
108 "," { uploc; return T_COMMA; }
110 "true"|"false" { uploc;
111 yylval->boolean=CAST_BOOLEAN(yytext);
114 "'"."'" { uploc; yylval->character=yytext[1];
117 [0-9]+ { uploc; yylval->integer=atoi(yytext);
120 [A-Za-z][A-Za-z0-9]* { uploc; yylval->lexeme=strdup(yytext);
124 [ \t]+ /* ignora whitespace */;
125 [\n] { yylloc->first_line = yylloc->last_line = yylineno;
126 yylloc->first_column = 1;
127 yylloc->last_column = 0;
132 "Syntax Error: unexpected "
133 "character '%s' at line %d\n",
134 yytext, yylloc->first_line);