Skip to content

Commit

Permalink
Add a scheme grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
mingodad committed Sep 4, 2023
1 parent e189a37 commit e9248f8
Show file tree
Hide file tree
Showing 3 changed files with 5,920 additions and 0 deletions.
1 change: 1 addition & 0 deletions playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const sampleList = [
["MSTA parser", "msta.g", "test.msta", "ace/mode/yaml"],
["Textdiagram parser", "textdiagram.g", "test.textdiagram", "ace/mode/text"],
["Pikchr parser", "pikchr.g", "test.pikchr", "ace/mode/text"],
["Scheme parser", "scheme.g", "test.scheme", "ace/mode/lisp"],
["Minic parser", "minic.g", "test.minic", "ace/mode/c_cpp"],
["Z80 assembler parser", "z80-asm.g", "test.z80-asm", "ace/mode/assembly_x86"],
["Peg parser (partially working)", "peg.g", "test.peg", "ace/mode/yaml"],
Expand Down
136 changes: 136 additions & 0 deletions playground/scheme.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//From: https://github.com/jarvinet/scheme/blob/master/src/scparse.y

/*Tokens*/
%token IDENTIFIER
%token NUMBER
%token CHARACTER
%token STRING
%token BEGINVECTOR
%token OPENPAR
%token CLOSEPAR
%token DOT
%token QUOTE
%token QUASIQUOTE
%token UNQUOTE
%token UNQUOTESPLICING
%token TOKEN_TRUE
%token TOKEN_FALSE


%start input

%%

input :
%empty
| input datum
;

datum :
simpledatum
| compounddatum
;

simpledatum :
boolean
| number
| character
| string
| symbol
;

boolean :
TOKEN_TRUE
| TOKEN_FALSE
;

number :
NUMBER
;

character :
CHARACTER
;

string :
STRING
;

symbol :
IDENTIFIER
;

compounddatum :
list
| vector
;

list :
OPENPAR datumzero CLOSEPAR
| OPENPAR datumone DOT datum CLOSEPAR
| abbreviation
;

vector :
BEGINVECTOR datumzero CLOSEPAR
;

datumzero :
datumzero datum
| /*empty*/
;

datumone :
datumzero datum
;

abbreviation :
abbrevprefix datum
;

abbrevprefix :
QUOTE
| QUASIQUOTE
| UNQUOTE
| UNQUOTESPLICING
;

%%

letter [A-Za-z]
digit [0-9]
specialinitial [!$%&*/:<=>?^_~]
initial {letter}|{specialinitial}
specialsubsequent [-+.@]
peculiaridentifier "-"|"+"|"..."
subsequent ({initial})|{digit}|{specialsubsequent}
identifier ({initial})({subsequent})*|{peculiaridentifier}
sign [+-]
number ({sign})?({digit})+("."{digit}+)?

%%

\"(\\.|[^"\n\r\\])*\" STRING
"#(" BEGINVECTOR
"(" OPENPAR
")" CLOSEPAR
"." DOT
"'" QUOTE
"`" QUASIQUOTE
"," UNQUOTE
",@" UNQUOTESPLICING
"#t" TOKEN_TRUE
"#f" TOKEN_FALSE
{number} NUMBER
#\\space CHARACTER
#\\SPACE CHARACTER
#\\newline CHARACTER
#\\NEWLINE CHARACTER
#\\. CHARACTER
";".* skip()
\n\r?|\r\n? skip()
[ \t]+ skip() /* eat up whitespace */
{identifier} IDENTIFIER

%%
Loading

0 comments on commit e9248f8

Please sign in to comment.