🔍 Mini C Scanner (2016 Formal Language Assignment, Dongguk Univ.)
Mini C
is complete subset of C Language
- 7 Keywords
- Support
Block Comment
(eg. /* ... */),Line Comment
(eg. //...) - And more..
Mini C Scanner
is Lexical Analyzer to generate tokens of source code to use in parser.
- Input file path of source code by debug arguments args[0]
- then, it will print tokens in console!
- Example code are enveloped in
perfect.mc
/*
A perfect number is an integer which is equal to the sum of all its divisors including 1 but excluding the number itself.
*/
const int max = 500;
void main()
{
int i, j, k;
int rem, sum; //rem : remainder
i = 2;
while (i <= max) {
sum = 0;
k = i / 2;
j = 1;
while (j <= k) {
rem = i % j;
if (rem == 0) sum += j;
++j;
}
if (i == sum) write(i);
++i;
}
}
And more Example Sources, Results
- Handling Lexical Error