1 | %{
|
---|
2 | // Copyright 2019 The CC Authors. All rights reserved.
|
---|
3 | // Use of this source code is governed by a BSD-style
|
---|
4 | // license that can be found in the LICENSE file.
|
---|
5 | %}
|
---|
6 |
|
---|
7 | %yyc c
|
---|
8 | %yyn c = s.next()
|
---|
9 | %yym s.mark = len(s.charBuf)
|
---|
10 |
|
---|
11 | %{
|
---|
12 | package cc // import "modernc.org/cc/v3"
|
---|
13 |
|
---|
14 | func (s *scanner) scan() (r rune) {
|
---|
15 | %}
|
---|
16 |
|
---|
17 | c-char [^'\n\x80\\]|{escape-sequence}
|
---|
18 | c-char-sequence {c-char}+
|
---|
19 | character-constant '{c-char-sequence}'
|
---|
20 | comment "/*"([^*\x80]|\*+[^*/\x80])*\*+\/
|
---|
21 | comment-not-terminated "/*"([^*\x80]|\*+[^*/\x80])*(\*+)?\n\x80
|
---|
22 | digit [0-9]
|
---|
23 | escape-sequence {simple-sequence}|{octal-escape-sequence}|{hexadecimal-escape-sequence}|{universal-character-name}
|
---|
24 | hex-quad {hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}
|
---|
25 | hexadecimal-digit [0-9a-fA-F]
|
---|
26 | hexadecimal-escape-sequence \\x{hexadecimal-digit}+
|
---|
27 | identifier {identifier-nondigit}({identifier-nondigit}|{digit}|"$")*
|
---|
28 | identifier-nondigit {nondigit}|"$"|{universal-character-name}
|
---|
29 | line-comment "//"[^\n\x80]*
|
---|
30 | nondigit [_a-zA-Z\x81]
|
---|
31 | octal-digit [0-7]
|
---|
32 | octal-escape-sequence \\{octal-digit}{octal-digit}?{octal-digit}?
|
---|
33 | pp-number ({digit}|\.{digit})({digit}|{identifier-nondigit}|[eEpP]{sign}|\.)*
|
---|
34 | s-char [^\x22\n\x80\\]|{escape-sequence}
|
---|
35 | s-char-sequence {s-char}+
|
---|
36 | sign [-+]
|
---|
37 | simple-sequence \\['\x22?\\abefnrtv]
|
---|
38 | string-literal \x22{s-char-sequence}?\x22
|
---|
39 | universal-character-name \\u{hex-quad}|\\U{hex-quad}{hex-quad}
|
---|
40 | white-space [ \t\f\v]
|
---|
41 |
|
---|
42 | %%
|
---|
43 | c := s.initScan()
|
---|
44 |
|
---|
45 | ({white-space}|{comment})*{line-comment} |
|
---|
46 | ({white-space}|{comment})+{line-comment}?
|
---|
47 | return ' '
|
---|
48 |
|
---|
49 | (({white-space}|{comment})*{comment-not-terminated})+
|
---|
50 | return s.unterminatedComment()
|
---|
51 |
|
---|
52 | "!=" return NEQ
|
---|
53 | "##" return PPPASTE
|
---|
54 | "%:" return '#'
|
---|
55 | "%:%:" return PPPASTE
|
---|
56 | "%=" return MODASSIGN
|
---|
57 | "%>" return '}'
|
---|
58 | "&&" return ANDAND
|
---|
59 | "&=" return ANDASSIGN
|
---|
60 | "*=" return MULASSIGN
|
---|
61 | "++" return INC
|
---|
62 | "+=" return ADDASSIGN
|
---|
63 | "--" return DEC
|
---|
64 | "-=" return SUBASSIGN
|
---|
65 | "->" return ARROW
|
---|
66 | "..." return DDD
|
---|
67 | "/=" return DIVASSIGN
|
---|
68 | ":>" return ']'
|
---|
69 | "<%" return '{'
|
---|
70 | "<:" return '['
|
---|
71 | "<<" return LSH
|
---|
72 | "<<=" return LSHASSIGN
|
---|
73 | "<=" return LEQ
|
---|
74 | "==" return EQ
|
---|
75 | ">=" return GEQ
|
---|
76 | ">>" return RSH
|
---|
77 | ">>=" return RSHASSIGN
|
---|
78 | "^=" return XORASSIGN
|
---|
79 | "|=" return ORASSIGN
|
---|
80 | "||" return OROR
|
---|
81 |
|
---|
82 | L{string-literal} return LONGSTRINGLITERAL
|
---|
83 | L{character-constant} return LONGCHARCONST
|
---|
84 | {character-constant} return CHARCONST
|
---|
85 | {identifier} return IDENTIFIER
|
---|
86 | {pp-number} return PPNUMBER
|
---|
87 | {string-literal} return STRINGLITERAL
|
---|
88 |
|
---|
89 | \r?\n return '\n'
|
---|
90 |
|
---|
91 | %%
|
---|
92 | if c, ok := s.abort(); ok {
|
---|
93 | return rune(c)
|
---|
94 | }
|
---|
95 |
|
---|
96 | goto yyAction
|
---|
97 | }
|
---|