0% found this document useful (0 votes)
28 views15 pages

Final Report Toa

The document describes the syntax and grammar rules of a programming language. It defines syntax rules for variables, conditions, functions, arrays, loops, and nested loops using BNF notation. The syntax rules cover basic programming constructs like data types, expressions, statements, and control structures.

Uploaded by

vp97btsm9j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views15 pages

Final Report Toa

The document describes the syntax and grammar rules of a programming language. It defines syntax rules for variables, conditions, functions, arrays, loops, and nested loops using BNF notation. The syntax rules cover basic programming constructs like data types, expressions, statements, and control structures.

Uploaded by

vp97btsm9j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Final Project

F2021266101 ArhamAhmad
F2021266134 NawwalAftabWaseer
F2021266121 M.AhmadAfzal
F2021266113 Talha Tajammal
Variables:
Variable_Declaration  Data_Type Identifier
=”Expression” ;
Data_Type  int | double | char | boolean | String
Identifier  letter Identifier_Tail
Identifier_Tail  Letter_Or_Digit Identifier_Tail |
ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_Or_Digit  Letter | Digit
Digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Expression  Literal | Identifier | Expression
Binary_Operator Expression
Literal Integer_Literal | Double_Literal |
Char_Literal | Boolean_Literal | String_Literal
Integer_Literal Digit Integer_Literal_Tail
Integer_Literal_Tail Digit Integer_Literal_Tail |
ε
Double_Literal Digit Double_Literal_Tail
Double_Literal_Tail  Digit Double_Literal_Tail

Char_Literal
 Any_Character_Except_Single_Quote
Boolean_Literal  true | false
String_Literal  "Any_Sequence_Of_Characters"
Binary_Operator  + | - | * | / | % | == | != | < | > |
<= | >= | && | ||

Conditions:

Program  Conditional_Statement | Statement

Conditional_Statement  If_Statement |
If_Else_Statement | Switch_Statement

If_Statement If “Condition” Statement

If_Else_Statement  If Condition Statement else


Statement

Switch_Statement  Switch “Expression”


“Switch_Cases”

Switch_Cases  Switch_Case | Switch_Cases


Switch_Case

Switch_Case  case Literal : Statement break


Condition  Expression Relational_Operator
Expression | Expression

Relational_Operator  == | != | < | > | <= | >=

Expression  Term Expression_Tail

Expression_Tail Additive_Operator Term


Expression_Tail | ε

Additive_Operator  + | -

Term  Factor Term_Tail

Term_Tail  Multiplicative_Operator Factor


Term_Tail | ε

Multiplicative_Operator  * | / | %

Ffactor  Literal | Identifier | ”Expression” |


Unary_Operator Factor

Literal  Integer_Literal | <Double_Literal |


Char_Literal | Boolean_Literal | String_Literal
Integer_Literal  Digit+
Double_Literal  Digit+ . Digit+
Char_Literal
Any_Character_Except_Single_Quote
Boolean_Literal  true | false
String_Literal Any_Sequence_Of_Characters

Identifier  letter Identifier_Tail


Identifier_Tail  Letter_Or_Digit Identifier_Tail |
ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_Or_Digit Letter | Digit
Digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Unary_Operator - | !

Statement  Expression_Statement |
Declaration_Statement | If_Statement |
If_e]Else_Statement | Switch_Statement |
While_Statement | Do_While_Statement |
For_Statement

Expression_Statement  Expression ;

Declaration_Statement  Variable_Declaration ;

While_Statement  While “Condition” Statement


Do_While_Statement  do Statement while
”Condition” ;

For_Statement  For ‘For_Init ; <For_Condition ;


“For_Update” Statement

For_Init  Expression_Statement |
Variable_declaration | ε
For_Condition  Expression | ε
For_Update  Expression_Statement | ε

Nested Condition:
Program  Conditional_Statement | Statement
Conditional_Statement  If_Statement |
If_Else_Statement
If_Statement  If ( “condition” )
Nested_Condition
If_Else_Statement  If ( “condition” )
Nested_Condition else Nested_Condition
Nested_Condition  Conditional_Statement |
Statement
Condition  Expression Relational_Operator
Expression | Expression
Relational_Operator  == | != | | | = | =
Expression  Term Expression_Tail
Expression_Tail Additive_Operator Term
Expression_Tail | ε
Additive_Operator + | -
Term  Factor Term_Tail
Term_Tail Multiplicative_Operator Factor
Term_Tail | ε
Multiplicative_Operator  * | / | %
Factor  Literal | Identifier | “Expression”|
Unary_Operator Factor
Literal  Integer_Literal | Double_Literal |
Char_Literal | Boolean_Literal | String_Literal
Integer_Literal Digit+
Double_Literal  Digit+ . Digit+
Char_Literal
'Any_character_except_single_quote'
Boolean_Literal  true | false
String_Literal  "any_sequence_of_characters"
Identifier  letter identifier_tail
Identifier_Tail  letter_or_digit Identifier_Tail | ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_or_Digit  Letter | Digit
Digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Unary_operator  - | !
Function:
Program  Function_Declaration |
Class_Declaration
Function_Declaration  Return_Type
Function_Name “Parameter_List”
Block_Statement
Return_Type Data_Type | void
Parameter_list> Parameter | Parameter_List ,
Parameter
Parameter Data_Type Variable_Declaration
Block_Statement  “Statement_List
Statement_List  Sstatement | Statement_List
Statement
Statement  Expression_Statement |
Declaration_Statement | If_Statement |
While_Statement | Do_While_Statement |
For_Statement | Return_Statement
Expression_Statement  Expression;
Declaration_Statement  Variable_Declaration ;
If_Statement  if ”Expression” Statement else
“Statement”
While_Statement  while “expression” Statement
Do_While_Statement  do Statement While
“Expression” ;
For_Statement  for “For_Init ; For_Condition” ;
“For_Update” Statement
For_Init  Expression_Statement |
Variable_Declaration | ε
For_Condition  Expression | ε
For_Update  Expression_Statement | ε
<return_statement> ::= return <expression> ;
Expression  Literal | Identifier | Expression
Binary_Operator Expression | Unary_Operator
Expression | “Expression”
Literal  Integer_Literal | Double_Literal |
Char_Literal | Boolean_Literal | String_Literal
Integer_Literal  Digit+
Double_Literal Digit . Digit+
Char_Literal
Any_Character_Except_Single_Quote
Boolean_Literal  true | false
String_Literal  Any_Sequence_Of_Characters
Data_Type  int | double | char | boolean | String |
Custom_Class_Type
Identifier  Letter Identifier_Tail
Identifier_Tail  Letter_Or_Digit Identifier_Tail |
ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_Or_Digit  Letter | Digit
Digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Binary_Operator  + | - | * | / | % | == | != | < | > |


