-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add language support for Simula #7025
base: main
Are you sure you want to change the base?
Changes from all commits
9596d2c
c72b594
8866963
9ad6c22
2f3e192
8695792
e7f3f44
395ca27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1635,6 +1635,7 @@ Dockerfile: | |
filenames: | ||
- Containerfile | ||
- Dockerfile | ||
- Dockerfile.sim | ||
ace_mode: dockerfile | ||
codemirror_mode: dockerfile | ||
codemirror_mime_type: text/x-dockerfile | ||
|
@@ -4204,6 +4205,7 @@ Makefile: | |
- Makefile.frag | ||
- Makefile.in | ||
- Makefile.inc | ||
- Makefile.sim | ||
- Makefile.wat | ||
- makefile | ||
- makefile.sco | ||
|
@@ -6821,6 +6823,18 @@ Simple File Verification: | |
codemirror_mode: properties | ||
codemirror_mime_type: text/x-properties | ||
language_id: 735623761 | ||
Simula: | ||
type: programming | ||
color: "#B22F2F" | ||
extensions: | ||
- ".sim" | ||
aliases: | ||
- sim | ||
tm_scope: source.sim | ||
ace_mode: simula | ||
codemirror_mode: simula | ||
codemirror_mime_type: text/x-simula | ||
language_id: 582204041 | ||
Singularity: | ||
type: programming | ||
color: "#64E6AD" | ||
|
@@ -8245,6 +8259,7 @@ YAML: | |
- ".mir" | ||
- ".reek" | ||
- ".rviz" | ||
- ".sim" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a sample for this language if you're going to add this extension here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not 100 % what you meant - was this about the Simula language, or about the YAML fallback? I made 2 updates to the pull request:
It would be nice if linguist supported a "noop fallback" configuration, where - if we can't positively identify a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was referring to the YAML entry. You added it but didn't add a sample. I see you've now added samples but you've now also added samples that are too big. Please remove any that are suppressed in the diff and any that aren't real world uses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I removed the samples! |
||
- ".sublime-syntax" | ||
- ".syntax" | ||
- ".yaml" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
! License: MIT; | ||
begin | ||
integer i; | ||
for i := 99 step -1 until 1 do | ||
begin | ||
outint(i, 2); | ||
outtext(" bottles of beer on the wall, "); | ||
outint(i, 2); | ||
outtext(" bottles of beer."); | ||
outimage; | ||
outtext("Take one down and pass it around, "); | ||
outint(i - 1, 2); | ||
outtext(" bottles of beer on the wall."); | ||
outimage; | ||
end; | ||
outtext("No more bottles of beer on the wall, no more bottles of beer."); | ||
end-let's-drink; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
! A simple Tic-Tac-Toe game. License: MIT; | ||
begin | ||
ref(TicTacToe) game; | ||
character player; | ||
|
||
class TicTacToe; | ||
begin | ||
character array board(1:9); | ||
|
||
procedure placeMark(mark, position); | ||
value mark, position; | ||
character mark; integer position; | ||
begin | ||
board(position) := mark; | ||
end-of-place-mark; | ||
|
||
boolean procedure checkWinner(player); | ||
value player; | ||
character player; | ||
begin | ||
integer position; | ||
comment | ||
There are 8 possible ways to win: 3 rows, 3 columns, and 2 diagonals. | ||
For reasons of laziness, we just AI-generate them: | ||
; | ||
if board(1) = player and board(2) = player and board(3) = player then | ||
checkWinner := true | ||
else if board(4) = player and board(5) = player and board(6) = player then | ||
checkWinner := true | ||
else if board(7) = player and board(8) = player and board(9) = player then | ||
checkWinner := true | ||
else if board(1) = player and board(4) = player and board(7) = player then | ||
checkWinner := true | ||
else if board(2) = player and board(5) = player and board(8) = player then | ||
checkWinner := true | ||
else if board(3) = player and board(6) = player and board(9) = player then | ||
checkWinner := true | ||
else if board(1) = player and board(5) = player and board(9) = player then | ||
checkWinner := true | ||
else if board(3) = player and board(5) = player and board(7) = player then | ||
checkWinner := true | ||
else | ||
checkWinner := false; | ||
end-of-checkWinner; | ||
|
||
character procedure winner; | ||
begin | ||
if checkWinner('X') then winner := 'X' | ||
else if checkWinner('O') then winner := 'O' | ||
else winner := ' '; | ||
end-of-winner; | ||
|
||
procedure DrawTopBottom; begin | ||
OutText("+---+---+---+"); | ||
OutImage; | ||
end; | ||
|
||
procedure draw; | ||
begin | ||
integer row; | ||
OutImage; | ||
DrawTopBottom; | ||
for row := 0 step 1 until 2 do begin | ||
OutText("| " ); | ||
OutChar(board(row * 3 + 1)); | ||
OutText(" | " ); | ||
OutChar(board(row * 3 + 2)); | ||
OutText(" | " ); | ||
OutChar(board(row * 3 + 3)); | ||
OutText(" |"); | ||
OutImage; | ||
DrawTopBottom; | ||
end | ||
end-of-draw; | ||
|
||
!populate the board with number placeholders; | ||
board(1) := '1'; | ||
board(2) := '2'; | ||
board(3) := '3'; | ||
board(4) := '4'; | ||
board(5) := '5'; | ||
board(6) := '6'; | ||
board(7) := '7'; | ||
board(8) := '8'; | ||
board(9) := '9'; | ||
end-of-TicTacToe; | ||
|
||
|
||
game :- new TicTacToe; | ||
player := 'X'; | ||
|
||
while game.winner <> 'X' and game.winner <> 'O' do | ||
begin | ||
game.draw; | ||
OutText("Player "); | ||
OutChar(player); | ||
OutText(" enter position: "); | ||
OutImage; | ||
game.placeMark(player, InInt); | ||
if player = 'X' then player := 'O' else player := 'X'; | ||
end; | ||
|
||
game.draw; | ||
|
||
OutText("The winner is: player "); | ||
OutChar(game.winner); | ||
OutImage; | ||
end-of-program |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT; | ||
begin | ||
! klant 1 | ||
beschrijving van een winkel | ||
copyright H.G.Sol; | ||
|
||
external class Demos; | ||
|
||
Demos begin | ||
Entity class Klant; | ||
begin | ||
Bediendes.Acquire(1); | ||
Hold(5); | ||
Bediendes.Release(1); | ||
Kassieres.Acquire(1); | ||
Hold(2); | ||
Kassieres.Release(1); | ||
end; | ||
ref(Res) Bediendes,Kassieres; | ||
Bediendes:- new Res("bediendes",2); | ||
Kassieres:- new Res("kassieres",1); | ||
Trace; | ||
new Klant("klant").Schedule(1); | ||
new Klant("klant").Schedule(2); | ||
new Klant("klant").Schedule(5); | ||
new Klant("klant").Schedule(6); | ||
Hold(40); | ||
end; | ||
end; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT; | ||
begin | ||
external class demos; | ||
! klant 4 | ||
zelfbediening en artikelvoorraad | ||
copyright H.G.Sol; | ||
Demos begin | ||
Entity class Klant; | ||
begin | ||
Karren.Acquire(1); | ||
Bier.Take(Hoevelheid.Sample); | ||
Hold(Paktijd.Sample); | ||
if Vragen.Sample then | ||
begin | ||
Bediendes.Acquire(1); | ||
Hold(Helptijd.Sample); | ||
Bediendes.Release(1); | ||
end; | ||
Kassieres.Acquire(1); | ||
Hold(Betaaltijd.Sample); | ||
Kassieres.Release(1); | ||
Karren.Release(1); | ||
end; | ||
|
||
Entity class Bierleverantie(Frequentie); | ||
real Frequentie; | ||
begin | ||
if Bier.Avail < 100 then | ||
Bier.Give(300); | ||
Hold(1/Frequentie); | ||
Repeat; | ||
end; | ||
|
||
Entity class Klantengenerator(Tussentijd); | ||
ref(Rdist)Tussentijd; | ||
begin | ||
new Klant("klant").Schedule(0); | ||
Hold(Tussentijd.Sample); | ||
Repeat; | ||
end; | ||
|
||
ref(Res) Karren,Bediendes,Kassieres; | ||
ref(Bin) Bier; | ||
ref(Rdist) Paktijd,Helptijd, Betaaltijd, Tussentijd; | ||
ref(Idist) Hoevelheid; | ||
ref(Bdist) Vragen; | ||
|
||
trace; | ||
|
||
Karren:- new Res("karren",10); | ||
Bediendes:- new Res("bediendes",2); | ||
Kassieres:- new Res("kassieres",2); | ||
Bier:- new Bin("bier",150); | ||
Tussentijd:- new Negexp("tt",.5); | ||
Paktijd:- new Normal("pt",5,.5); | ||
Helptijd:- new Normal("ht",2,.5); | ||
Betaaltijd:- new Negexp("bt",.5); | ||
Hoevelheid:- new Randint("hv",1,12); | ||
Vragen:- new Draw("vr",.3); | ||
|
||
Hold(9*60); | ||
Reset; | ||
new Bierleverantie("bl",1/40).Schedule(30); | ||
new Klantengenerator("kg",Tussentijd).Schedule(0); | ||
Hold(18*60 - 9*60); | ||
end; | ||
end; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
comment License: program borrowed from S-PORT https://github.com/portablesimula/S-PORT; | ||
begin | ||
comment this program computes the "best" powers of ten re U1100; | ||
integer lower, upper, minlim, ee, pp; | ||
|
||
procedure outpower(exp_param,power_param); name exp_param; | ||
integer exp_param,power_param; | ||
begin | ||
integer exp, power; | ||
integer array digits(lower:upper); | ||
integer max,min,digit; | ||
|
||
procedure divide(exp); integer exp; | ||
begin integer i, rem; | ||
while exp>0 do begin | ||
exp := exp-1; rem := 0; | ||
i := max+1; | ||
while i>min do begin | ||
i := i-1; | ||
digit := digits(i)//2; | ||
if digits(i)-2*digit>0 then digits(i-1):=digits(i-1)+10; | ||
digits(i):=digit; | ||
end; | ||
if digits(min-1)>0 then begin | ||
min := min-1; digits(min) := 5; | ||
end; | ||
if digits(max)=0 then max:=max-1; | ||
end while; | ||
if max<>0 then begin exp_param:=exp_param+1; goto RETRY end; | ||
end divide; | ||
|
||
procedure output; | ||
begin integer i, j, first, last, carry, borrow; | ||
! the number to be output is in digits(min:max); | ||
last := min; | ||
first := max+1; | ||
while first>min do begin | ||
first := first-1; | ||
carry:=borrow:=0; | ||
i := last-1; | ||
while i<first do begin | ||
i := i+1; | ||
digit:=digits(i)*2+carry; | ||
if digit>10 then begin carry:=1; digit:=digit-10 end | ||
else carry:=0; | ||
digit:=digits(i-1)-digit-borrow; | ||
if digit<0 then begin borrow:=1; digit:=digit+10 end | ||
else borrow:=0; | ||
digits(i-1):=digit; | ||
end; | ||
digits(first) := digits(first)-borrow-carry; | ||
if digits(last)<>0 then last:=last-1; | ||
end first; | ||
if digits(0)<4 then begin exp_param:=exp_param-1; goto RETRY end; | ||
if digits(-20)=7 | ||
then begin | ||
outint(exp_param,4); outint(power_param,4); outchar(':'); | ||
for i:= -20 step -1 until -22 do outchar(char(rank('0')+digits(i))); | ||
outimage; | ||
end | ||
else if digits(-20)=0 | ||
then begin | ||
outint(exp_param,4); outint(power_param,4); outchar(':'); | ||
for i:= -20 step -1 until -22 do outchar(char(rank('0')+digits(i))); | ||
outimage; | ||
end if; | ||
end output; | ||
|
||
RETRY: ! here when the exponent has been corrected; | ||
exp := exp_param; power := power_param; | ||
max:= power+1; !one sign. digit only; | ||
min:= max; !one sign. digit only; | ||
digits(max):=1; | ||
divide(exp); | ||
output; | ||
end outpower; | ||
|
||
!outtext("51634306575354226427"); ! outimage; | ||
!outpower(665,200); | ||
!outpower(608,183); ! 75 - denne er best; | ||
!outtext("44446551131230337166"); ! outimage; | ||
!outpower(326,098); ! 74 - denne er best; | ||
!outtext("42154166127714446321"); outimage; | ||
!outpower(167,050); ! 76 - denne er best; | ||
|
||
ee := 1026; pp := 308; | ||
while pp>0 do | ||
begin upper := pp; lower := -3.4*upper; | ||
ee := ee-3; pp := pp-1; outpower(ee,pp) end; | ||
|
||
end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need a test for this heuristic