parse.y merged.
[toypasc.git] / scanner.l
blob7b4e4bd28e33b8853e6418714eb3d4fb7a07ac83
1 %{
2 #include <stdio.h>
3 #include "base.h"
4 #include "parser.h"
6 #define uploc   { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }
7 /*#define YY_DECL int yylex (YYSTYPE *yylval_param)*/
8 %}
10 %option yylineno
11 %option bison-bridge
12 %option bison-locations
13 %option noyywrap
14 %option nounput
17 "Var"                       { uploc; return T_VAR; }
18 "Integer"|"Boolean"|"Char"  { uploc;
19                               yylval->type = type_get_from_lexeme(yytext);
20                               return TYPE_IDENTIFIER;
21                             }
23 "Procedure"                 { uploc; return T_PROCEDURE; }
24 "Function"                  { uploc; return T_FUNCTION; }
25 "Begin"                     { uploc; return T_BEGIN; }
26 "End"                       { uploc; return T_END; }
28 "printInt"                  { uploc; return T_PRINT_INT; }
29 "printBoolean"              { uploc; return T_PRINT_BOOL; }
30 "printChar"                 { uploc; return T_PRINT_CHAR; }
31 "println"                   { uploc; return T_PRINT_LINE; }
33 "if"                        { uploc; return T_IF; }
34 "else"                      { uploc; return T_ELSE; }
35 "while"                     { uploc; return T_WHILE; }
36 "for"                       { uploc; return T_FOR; }
37 "to"                        { uploc; return T_TO; }
38 "do"                        { uploc; return T_DO; }
40 ":="                        { uploc; return T_ASSIGNMENT; }
41 "("                         { uploc; return T_LPAR; }
42 ")"                         { uploc; return T_RPAR; }
43 "+"                         { uploc; return T_ADD; }
44 "-"                         { uploc; return T_SUB; }
45 "*"                         { uploc; return T_MULT; }
46 "/"                         { uploc; return T_DIV; }
47 "and"                       { uploc; return T_AND; }
48 "or"                        { uploc; return T_OR; }
49 "not"                       { uploc; return T_NOT; }
51 ">"                         { uploc; return T_MAJOR; }
52 "<"                         { uploc; return T_MINOR; }
53 "="                         { uploc; return T_EQUAL; }
54 "<>"                        { uploc; return T_NOTEQUAL; }
55 ">="                        { uploc; return T_MAJOREQUAL; }
56 "<="                        { uploc; return T_MINOREQUAL; }
58 ";"                         { uploc; return T_SEMICOLON; }
59 ":"                         { uploc; return T_COLON; }
60 "."                         { uploc; return T_DOT; }
61 ","                         { uploc; return T_COMMA; }
63 "True"|"False"              { uploc;
64                               yylval->boolean=strcmp(yytext, "False");
65                               return BOOL_LITERAL;
66                             }
67 [0-9]+                      { uploc;
68                               yylval->integer=atoi(yytext);
69                               return INT_LITERAL;
70                             }
71 [A-Za-z][A-Za-z0-9]*        { uploc;
72                               yylval->lexeme=strdup(yytext);
73                               return IDENTIFIER;
74                             }
76 [ \t]+                      /* ignora whitespace */;
77 [\n]                        { yylloc->first_line = yylloc->last_line = yylineno;
78                               yylloc->first_column = 1;
79                               yylloc->last_column = 0;
80                             }
82 .                           { uploc;
83                               fprintf (stderr,
84                                        "%d: syntax error: unexpected character ´%s´\n",
85                                        yylloc->first_line, yytext);
86                             }