<= | >= | && | ||
Unary_Operator ? - | !

Array:
Program  Array_Declaration | Statement
Array_Declaration Data_Type Identifier
Expression ;
Statement  Expression_Statement |
Declaration_Statement
Expression_Statement  Expression ;
Declaration_Statement  Variable_Declaration
;
Expression  Identifier | Array_access |
Array_creation
Array_access  Identifier “expression”
Array_Creation  new Data_Type expression
Data_Type  int | double | char | boolean |
String
Identifier  letter Identifier_Tail
Identifier_Tail  Letter_or_Digit
Identifier_Tail | ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_or_Digit  Letter | Digit
Digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
LOOP:

<loop> → <for_loop> | <while_loop> |


<do_while_loop>

<for_loop> → for ( <initialization>; <condition>;


<update> ) <statement>

<while_loop> → while ( <condition> )


<statement>

<do_while_loop> → do <statement> while


( <condition> ) ;

<initialization> → <expression_statement> |
<variable_declaration> | ε

<condition> → <expression> | ε

<update> → <expression_statement> | ε
<statement> → <array_delecration>|
<Expression> | <block_statement> | <loop>|
<Condition_Statement>|<Variable_Declaration>

<expression_statement> → <expression> ;

Variable Declaration

<variable_declaration> → <data_type>
<identifier> [= <expression>] ;

Statement & Block

<block_statement> → { <statement_list> }

<statement_list> → <statement> |
<statement_list> <statement>

<expression> ::= <literal> | <identifier> |


<expression> <binary_operator> <expression> |
<unary_operator> <expression> | ( <expression> )
<literal> ::= <integer_literal> | <double_literal> |
<char_literal> | <boolean_literal> | <string_literal>
<data_type> ::= int | double | char | boolean |
String | <custom_class_type>

<integer_literal> ::= <digit>+


<double_literal> ::= <digit>+ . <digit>+
<char_literal> ::=
'<any_character_except_single_quote>'
<boolean_literal> ::= true | false
<string_literal> ::=
"<any_sequence_of_characters>"

<binary_operator> ::= + | - | * | / | % | == | != | < | >


| <= | >= | && | ||
<unary_operator> ::= - | !

<identifier> ::= <letter> <identifier_tail>


<identifier_tail> ::= <letter_or_digit>
<identifier_tail> | ε
<letter> ::= a | b | c | ... | z | A | B | C | ... | Z | _
<letter_or_digit> ::= <letter> | <digit>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Nested Loop:
Program  Loop | Statement
Loop  For_Loop | While_Loop |
Do_While_Loop
For_Loop  for (“ For_Init ; For_Condition ;
For_Update”) Nested_Loop
While_Loop  while (”expression” )
Nested_loop
Do_while_Loop  do Nested_Loop while
( expression ) ;
Nested_Loop  Loop | Statement
For_Init  Expression_Statement |
Variable_Declaration | ε
For_Condition  Expression | ε
For_Update  Expression_Statement | ε
Expression_Statement  Expression ;
Variable_Declaration  Data_Type Identifier [=
expression] ;
Statement  Expression_Statement |
Declaration_Statement | If_Statement |
While_Statement | Do_While_Statement |
For_Statement
If_Statement  If ( expression ) Nested_Loop
[else Nested_Loop]
While_Statement  While ( expression )
nested_loop
Do_While_Statement  do Nested_Loop while
( expression ) ;
For_Statement  for ( For_Init ; For_Condition ;
For_Update ) nested_loop
Expression  Literal | Identifier | Expression
Binary_operator Expression | Unary_Operator
Expression | ( Expression )
Literal  Integer_Literal | Double_Literal |
Char_Iiteral | Boolean_Literal | String_Literal
Integer_Literal  digit+
Double_Literal  digit+ . digit+
Char_Literal 
'any_character_except_single_quote'
Boolean_Literal  true | false
String_Literal  "any_sequence_of_characters"
Data_Type  int | double | char | boolean | String
Identifier  Letter Identifier_Tail
Identifier_Tail  Letter_or_Digit Identifier_Tail |
ε
Letter  a | b | c | ... | z | A | B | C | ... | Z | _
Letter_or_Digit  Letter | Digit
Digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Binary_Operator  + | - | * | / | % | == | != | | | = |
= | && | ||
Unary_Operator  - | !

You might also like