MinJunKweon / Mini-C-Scanner

:mag: Mini C Scanner (2016 Formal Language Assignment, Dongguk Univ.)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mini-C-Scanner

🔍 Mini C Scanner (2016 Formal Language Assignment, Dongguk Univ.)

What is it?

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.

How To Use?

  • Input file path of source code by debug arguments args[0]
  • then, it will print tokens in console!

Example result

Example

  • 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;
  	}
  }

Struct

Class Diagram

Class Diagram

State Diagram in Scanner

State Diagram

TODO

  • Handling Lexical Error

About

:mag: Mini C Scanner (2016 Formal Language Assignment, Dongguk Univ.)

License:MIT License


Languages

Language:Java 100.0%