mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add TXL language
Add: * TXL language * Sample TXL file
This commit is contained in:
@@ -1175,6 +1175,13 @@ SuperCollider:
|
|||||||
extensions:
|
extensions:
|
||||||
- .scd
|
- .scd
|
||||||
|
|
||||||
|
TXL:
|
||||||
|
type: programming
|
||||||
|
lexer: Text only
|
||||||
|
primary_extension: .txl
|
||||||
|
extensions:
|
||||||
|
- .txl
|
||||||
|
|
||||||
Tcl:
|
Tcl:
|
||||||
type: programming
|
type: programming
|
||||||
color: "#e4cc98"
|
color: "#e4cc98"
|
||||||
|
|||||||
80
samples/TXL/Cal.Txl
Normal file
80
samples/TXL/Cal.Txl
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
% Calculator.Txl - simple numerical expression evaluator
|
||||||
|
|
||||||
|
% Part I. Syntax specification
|
||||||
|
define program
|
||||||
|
[expression]
|
||||||
|
end define
|
||||||
|
|
||||||
|
define expression
|
||||||
|
[term]
|
||||||
|
| [expression] [addop] [term]
|
||||||
|
end define
|
||||||
|
|
||||||
|
define term
|
||||||
|
[primary]
|
||||||
|
| [term] [mulop] [primary]
|
||||||
|
end define
|
||||||
|
|
||||||
|
define primary
|
||||||
|
[number]
|
||||||
|
| ( [expression] )
|
||||||
|
end define
|
||||||
|
|
||||||
|
define addop
|
||||||
|
'+
|
||||||
|
| '-
|
||||||
|
end define
|
||||||
|
|
||||||
|
define mulop
|
||||||
|
'*
|
||||||
|
| '/
|
||||||
|
end define
|
||||||
|
|
||||||
|
|
||||||
|
% Part 2. Transformation rules
|
||||||
|
rule main
|
||||||
|
replace [expression]
|
||||||
|
E [expression]
|
||||||
|
construct NewE [expression]
|
||||||
|
E [resolveAddition] [resolveSubtraction] [resolveMultiplication]
|
||||||
|
[resolveDivision] [resolveParentheses]
|
||||||
|
where not
|
||||||
|
NewE [= E]
|
||||||
|
by
|
||||||
|
NewE
|
||||||
|
end rule
|
||||||
|
|
||||||
|
rule resolveAddition
|
||||||
|
replace [expression]
|
||||||
|
N1 [number] + N2 [number]
|
||||||
|
by
|
||||||
|
N1 [+ N2]
|
||||||
|
end rule
|
||||||
|
|
||||||
|
rule resolveSubtraction
|
||||||
|
replace [expression]
|
||||||
|
N1 [number] - N2 [number]
|
||||||
|
by
|
||||||
|
N1 [- N2]
|
||||||
|
end rule
|
||||||
|
|
||||||
|
rule resolveMultiplication
|
||||||
|
replace [term]
|
||||||
|
N1 [number] * N2 [number]
|
||||||
|
by
|
||||||
|
N1 [* N2]
|
||||||
|
end rule
|
||||||
|
|
||||||
|
rule resolveDivision
|
||||||
|
replace [term]
|
||||||
|
N1 [number] / N2 [number]
|
||||||
|
by
|
||||||
|
N1 [/ N2]
|
||||||
|
end rule
|
||||||
|
|
||||||
|
rule resolveParentheses
|
||||||
|
replace [primary]
|
||||||
|
( N [number] )
|
||||||
|
by
|
||||||
|
N
|
||||||
|
end rule
|
||||||
Reference in New Issue
Block a user