-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoberon2-lex.y
72 lines (63 loc) · 2.12 KB
/
oberon2-lex.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
%local {
#include <stdio.h>
static char id[100];
static int idlen;
static int lineno;
#define yyslex() fgetc (stdin)
#include "oberon2-kw.c"
}
%expect 30
%scanner
%%
program :
| program lexema
lexema : {idlen = 0;} ident {return KR_find_keyword (id, idlen);}
| number_character {if ($1) return CHARACTER; else return NUMBER;}
| string {return STRING;}
| '+' {return '+';}
| ":=" {return ASSIGN;}
| '-' {return '-';}
| '@' {return '@';}
| '*' {return '*';}
| '=' {return '=';}
| '/' {return '/';}
| '#' {return '#';}
| '~' {return '~';}
| '<' {return '<';}
| '&' {return '&';}
| '>' {return '>';}
| '.' {return '.';}
| "<=" {return LE;}
| ',' {return ',';}
| ">=" {return GE;}
| ';' {return ';';}
| ".." {return RANGE;}
| '|' {return '|';}
| ':' {return ':';}
| '(' {return '(';}
| ')' {return ')';}
| '[' {return '[';}
| ']' {return ']';}
| '{' {return '{';}
| '}' {return '}';}
| comment
| space
| error
space : ' ' | '\t' | '\n' {lineno++;}
ident : letter {id[idlen++]=yysprev_char;}
(letter {id[idlen++]=yysprev_char;}
| digit {id[idlen++]=yysprev_char;})*
number_character : {$$ = 0;} digit (hexDigit)*
(['H'|'X' {$$ = 1;}] | '.' (digit)* [ScaleFactor])
ScaleFactor : ('E' | 'D') ['+' | '-'] digit (digit)*
hexDigit : digit | 'A'-'F'
digit : '0'-'9'
letter : 'A'-'Z'|'a'-'z'
string : '"' ('\0'->'"' | '"'<-'\377')* '"'
| '\'' ('\0'->'\'' | '\''<-'\377')* '\''
comment : "(*" ('\0'-'\377' | comment)* "*)"
%%
int yyserror (char *s)
{
fprintf (stderr, "illegal code %d on line %d\n", yyschar, lineno);
}