Per scriverlo, o meglio per scrivere il parser, ho iniziato a
"formalizzare" il linguaggio. ( La facoltà di ingeneria fa male io
l'ho sempre detto. ) ho usato la Backus-Naur_Form ( leggermente
modificata e addattata ). Volevo un vostro parere. E' una versione
minimale del pascal non prevede ne cicli ne funzioni ma è un punto di
inizio.
identifier ::= letter [ ( letter | digit | "_" )* ]
letter ::= "A".."Z" # da A a Z
digit ::= "0".."9" # da 0 a 9
ws = ( " " | "\n" | "\t" | comment )*
comment = "{" [ any_character* ] "}" | "(*" [ any_character* ] "*)"
program ::= [ ws ] [ program_head ] [ ws ] [ definition_section
[ ws ] ] statement_block.
program_head ::= "PROGRAM" ws identifier [ [ ws ] "(" [ ws ]
identifier [ ( [ ws ] "," [ ws ] identifier )* ] [ ws ] ")" ] [ ws ]
";"
definition_section := ( const_list | var_list )*
const_list ::= "CONST" ( ws identifier [ [ ws ] ":" [ ws ]
identifier ] [ ws ] "=" [ ws ] expression [ ws ] ";" [ ws ] )*
expression ::= expression_atom | expression_atom [ ws ]
aritmentic_operator [ ws ] expression_atom
expression_atom ::= identifier | string | numbers |
"(" [ ws ] expression [ ws ] ")"
string ::= """ any_character* """
numbers ::= digit* [ "." digit* ]
aritmetic_operator ::= "+" | "-" | "*" | "/" | "DIV" |
"MOD"
var_list ::= "VAR" ws ( identifier [ ws ] [ ( "," identifier
[ ws ] )* ] ":" [ ws ] identifier [ ws ] ";" [ ws ] )*
statement_block ::= "BEGIN" ws statament [ ( [ ws ] ";" [ ws ]
statement )* ] [ ws ] "END"
statement ::= if_statement | assignment_statement |
asm_statament_block
if_statement ::= "IF" ws boolean_expression ws "THEN" ws
statement [ ws "ELSE" ws statement ]
boolean_expression ::= boolean_expression_atom |
expression [ ws ] comparison_operator [ ws ] expression |
boolean_expression_atom ws boolean_operator ws boolean_expression_atom
boolean_expression_atom ::= identifier |
"(" [ ws ] boolean_expression [ ws ] ")" | "NOT" [ ws ]
boolean_expression_atom
comparison_operator ::= "=" | ">" | ">=" | "<" |
"<=" | "<>"
boolean_operator ::= "AND" | "OR" | "XOR"
assignment_statement ::= identifier [ ws ] ":=" [ ws ]
<expression>
asm_statament_block ::= "ASM" ws asm_statament [ ws ]
( asm_separator [ ws ] [ asm_statament ] )* [ ws ] "END"
asm_statament ::= asm_command ws [ asm_option
[ ( [ ws ] "," [ ws ] asm_option )* ] ]
asm_command ::= identifier
asm_option ::= identifier | number
asm_separator ::= ";" | "\n"