Initial check in docu

This commit is contained in:
2026-01-03 18:31:15 +01:00
parent e2c3cbc520
commit ee130973e2
98 changed files with 9430 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
// ============================================================================
// Demo parser for four operator calculator
// ============================================================================
unit calcParser;
parser TcalcParser;
options
{
importVocab = calcLexer;
exportVocab = calcParser;
}
memberdecl
{
value : integer;
}
// ============================================================================
// calc
// ============================================================================
calc
: (expression SEMI {writeln(value);} )+
;
// ============================================================================
// expression
// ============================================================================
expression
: simpleExpression
;
// ============================================================================
// simpleExpression
// ============================================================================
simpleExpression
local
{
temp: integer;
}
: term { temp := value; }
(
PLUS term { temp := temp + value; }
| MINUS term { temp := temp - value; }
)* { value := temp; }
;
// ============================================================================
// term
// ============================================================================
term
local
{
temp: integer;
}
: factor { temp := value; }
(
STAR factor { temp := temp * value; }
| SLASH factor { temp := temp div value; }
)* { value := temp; }
;
// ============================================================================
// factor
// ============================================================================
factor
local
{
s: integer;
}
{
s := 1;
}
:
(
PLUS { s := 1; }
| MINUS { s := -1; }
)?
(
uInt
| LPAREN expression RPAREN
)
{
value := s * value;
}
;
// ============================================================================
// uInt
// ============================================================================
uInt
: x:INT { value := StrToInt( x.TokenText); }
;