0% found this document useful (0 votes)
8 views2 pages

CFG

Compiler

Uploaded by

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

CFG

Compiler

Uploaded by

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

Program -> StatementList

StatementList -> Statement StatementList | ε

Statement -> VariableDeclaration


| FunctionDefinition
| IfStatement
| ForLoop
| FunctionCall
| ε

# Variable Declarations

VariableDeclaration -> VarKeyword Identifier "=" Expression ";"

VarKeyword -> "var" | "num" | "str" | "bool"


Identifier -> [a-zA-Z_][a-zA-Z0-9_]*

# Expressions (Handle values and operations)

Expression -> BoolExpr


| NumExpr
| StrExpr

BoolExpr -> "true" | "false"


NumExpr -> Number (Operator Number)*
StrExpr -> '"' StringContent '"'

Operator -> "+" | "-" | "*" | "/"


Number -> [0-9]+
StringContent -> [a-zA-Z0-9\-\+/*=]*

# Function Definitions

FunctionDefinition -> "func" Identifier "{" FunctionBody "}"


FunctionBody -> StatementList

# Conditionals

IfStatement -> "if" "(" Condition ")" "{" Action "}"


ElifPart ElsePart

ElifPart -> "elif" "(" Condition ")" "{" Action "}" | ε


ElsePart -> "else" "{" Action "}" | ε
Condition -> Expression ComparisonOp Expression
ComparisonOp -> "==" | "!=" | ">=" | "<=" | ">" | "<"

# For Loops

ForLoop -> "for" "(" VariableDeclaration "," Condition "," LoopAction ")" "{"
ActionList "}"
LoopAction -> Identifier "=" Expression

# Function Calls

FunctionCall -> (Identifier | Keyword) "(" Expression ")"

# Actions

Action -> Statement


ActionList -> Action ActionList | ε

# Keywords

Keyword -> "print" | "return" | other_keywords...

# Example: "keyword/identifier"("expression")

You might also like