Skip to content

Latest commit

 

History

History
90 lines (72 loc) · 3.63 KB

File metadata and controls

90 lines (72 loc) · 3.63 KB

AI Language Design Assistant Report

Name: ____________________________
Adm No.: __________________________

1. Language Name and Description

Language Name: PRLANG (Pips Risk Language)

PRLANG is a tiny domain-specific language for calculating stop-loss distance and leveraged risk in trading. A user writes a command with symbol, order type, entry price, stop-loss, leverage, and optional lot size. The PRLANG runner evaluates the command and returns the SL distance in price, pips, estimated loss, required margin, and loss as a percentage of margin.

2. AI Conversations

2.1 Asking AI for Grammar Rules (BNF)

My prompt:
"Give me BNF grammar rules for a tiny trading language that accepts symbol, order type, entry, SL, leverage, and lot size."

AI response (important part):

<command>    ::= <symbol> <order_type> <price> "sl" <price> "leverage" <number> ["lot" <number>]
<symbol>     ::= "XAUUSD" | "EURUSD" | "GBPUSD" | "USDJPY"
<order_type> ::= "buy" | "sell" | "buy limit" | "sell limit"
<price>      ::= <number>
<number>     ::= <digit> | <digit> <number> | <digit> "." <digit_sequence>
<digit>      ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

2.2 Asking AI for Interpreter Code

My prompt:
"Write Python code to parse a command like XAUUSD buy limit 3110.00 sl 3109.95 leverage 100 lot 1 and compute pips and SL-risk metrics."

AI response (important part):

COMMAND_PATTERN = re.compile(
    r"^\\s*(?P<symbol>[A-Za-z]{6})\\s+"
    r"(?P<order_type>buy\\s+limit|sell\\s+limit|buy|sell)\\s+"
    r"(?P<entry>\\d+(?:\\.\\d+)?)\\s+"
    r"sl\\s+(?P<sl>\\d+(?:\\.\\d+)?)\\s+"
    r"leverage\\s+(?P<leverage>\\d+(?:\\.\\d+)?)"
    r"(?:\\s+lot\\s+(?P<lot>\\d+(?:\\.\\d+)?))?\\s*$",
    re.IGNORECASE,
)

price_diff = abs(entry - sl)
pips = price_diff / pip_size
loss_quote = price_diff * contract_size * lot
margin_required = (entry * contract_size * lot) / leverage

2.3 Asking AI to Fix One Problem

Problem identified:
The first version only handled hardcoded examples and did not read commands from a source file.

My prompt:
"Please update it so I can execute commands from a .prl file, skip comments, and print a report for each line."

AI response (important part):

def run_prl_file(file_path: str):
    with open(file_path, "r", encoding="utf-8") as f:
        for line_no, raw_line in enumerate(f, start=1):
            line = raw_line.strip()
            if not line or line.startswith("#"):
                continue
            result = run_pips_language(line)
            print(line_no, result)

3. Two Things the AI Did Well

  1. It generated a practical parser pattern for command-based trading syntax quickly.
  2. It provided a clear risk-calculation model linking price distance, pips, margin, and leverage.

4. Two Things the AI Got Wrong (or Needed Manual Fixing)

  1. Initial output mode relied on built-in examples instead of processing .prl input files.
  2. Validation and usability details (for example comments, empty lines, and CLI flow) needed refinement.

5. One Thing I Learned About Programming Languages

I learned that domain-specific languages are most useful when syntax matches real user tasks. In this project, simple keywords (sl, leverage, lot) made the language readable, while semantic rules produced useful risk metrics beyond basic parsing.

6. How to Run PRLANG

Single inline command:

python pips_risk_language.py --command "XAUUSD buy limit 3110.00 sl 3109.95 leverage 100 lot 1"

From a .prl source file:

python pips_risk_language.py pips_demo.prl

Example .prl source file: pips_demo.prl