https://github.com/yuesong-feng/lexical-analyzer
编译原理,C++实现C-语言的词法分析器
https://github.com/yuesong-feng/lexical-analyzer
Last synced: 2 months ago
JSON representation
编译原理,C++实现C-语言的词法分析器
- Host: GitHub
- URL: https://github.com/yuesong-feng/lexical-analyzer
- Owner: yuesong-feng
- Created: 2020-06-11T04:52:29.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-13T08:54:45.000Z (almost 4 years ago)
- Last Synced: 2024-12-24T12:10:33.037Z (4 months ago)
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lexical-analyzer
编译原理,C++实现C-语言的词法分析器分析前的C-语言片段:
```c
/* A program to perform finding the maximum number of the three. */int max(int x, int y, int z)
{
int result;
if (x > y)
{
result = x;
if (z > result)
{
result = z;
}
}
else
{
result = y;
if (z > result)
{
result = z;
}
}
return result;
}void main(void)
{
int a;
int b;
int c;
/* int d; */
a = input();
b = input();
c = input();
output(max(a, b, c));
/*
d = 2 * max(a, b, c);
output(d);
*/
}
```经过词法分析后的代码片段:
```
3: reserved word: int
3: ID, name = max
3: (
3: reserved word: int
3: ID, name = x
3: ,
3: reserved word: int
3: ID, name = y
3: ,
3: reserved word: int
3: ID, name = z
3: )
4: {
5: reserved word: int
5: ID, name = result
5: ;
6: reserved word: if
6: (
6: ID, name = x
6: >
6: ID, name = y
6: )
7: {
8: ID, name = result
8: =
8: ID, name = x
8: ;
9: reserved word: if
9: (
9: ID, name = z
9: >
9: ID, name = result
9: )
10: {
11: ID, name = result
11: =
11: ID, name = z
11: ;
12: }
13: }
14: reserved word: else
15: {
16: ID, name = result
16: =
16: ID, name = y
16: ;
17: reserved word: if
17: (
17: ID, name = z
17: >
17: ID, name = result
17: )
18: {
19: ID, name = result
19: =
19: ID, name = z
19: ;
20: }
21: }
22: reserved word: return
22: ID, name = result
22: ;
23: }
25: reserved word: void
25: ID, name = main
25: (
25: reserved word: void
25: )
26: {
27: reserved word: int
27: ID, name = a
27: ;
28: reserved word: int
28: ID, name = b
28: ;
29: reserved word: int
29: ID, name = c
29: ;
31: ID, name = a
31: =
31: ID, name = input
31: (
31: )
31: ;
32: ID, name = b
32: =
32: ID, name = input
32: (
32: )
32: ;
33: ID, name = c
33: =
33: ID, name = input
33: (
33: )
33: ;
34: ID, name = output
34: (
34: ID, name = max
34: (
34: ID, name = a
34: ,
34: ID, name = b
34: ,
34: ID, name = c
34: )
34: )
34: ;
40: }
EOF
```