Advertisement
bokunda

lex.l

May 24th, 2024
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "y.tab.h"
  6. int yyline;
  7. %}
  8.  
  9. %%
  10.  
  11. [A-Za-z"_"]{1,} {
  12.     strcpy(yylval.ctekst, yytext);
  13.     return TEKST;
  14. }
  15.  
  16. "0."[0-9]{1} {
  17.     yylval.ckriterijum = atof(yytext);
  18.     return KRITERIJUM;
  19. }
  20.  
  21. "*"|"+"|"-"|"?" {
  22.    
  23.     if (yytext[0] == '*') {
  24.         yylval.cocena = 3;
  25.     }
  26.     else if (yytext[0] == '+') {
  27.         yylval.cocena = 2;
  28.     }
  29.     else if (yytext[0] == '-') {
  30.         yylval.cocena = 1;
  31.     }
  32.     else {
  33.         yylval.cocena = 0;
  34.     }
  35.    
  36.     return OCENA;
  37. }
  38.  
  39. "###" {
  40.     return TARABE;
  41. }
  42.  
  43. "pr:" {
  44.     return PR;
  45. }
  46.  
  47. " " {
  48.  
  49. }
  50.  
  51. \n {
  52.     yyline++;
  53. }
  54.  
  55. . {
  56.     return yytext[0];
  57. }
  58.  
  59. %%
Tags: lex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement