-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #914 from andrew-johnson-4/parse-c-headers
Parse c headers
- Loading branch information
Showing
6 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
dev: install-production | ||
lm --c t.lm | ||
lm --c tests/regress/import-c.lm | ||
cc tmp.c | ||
./a.out | ||
echo $? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
c-parse := λ(: tokens List<String>). (: ( | ||
(print tokens) | ||
) Nil); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
|
||
c-tokenize := λ(: text String). (: ( | ||
(print text) | ||
(let tokens (: LEOF List<String>)) | ||
(while (head-string text) ( | ||
(let prev-text text) | ||
# these steps don't need to be ordered, so first-come first-serve | ||
(if (has-prefix( text '\s_s )) (set text (remove-prefix( text '\s_s ))) ()) | ||
(if (has-prefix( text '\t_s )) (set text (remove-prefix( text '\t_s ))) ()) | ||
(if (has-prefix( text '\n_s )) (set text (remove-prefix( text '\n_s ))) ()) | ||
(if (has-prefix( text '\[_s )) ( (set text (remove-prefix( text '\[_s ))) (set tokens (cons( '\[_s tokens ))) ) ()) | ||
(if (has-prefix( text '\]_s )) ( (set text (remove-prefix( text '\]_s ))) (set tokens (cons( '\]_s tokens ))) ) ()) | ||
(if (has-prefix( text '[_s )) ( (set text (remove-prefix( text '[_s ))) (set tokens (cons( '[_s tokens ))) ) ()) | ||
(if (has-prefix( text ']_s )) ( (set text (remove-prefix( text ']_s ))) (set tokens (cons( ']_s tokens ))) ) ()) | ||
(if (has-prefix( text '{_s )) ( (set text (remove-prefix( text '{_s ))) (set tokens (cons( '{_s tokens ))) ) ()) | ||
(if (has-prefix( text '}_s )) ( (set text (remove-prefix( text '}_s ))) (set tokens (cons( '}_s tokens ))) ) ()) | ||
(if (has-prefix( text ',_s )) ( (set text (remove-prefix( text ',_s ))) (set tokens (cons( ',_s tokens ))) ) ()) | ||
(if (has-prefix( text '->_s )) ( (set text (remove-prefix( text '->_s ))) (set tokens (cons( '->_s tokens ))) ) ()) | ||
(if (has-prefix( text '!=_s )) ( (set text (remove-prefix( text '!=_s ))) (set tokens (cons( '!=_s tokens ))) ) ()) | ||
(if (has-prefix( text '!_s )) ( (set text (remove-prefix( text '!_s ))) (set tokens (cons( '!_s tokens ))) ) ()) | ||
(if (has-prefix( text '==_s )) ( (set text (remove-prefix( text '==_s ))) (set tokens (cons( '==_s tokens ))) ) ()) | ||
(if (has-prefix( text '=_s )) ( (set text (remove-prefix( text '=_s ))) (set tokens (cons( '=_s tokens ))) ) ()) | ||
(if (has-prefix( text '+=_s )) ( (set text (remove-prefix( text '+=_s ))) (set tokens (cons( '+=_s tokens ))) ) ()) | ||
(if (has-prefix( text '-=_s )) ( (set text (remove-prefix( text '-=_s ))) (set tokens (cons( '-=_s tokens ))) ) ()) | ||
(if (has-prefix( text '/=_s )) ( (set text (remove-prefix( text '/=_s ))) (set tokens (cons( '/=_s tokens ))) ) ()) | ||
(if (has-prefix( text '%=_s )) ( (set text (remove-prefix( text '%=_s ))) (set tokens (cons( '%=_s tokens ))) ) ()) | ||
(if (has-prefix( text '*=_s )) ( (set text (remove-prefix( text '*=_s ))) (set tokens (cons( '*=_s tokens ))) ) ()) | ||
(if (has-prefix( text '<<=_s )) ( (set text (remove-prefix( text '<<=_s ))) (set tokens (cons( '<<=_s tokens ))) ) ()) | ||
(if (has-prefix( text '>>=_s )) ( (set text (remove-prefix( text '>>=_s ))) (set tokens (cons( '>>=_s tokens ))) ) ()) | ||
(if (has-prefix( text '&=_s )) ( (set text (remove-prefix( text '&=_s ))) (set tokens (cons( '&=_s tokens ))) ) ()) | ||
(if (has-prefix( text '^=_s )) ( (set text (remove-prefix( text '^=_s ))) (set tokens (cons( '^=_s tokens ))) ) ()) | ||
(if (has-prefix( text '|=_s )) ( (set text (remove-prefix( text '|=_s ))) (set tokens (cons( '|=_s tokens ))) ) ()) | ||
(if (has-prefix( text '+_s )) ( (set text (remove-prefix( text '+_s ))) (set tokens (cons( '+_s tokens ))) ) ()) | ||
(if (has-prefix( text '-_s )) ( (set text (remove-prefix( text '-_s ))) (set tokens (cons( '-_s tokens ))) ) ()) | ||
(if (has-prefix( text '*_s )) ( (set text (remove-prefix( text '*_s ))) (set tokens (cons( '*_s tokens ))) ) ()) | ||
(if (has-prefix( text '/_s )) ( (set text (remove-prefix( text '/_s ))) (set tokens (cons( '/_s tokens ))) ) ()) | ||
(if (has-prefix( text '%_s )) ( (set text (remove-prefix( text '%_s ))) (set tokens (cons( '%_s tokens ))) ) ()) | ||
(if (has-prefix( text '<<_s )) ( (set text (remove-prefix( text '<<_s ))) (set tokens (cons( '<<_s tokens ))) ) ()) | ||
(if (has-prefix( text '>>_s )) ( (set text (remove-prefix( text '>>_s ))) (set tokens (cons( '>>_s tokens ))) ) ()) | ||
(if (has-prefix( text '&_s )) ( (set text (remove-prefix( text '&_s ))) (set tokens (cons( '&_s tokens ))) ) ()) | ||
(if (has-prefix( text '^_s )) ( (set text (remove-prefix( text '^_s ))) (set tokens (cons( '^_s tokens ))) ) ()) | ||
(if (has-prefix( text '|_s )) ( (set text (remove-prefix( text '|_s ))) (set tokens (cons( '|_s tokens ))) ) ()) | ||
(if (has-prefix( text '~_s )) ( (set text (remove-prefix( text '~_s ))) (set tokens (cons( '~_s tokens ))) ) ()) | ||
(if (has-prefix( text '?_s )) ( (set text (remove-prefix( text '?_s ))) (set tokens (cons( '?_s tokens ))) ) ()) | ||
(if (has-prefix( text ':_s )) ( (set text (remove-prefix( text ':_s ))) (set tokens (cons( ':_s tokens ))) ) ()) | ||
(if (has-prefix( text '\:_s )) ( (set text (remove-prefix( text '\:_s ))) (set tokens (cons( '\:_s tokens ))) ) ()) | ||
(if (has-prefix( text '._s )) ( (set text (remove-prefix( text '._s ))) (set tokens (cons( '._s tokens ))) ) ()) | ||
(if (has-prefix( text '\o_s )) ( | ||
(while (&&( (!=( (head-string text) 0_u8 )) (!=( (head-string text) 10_u8 )) )) ( | ||
(set text (tail-string text)) | ||
)) | ||
) ()) | ||
(if (is-c-ident-char( text )) ( | ||
(let t SNil) | ||
(while (&&( (!=( (head-string text) 0_u8 )) (is-c-ident-char text) )) ( | ||
(set t (+( t (SAtom(clone-rope(head-string text))) ))) | ||
(set text (tail-string text)) | ||
)) | ||
(set tokens (cons( (clone-rope t) tokens ))) | ||
) ()) | ||
(if (==( (as text U64) (as prev-text U64) )) ( | ||
(print 'Unrecognized\sC\sToken\sStart:\s_s)(print (head-string text))(print '\n_s)(exit 1_u64) | ||
) ()) | ||
)) | ||
tokens | ||
) List<String>); | ||
|
||
is-c-ident-char := λ(: text String). (: ( | ||
(let r 0_u64) | ||
(match (head-string text) ( | ||
() | ||
( 46_u8 (set r 1_u64) ) | ||
( 48_u8 (set r 1_u64) ) | ||
( 49_u8 (set r 1_u64) ) | ||
( 50_u8 (set r 1_u64) ) | ||
( 51_u8 (set r 1_u64) ) | ||
( 52_u8 (set r 1_u64) ) | ||
( 53_u8 (set r 1_u64) ) | ||
( 54_u8 (set r 1_u64) ) | ||
( 55_u8 (set r 1_u64) ) | ||
( 56_u8 (set r 1_u64) ) | ||
( 57_u8 (set r 1_u64) ) | ||
( 65_u8 (set r 1_u64) ) | ||
( 66_u8 (set r 1_u64) ) | ||
( 67_u8 (set r 1_u64) ) | ||
( 68_u8 (set r 1_u64) ) | ||
( 69_u8 (set r 1_u64) ) | ||
( 70_u8 (set r 1_u64) ) | ||
( 71_u8 (set r 1_u64) ) | ||
( 72_u8 (set r 1_u64) ) | ||
( 73_u8 (set r 1_u64) ) | ||
( 74_u8 (set r 1_u64) ) | ||
( 75_u8 (set r 1_u64) ) | ||
( 76_u8 (set r 1_u64) ) | ||
( 77_u8 (set r 1_u64) ) | ||
( 78_u8 (set r 1_u64) ) | ||
( 79_u8 (set r 1_u64) ) | ||
( 80_u8 (set r 1_u64) ) | ||
( 81_u8 (set r 1_u64) ) | ||
( 82_u8 (set r 1_u64) ) | ||
( 83_u8 (set r 1_u64) ) | ||
( 84_u8 (set r 1_u64) ) | ||
( 85_u8 (set r 1_u64) ) | ||
( 86_u8 (set r 1_u64) ) | ||
( 87_u8 (set r 1_u64) ) | ||
( 88_u8 (set r 1_u64) ) | ||
( 89_u8 (set r 1_u64) ) | ||
( 90_u8 (set r 1_u64) ) | ||
( 95_u8 (set r 1_u64) ) | ||
( 97_u8 (set r 1_u64) ) | ||
( 98_u8 (set r 1_u64) ) | ||
( 99_u8 (set r 1_u64) ) | ||
( 100_u8 (set r 1_u64) ) | ||
( 101_u8 (set r 1_u64) ) | ||
( 102_u8 (set r 1_u64) ) | ||
( 103_u8 (set r 1_u64) ) | ||
( 104_u8 (set r 1_u64) ) | ||
( 105_u8 (set r 1_u64) ) | ||
( 106_u8 (set r 1_u64) ) | ||
( 107_u8 (set r 1_u64) ) | ||
( 108_u8 (set r 1_u64) ) | ||
( 109_u8 (set r 1_u64) ) | ||
( 110_u8 (set r 1_u64) ) | ||
( 111_u8 (set r 1_u64) ) | ||
( 112_u8 (set r 1_u64) ) | ||
( 113_u8 (set r 1_u64) ) | ||
( 114_u8 (set r 1_u64) ) | ||
( 115_u8 (set r 1_u64) ) | ||
( 116_u8 (set r 1_u64) ) | ||
( 117_u8 (set r 1_u64) ) | ||
( 118_u8 (set r 1_u64) ) | ||
( 119_u8 (set r 1_u64) ) | ||
( 120_u8 (set r 1_u64) ) | ||
( 121_u8 (set r 1_u64) ) | ||
( 122_u8 (set r 1_u64) ) | ||
( _ () ) | ||
)) | ||
r | ||
) U64); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
|
||
import PLUGINS/FRONTEND/C/c-parse-all.lm; | ||
import PLUGINS/FRONTEND/C/c-tokenize.lm; | ||
import PLUGINS/FRONTEND/C/c-parse.lm; |