|
|
@ -3,7 +3,7 @@ |
|
|
|
# Copyright (c) 2016-2021 Ian Piumarta and other contributors (see AUTHORS) |
|
|
|
# All rights reserved (see LICENSE) |
|
|
|
# |
|
|
|
# Last edited: 2023-03-22 16:30:14 by piumarta on zora-10.local |
|
|
|
# Last edited: 2023-03-22 16:42:06 by piumarta on zora-10.local |
|
|
|
|
|
|
|
%{ |
|
|
|
/* compile: leg -o ccmeta.c ccmeta.leg |
|
|
@ -34,6 +34,7 @@ |
|
|
|
|
|
|
|
#define META_PROTO_MAX t_Try |
|
|
|
|
|
|
|
// C protos must begin with Comment because it is a sentinel |
|
|
|
#define DO_C_PROTOS() \ |
|
|
|
_DO(Comment) _DO(Token) \ |
|
|
|
_DO(C_declaration) _DO(C_string) \ |
|
|
@ -2177,39 +2178,6 @@ __RESTRICT = '__restrict' !IDREST &{gnu} { $$= newToken("__restr |
|
|
|
__INLINE = '__inline' !IDREST &{gnu} { $$= newToken("__inline" ) } - |
|
|
|
_FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float128" ) } - |
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------- Common rules ----------------------------------------------# |
|
|
|
|
|
|
|
- = (blank | comment)* &{lang == META} |
|
|
|
| < Space* > &{lang == C} { if (yyleng && $$) setComment($$, newComment(yytext)) } |
|
|
|
|
|
|
|
|
|
|
|
#| C rules |
|
|
|
Space = Blank | Comment | EOL | Directive |
|
|
|
| "__extension__" &{gnu} { icol += 13 } |
|
|
|
|
|
|
|
Blank = ( [\003-\010] | '\013' | '\f' | [\016-\037] | [\177-\377] | ' ' ) { ++icol } |
|
|
|
| '\t' { icol= (icol + 8) & ~7 } |
|
|
|
|
|
|
|
EOL = ( "\r\n" | '\n' | '\r' ) { ++irow; icol= 0 } |
|
|
|
|
|
|
|
Comment = "/*" ( !"*/" (EOL | Any) )* "*/" |
|
|
|
| "//" ( ![\n\r] Any )* EOL |
|
|
|
|
|
|
|
Directive = "#" (!EOL .)* |
|
|
|
|
|
|
|
Any = . { ++icol } |
|
|
|
|
|
|
|
#| Meta rules |
|
|
|
blank = space | eol |
|
|
|
space = [ \t] |
|
|
|
eol = ( "\n""\r"* |
|
|
|
| "\r""\n"* |
|
|
|
) { inputStack->lineNumber++ } |
|
|
|
|
|
|
|
comment = "//" ( ![\n\r] . )* |
|
|
|
| "/*" ( !"*/" (eol | .) )* "*/" |
|
|
|
|
|
|
|
#--------------------------------------------- Meta grammar ----------------------------------------------# |
|
|
|
|
|
|
|
# the semicolon has to be explicit with no space eaten afterwards to prevent the |
|
|
@ -2259,7 +2227,7 @@ meta_ident = l:META_IDENT { $$ = l |
|
|
|
# | META_AT n:meta_prefix { $$ = newUnary(Unquote_proto, n) } |
|
|
|
|
|
|
|
meta_syntax2 = < [a-zA-Z_][a-zA-Z0-9_]* > |
|
|
|
&{ null != getSyntaxId(2, intern(yytext)) } - { $$ = getSyntaxId(2, intern(yytext)) } |
|
|
|
&{ null != getSyntaxId(2, intern(yytext)) } -- { $$ = getSyntaxId(2, intern(yytext)) } |
|
|
|
|
|
|
|
meta_try = META_TRY t:meta_stmt i:meta_null c:meta_null f:meta_null |
|
|
|
( META_CATCH META_LPAREN i:META_IDENT META_RPAREN c:meta_stmt ) ? |
|
|
@ -2380,7 +2348,7 @@ meta_value = n:META_FLOAT { $$ = newFloat(n) } |
|
|
|
| p:meta_paramList e:meta_block { $$ = newFunc(null, p, e, null) } |
|
|
|
| META_LPAREN ( i:meta_block | i:meta_exp ) META_RPAREN { $$ = i } |
|
|
|
|
|
|
|
meta_string = s:META_STRING - { $$ = s } |
|
|
|
meta_string = s:META_STRING -- { $$ = s } |
|
|
|
|
|
|
|
META_STRING = META_DQUOTE < (!META_DQUOTE meta_char)* > META_DQUOTE { $$ = makeString(unescape(yytext)) } |
|
|
|
|
|
|
@ -2411,93 +2379,125 @@ meta_keyword = META_SWITCH | META_CASE | META_DEFAULT | META_DO | META_FOR | MET |
|
|
|
| META_THROW | META_TRY | META_CATCH | META_FINALLY |
|
|
|
# | META_SYNTAX |
|
|
|
|
|
|
|
META_IDENT = !meta_keyword < [a-zA-Z_][a-zA-Z0-9_]* > - { $$ = intern(yytext) } |
|
|
|
META_IDENT = !meta_keyword < [a-zA-Z_][a-zA-Z0-9_]* > -- { $$ = intern(yytext) } |
|
|
|
|
|
|
|
meta_integer = i:META_INTEGER { $$ = i } |
|
|
|
| '-' i:meta_integer { $$ = makeInteger(-getInteger(i)) } |
|
|
|
|
|
|
|
META_INTEGER = '0b' < [01]+ > - { $$ = makeInteger(strtol(yytext, 0, 2)) } |
|
|
|
| '0x' < [0-9a-fA-F]+ > - { $$ = makeInteger(strtol(yytext, 0, 16)) } |
|
|
|
| '0' < [0-7]+ > - { $$ = makeInteger(strtol(yytext, 0, 8)) } |
|
|
|
| < [0-9]+ > - { $$ = makeInteger(strtol(yytext, 0, 10)) } |
|
|
|
| META_SQUOTE < (!META_SQUOTE meta_char) > META_SQUOTE - { $$ = makeInteger(unescape(yytext)[0]) } |
|
|
|
|
|
|
|
META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > - { $$ = makeFloat(strtold(yytext, 0)) } |
|
|
|
| < [-+]* [0-9]* '.' [0-9]+ ('e'[-+]*[0-9]+)? > - { $$ = makeFloat(strtold(yytext, 0)) } |
|
|
|
| < [-+]* [0-9]+ ('e'[-+]*[0-9]+) > - { $$ = makeFloat(strtold(yytext, 0)) } |
|
|
|
|
|
|
|
#META_FUN = 'fun' ![a-zA-Z0-9_] - |
|
|
|
#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] - |
|
|
|
META_VAR = 'var' ![a-zA-Z0-9_] - |
|
|
|
META_SWITCH = 'switch' ![a-zA-Z0-9_] - |
|
|
|
META_CASE = 'case' ![a-zA-Z0-9_] - |
|
|
|
META_DEFAULT = 'default' ![a-zA-Z0-9_] - |
|
|
|
META_DO = 'do' ![a-zA-Z0-9_] - |
|
|
|
META_FOR = 'for' ![a-zA-Z0-9_] - |
|
|
|
META_IN = 'in' ![a-zA-Z0-9_] - |
|
|
|
META_WHILE = 'while' ![a-zA-Z0-9_] - |
|
|
|
META_IF = 'if' ![a-zA-Z0-9_] - |
|
|
|
META_ELSE = 'else' ![a-zA-Z0-9_] - |
|
|
|
META_NULL = 'null' ![a-zA-Z0-9_] - |
|
|
|
META_RETURN = 'return' ![a-zA-Z0-9_] - |
|
|
|
META_BREAK = 'break' ![a-zA-Z0-9_] - |
|
|
|
META_CONTINUE = 'continue' ![a-zA-Z0-9_] - |
|
|
|
META_THROW = 'throw' ![a-zA-Z0-9_] - |
|
|
|
META_TRY = 'try' ![a-zA-Z0-9_] - |
|
|
|
META_CATCH = 'catch' ![a-zA-Z0-9_] - |
|
|
|
META_FINALLY = 'finally' ![a-zA-Z0-9_] - |
|
|
|
META_IMPORT = 'import' ![a-zA-Z0-9_] - |
|
|
|
META_HASH = '#' - |
|
|
|
META_LOGOR = '||' - |
|
|
|
META_LOGAND = '&&' - |
|
|
|
META_BITOR = '|' ![|=] - |
|
|
|
META_BITXOR = '^' ![=] - |
|
|
|
META_BITAND = '&' ![&=] - |
|
|
|
META_EQUAL = '==' - |
|
|
|
META_NOTEQ = '!=' - |
|
|
|
META_LESS = '<' ![<=] - |
|
|
|
META_LESSEQ = '<=' - |
|
|
|
META_GREATEREQ = '>=' - |
|
|
|
META_GREATER = '>' ![>=] - |
|
|
|
META_SHLEFT = '<<' ![=] - |
|
|
|
META_SHRIGHT = '>>' ![=] - |
|
|
|
META_PLUS = '+' ![+=] - |
|
|
|
META_MINUS = '-' ![-=] - |
|
|
|
META_NEGATE = '-' ![-=0-9.] - |
|
|
|
META_PLUSPLUS = '++' - |
|
|
|
META_MINUSMINUS = '--' - |
|
|
|
META_TILDE = '~' - |
|
|
|
META_PLING = '!' ![=] - |
|
|
|
META_MULTI = '*' ![=] - |
|
|
|
META_DIVIDE = '/' ![/=] - |
|
|
|
META_MODULO = '%' ![=] - |
|
|
|
META_ASSIGN = '=' ![=] - |
|
|
|
META_ASSIGNADD = '+=' - |
|
|
|
META_ASSIGNSUB = '-=' - |
|
|
|
META_ASSIGNMUL = '*=' - |
|
|
|
META_ASSIGNDIV = '/=' - |
|
|
|
META_ASSIGNMOD = '%=' - |
|
|
|
META_ASSIGNBITOR = '|=' - |
|
|
|
META_ASSIGNBITXOR = '^=' - |
|
|
|
META_ASSIGNBITAND = '&=' - |
|
|
|
META_ASSIGNSHLEFT = '<<=' - |
|
|
|
META_ASSIGNSHRIGHT = '>>=' - |
|
|
|
META_QUERY = '?' - |
|
|
|
META_COLON = ':' - |
|
|
|
META_SEMICOLON = ';' - |
|
|
|
META_COMMA = ',' - |
|
|
|
META_DOT = '.' - |
|
|
|
#META_BACKTICK = '`' - |
|
|
|
META_AT = '@' - |
|
|
|
META_LCB = '{' - |
|
|
|
META_RCB = '}' - |
|
|
|
META_LBRAC = '[' - |
|
|
|
META_RBRAC = ']' - |
|
|
|
META_LPAREN = '(' - |
|
|
|
META_RPAREN = ')' - |
|
|
|
META_INTEGER = '0b' < [01]+ > { $$ = makeInteger(strtol(yytext, 0, 2)) } -- |
|
|
|
| '0x' < [0-9a-fA-F]+ > { $$ = makeInteger(strtol(yytext, 0, 16)) } -- |
|
|
|
| '0' < [0-7]+ > { $$ = makeInteger(strtol(yytext, 0, 8)) }-- |
|
|
|
| < [0-9]+ > { $$ = makeInteger(strtol(yytext, 0, 10)) } -- |
|
|
|
| META_SQUOTE < (!META_SQUOTE meta_char) > META_SQUOTE { $$ = makeInteger(unescape(yytext)[0]) } -- |
|
|
|
|
|
|
|
META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > { $$ = makeFloat(strtold(yytext, 0)) } -- |
|
|
|
| < [-+]* [0-9]* '.' [0-9]+ ('e'[-+]*[0-9]+)? > { $$ = makeFloat(strtold(yytext, 0)) } -- |
|
|
|
| < [-+]* [0-9]+ ('e'[-+]*[0-9]+) > { $$ = makeFloat(strtold(yytext, 0)) } -- |
|
|
|
|
|
|
|
#META_FUN = 'fun' ![a-zA-Z0-9_] -- |
|
|
|
#META_SYNTAX = 'syntax' ![a-zA-Z0-9_] -- |
|
|
|
META_VAR = 'var' ![a-zA-Z0-9_] -- |
|
|
|
META_SWITCH = 'switch' ![a-zA-Z0-9_] -- |
|
|
|
META_CASE = 'case' ![a-zA-Z0-9_] -- |
|
|
|
META_DEFAULT = 'default' ![a-zA-Z0-9_] -- |
|
|
|
META_DO = 'do' ![a-zA-Z0-9_] -- |
|
|
|
META_FOR = 'for' ![a-zA-Z0-9_] -- |
|
|
|
META_IN = 'in' ![a-zA-Z0-9_] -- |
|
|
|
META_WHILE = 'while' ![a-zA-Z0-9_] -- |
|
|
|
META_IF = 'if' ![a-zA-Z0-9_] -- |
|
|
|
META_ELSE = 'else' ![a-zA-Z0-9_] -- |
|
|
|
META_NULL = 'null' ![a-zA-Z0-9_] -- |
|
|
|
META_RETURN = 'return' ![a-zA-Z0-9_] -- |
|
|
|
META_BREAK = 'break' ![a-zA-Z0-9_] -- |
|
|
|
META_CONTINUE = 'continue' ![a-zA-Z0-9_] -- |
|
|
|
META_THROW = 'throw' ![a-zA-Z0-9_] -- |
|
|
|
META_TRY = 'try' ![a-zA-Z0-9_] -- |
|
|
|
META_CATCH = 'catch' ![a-zA-Z0-9_] -- |
|
|
|
META_FINALLY = 'finally' ![a-zA-Z0-9_] -- |
|
|
|
META_IMPORT = 'import' ![a-zA-Z0-9_] -- |
|
|
|
META_HASH = '#' -- |
|
|
|
META_LOGOR = '||' -- |
|
|
|
META_LOGAND = '&&' -- |
|
|
|
META_BITOR = '|' ![|=] -- |
|
|
|
META_BITXOR = '^' ![=] -- |
|
|
|
META_BITAND = '&' ![&=] -- |
|
|
|
META_EQUAL = '==' -- |
|
|
|
META_NOTEQ = '!=' -- |
|
|
|
META_LESS = '<' ![<=] -- |
|
|
|
META_LESSEQ = '<=' -- |
|
|
|
META_GREATEREQ = '>=' -- |
|
|
|
META_GREATER = '>' ![>=] -- |
|
|
|
META_SHLEFT = '<<' ![=] -- |
|
|
|
META_SHRIGHT = '>>' ![=] -- |
|
|
|
META_PLUS = '+' ![+=] -- |
|
|
|
META_MINUS = '-' ![-=] -- |
|
|
|
META_NEGATE = '-' ![-=0-9.] -- |
|
|
|
META_PLUSPLUS = '++' -- |
|
|
|
META_MINUSMINUS = '--' -- |
|
|
|
META_TILDE = '~' -- |
|
|
|
META_PLING = '!' ![=] -- |
|
|
|
META_MULTI = '*' ![=] -- |
|
|
|
META_DIVIDE = '/' ![/=] -- |
|
|
|
META_MODULO = '%' ![=] -- |
|
|
|
META_ASSIGN = '=' ![=] -- |
|
|
|
META_ASSIGNADD = '+=' -- |
|
|
|
META_ASSIGNSUB = '-=' -- |
|
|
|
META_ASSIGNMUL = '*=' -- |
|
|
|
META_ASSIGNDIV = '/=' -- |
|
|
|
META_ASSIGNMOD = '%=' -- |
|
|
|
META_ASSIGNBITOR = '|=' -- |
|
|
|
META_ASSIGNBITXOR = '^=' -- |
|
|
|
META_ASSIGNBITAND = '&=' -- |
|
|
|
META_ASSIGNSHLEFT = '<<=' -- |
|
|
|
META_ASSIGNSHRIGHT = '>>=' -- |
|
|
|
META_QUERY = '?' -- |
|
|
|
META_COLON = ':' -- |
|
|
|
META_SEMICOLON = ';' -- |
|
|
|
META_COMMA = ',' -- |
|
|
|
META_DOT = '.' -- |
|
|
|
#META_BACKTICK = '`' -- |
|
|
|
META_AT = '@' -- |
|
|
|
META_LCB = '{' -- |
|
|
|
META_RCB = '}' -- |
|
|
|
META_LBRAC = '[' -- |
|
|
|
META_RBRAC = ']' -- |
|
|
|
META_LPAREN = '(' -- |
|
|
|
META_RPAREN = ')' -- |
|
|
|
META_DQUOTE = '"' |
|
|
|
META_SQUOTE = "'" |
|
|
|
|
|
|
|
#-------------------- C space rules --------------------# |
|
|
|
|
|
|
|
- = < Space* > { if (yyleng && $$) setComment($$, newComment(yytext)) } |
|
|
|
|
|
|
|
Space = Blank | Comment | EOL | Directive |
|
|
|
| "__extension__" &{gnu} { icol += 13 } |
|
|
|
|
|
|
|
Blank = ( [\003-\010] | '\013' | '\f' | [\016-\037] | [\177-\377] | ' ' ) { ++icol } |
|
|
|
| '\t' { icol= (icol + 8) & ~7 } |
|
|
|
|
|
|
|
EOL = ( "\r\n" | '\n' | '\r' ) { ++irow; icol= 0 } |
|
|
|
|
|
|
|
Comment = "/*" ( !"*/" (EOL | Any) )* "*/" |
|
|
|
| "//" ( ![\n\r] Any )* EOL |
|
|
|
|
|
|
|
Directive = "#" (!EOL .)* |
|
|
|
|
|
|
|
Any = . { ++icol } |
|
|
|
|
|
|
|
#-------------------- Meta space rules --------------------# |
|
|
|
|
|
|
|
-- = (blank | comment)* |
|
|
|
|
|
|
|
blank = space | eol |
|
|
|
space = [ \t] |
|
|
|
eol = ( "\n""\r"* |
|
|
|
| "\r""\n"* |
|
|
|
) { inputStack->lineNumber++ } |
|
|
|
|
|
|
|
comment = "//" ( ![\n\r] . )* |
|
|
|
| "/*" ( !"*/" (eol | .) )* "*/" |
|
|
|
|
|
|
|
%% |
|
|
|
; |
|
|
|
|
|
|
|