Skip to content

tashib11/compiler-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PAW Language Compiler

A custom programming language lexical analyzer built with Flex (Lex). PAW uses creative command names and syntax for a unique programming experience.

Overview

This project implements a lexical analyzer for the PAW programming language, a custom language with unique keywords and syntax patterns. The analyzer tokenizes source code and identifies different token types including keywords, identifiers, literals, operators, and delimiters.

Project Files

  • pawlang.l - Main Lex specification file for the PAW language lexer
  • count.l - Additional Lex specification (utility lexer)
  • lex.yy.c - Generated C code from Lex compilation
  • input.txt - Sample PAW program for testing
  • output.txt - Output from lexical analysis
  • command.txt - Build and run commands

Building and Running

Prerequisites

  • Flex (Lex compiler)
  • GCC (C compiler)

Compilation Commands

# Compile the PAW language lexer
flex pawlang.l
gcc lex.yy.c -o pawlang
.\pawlang

# Compile the counter lexer
flex count.l
.\count

PAW Language Syntax

Keywords

PAW Keyword Meaning Example
var Variable var x = 10
const Constant const g = 9.8
fun Function fun main() {}
iff If statement iff (x > 5) {}
eliff Else if eliff (x < 5) {}
neo Else neo {}
run For loop run (var i = 0 \ i < 10 \ i++)
when While loop when (condition) {}
show Print/Output show "text"
pay Return pay value
arr Array arr numbers = {1, 2, 3}
offja Break offja
skip Continue skip
turu True turu
vugi False vugi
nil Null nil
chk Try chk {}
caught Catch caught {}
staple Main function fun staple() {}
take Scanf/Input take x
proin Include proin library

Data Types & Literals

  • INTEGER - Numeric literals: 123, 456
  • FLOAT - Decimal numbers: 9.8, 3.14
  • STRING - Double-quoted text: "hello world"
  • VSTRING - Variable string (with interpolation): 'hello {name}'

Operators & Delimiters

  • OPERATOR - Arithmetic and logical: + - * / = < > ! & |
  • DELIMITER - Brackets and separators: , ( ) [ ] { } \

Comments

  • Single-line: // comment
  • Multi-line: /* comment */

Token Output

The lexer produces output in the format:

token_type -> matched_text

Example output:

funtion     -> fun
variable    -> var
INTEGER     -> 100
OPERATOR    -> =
IDENTIFIER  -> x

Sample Program

See input.txt for a sample PAW program demonstrating language features:

  • Variable and constant declarations
  • Array creation
  • Conditional statements (if/else if/else)
  • Loop construction
  • String output with variable interpolation

Architecture

The lexer uses Flex regex patterns to:

  1. Match language keywords to token types
  2. Identify identifiers and literals
  3. Recognize operators and delimiters
  4. Handle comments (single and multi-line)
  5. Report unrecognized symbols

Generated Output

Run the compiled program to analyze PAW source files and produce tokenized output showing the lexical analysis results.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors