Skip to content

a-sharifi/my_compiler_exrecise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Compiler

License: MIT made-with-python Made in MRL

A simple package for compiler practice

In two phases

  1. Lexical analyzer
  2. Syntax analyzer

Lexical analyzer

my simple lexical definite final autonama

Run

git clone https://github.com/amirsharifi74/my_compiler_exrecise.git

python3 lexical_analizer/scanner.py -i <input_file> -o <output_file>

Short_param Long_param description default
-o --output path to input source code file out.txt
-i --input path to outout source code file test.pp

Syntax analyzer

Simple grammer to detect array of our custum language(my language name is amir) Give output of Lexical analizer(tokens) and get the syntax error in CMD the rest of the language grammer is similar to this

Grammer

type -> simple

|  id

| array [simple] of type

symple -> integer

| char

| num dotdot num

params

Short_param Long_param description default
-i --input path to input tokens file out.txt

Run

python3 syntax_analizer/parser.py -i <your_tokens_file_path>


Impilimentation with antlr4

Antlr4 Github page

installation antlr4

getting start with antlr4

Dont forget to install pip install antlr4-python3-runtime

caution: for running my sample code you should generate code for python

cd antlr/
antlr4 -Dlanguage=Python3 Array.g4

Run antlr

First of all write your code in test.pp

cd antlr/
python3 ArrayDetector.py

About

A simple Lexical and syntax analizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •