Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pascal Interpreter

A fully-featured Pascal interpreter written in Python that supports variables, procedures, and arithmetic operations.

Features

  • Lexical Analysis: Tokenizes Pascal source code
  • Parsing: Builds an Abstract Syntax Tree (AST) from tokens
  • Semantic Analysis: Validates variable declarations and scoping rules
  • Interpretation: Executes the AST with call stack management

Supported Features

  • Variable declarations (INTEGER and REAL types)
  • Procedure definitions and calls
  • Formal and actual parameters
  • Nested scopes
  • Arithmetic operations: +, -, *, /, DIV
  • Unary operations: +, -
  • Comments: { comment text }

Project Structure

  • main.py - Entry point and command-line interface
  • lexer.py - Tokenization module
  • tokens.py - Token type definitions
  • parser.py - Parser implementation
  • ast_nodes.py - AST node classes
  • semantic_analyzer.py - Semantic analysis and symbol table management
  • interpreter.py - AST interpreter and execution engine
  • errors.py - Error definitions
  • demo.pas - Sample Pascal program

Usage

python main.py <pascal_file>

Options

  • --scope - Print scope information during execution
  • --stack - Print call stack during execution

Example

python main.py demo.pas

Sample Pascal Program

PROGRAM Demo;

VAR
    x, y: INTEGER;
    a: REAL;

PROCEDURE Add(num1, num2: INTEGER);
BEGIN
END;

BEGIN
    x := 10;
    y := 20;
    a := 5.5;
    Add(x, y)
END.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages