implementation the simple compiler using php
PROJECT is a case sensitive objects oriented Language. A program consists of class declaration which includes variables declaration and sequence of Methods declarations. Each method consists in turn of variable declarations and statements. The types in compiler are very restricted as in table 1.
1- Project contain a full functional editor (comment, uncomment, put red line under wrong words, auto complete, navigation to function or class, line NO).
2- Project contain two buttons , one button called “Scan” to run scanner and other called “Parse” to run parser –parser must take output of scanner to do it’s task.
3- project contain a button named “Browse” that allows us to choose a file from a disk that allows us to parse or scan this file Without Showing what is inside the file and shows the output.
4- Comments in compiler includes multiple line comment is written between </ and />and single line comment is written as *** .Your parser must ignore all comments and white spaces.
5- Tokens and return values: You must build a dictionary to save Keywords that are defined in table 1 .
6- in complier system Language Delimiters (words and lines): The words are delimited by Space and tab. The line delimiter is semicolon (;) and newline.
7- Parser grammar rules:
- Program →Start-Symbols ClassDeclaration End-Symbols.
- Start-Symbols →@| ^
- End-Symbols→$ |#
- ClassDeclaration→ Type ID{ Class_Implementation} | Type ID Infer { Class_Implementation}
- Class_Implementation→ Variable_Decl Class_Implementation| Method_Decl Class_Implementation | Comment Class_Implementation | require_command Class_Implementation| Func _Call Class_Implementation |em
- Method_Decl→ Func Decl ;| Func Decl { Variable_Decl Statements }
- Func Decl →Type ID (ParameterList)
- Type → Ipok |Sipok |Craf |Sequence |Ipokf |Sipokf |Valueless |Rational
- ParameterList →em| None | Non-Empty List
- Non-Empty List→ Type ID | Non-Empty List , Type ID
- Variable_Decl→ em | Type ID_List ; Variable_Decl | Type ID_List [ID] ; Variable_Decl
- ID_List →ID | ID_List , ID
- Statements→em | Statement Statements
- Statement→Assignment | If _Statement | However _Statement | when_Statement | Respondwith _ Statement | Endthis _Statement|Scanvalur (ID ); | Print (Expression); |
- Assignment→ Variable_Decl = Expression;
- Func _Call → ID (Argument_List) ;
- Argument_List →em | NonEmpty_Argument_List
- NonEmpty_Argument_List →Expression | NonEmpty_Argument_List , Expression
- Block Statements→{ statements }
- If _Statement→ if (Condition _Expression) Block Statements | if (Condition _Expression) Block Statements else Block Statements
- Condition _Expression→ Condition |Condition Condition _Op Condition
- Condition _Op → && | ||
- Condition→ Expression Comparison _Op Expression
- Comparison _Op → == | != | > | >= | < | <=
- However _Statement → However (Condition _Expression) Block Statements
- when _Statement → when ( expression ; expression ; expression )Block Statements
- Respondwith _Statement→ Respondwith Expression ; | return ID ;
- Endthis _Statement→ Endthis;
- Expression → Term |Expression Add_Op Term
- Add_Op → + | -
- Term→Factor| Term Mul_Op Factor
- Mul_Op→* | /
- Factor→ ID| Number
- Comment →</ STR /> | ***STR
- Require_command →Require(F_name.txt);
- F_name →STR
Keywords | Meaning | Return Token |
---|---|---|
Type | is the blueprint from which individual objects are created. | Class |
Infer | Inheritance in oop | Inheritance |
If—Else | conditional statements | Condition |
Ipok | Integer type | Integer |
Sipok | Signed Integer type | SInteger |
Craf | Character Type | Character |
Sequence | Group of characters | String |
Ipokf | Float type | Float |
Sipokf | Signed Float type | SFloat |
Valueless | Void Type | Void |
Rational | Boolean type | Boolean |
Endthis | Break immediately from a loop | Break |
However/When | repeatedly execute code as long as condition is true | Loop |
Respondwith | Return a value from a function | Return |
Srap | grouped list of variables placed under one name | Struct |
Scan–Conditionof | To switch between many cases | Switch |
@| ^ | Program Starting Symbols | Start Symbol |
$|# | Program Ending Symbols | End Symbol |
(+, -, *, /,) | Used to add, subtract, multiply and divide respectively | Arithmetic Operation |
(&&, ||, ~) | Used to and, or and not repectively | Logic operators |
(==, <, >, !=, <=, >=) | Used to describe relations | relational operators |
= | Used to describe Assignment operation | Assignment operator |
-> | Used in Seop to access Seop elements | Access Operator |
{,},[,] | Used to group class statements, statements or array index respectively | Braces |
[0-9] and any combination | Used to describe numbers | Constant |
“,’ | Used in defining strings and single character reprctively | Quotation Mark |
Require | Used to include one file in another | Inclusion |
You can communicate by following e-mails If you have more questions about the project or to get the all src code :