"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/host-c/rlhc-c.lm" between
ragel-7.0.0.11.tar.gz and ragel-7.0.0.12.tar.gz

About: Ragel compiles executable finite state machines from regular languages (C, C++, Obj-C, C#, D, Java, Go and Ruby). Development version.

rlhc-c.lm  (ragel-7.0.0.11):rlhc-c.lm  (ragel-7.0.0.12)
include 'ril.lm' include 'ril.lm'
namespace c_out namespace c_out
token _IN_ /''/ token _IN_ /''/
token _EX_ /''/ token _EX_ /''/
lex lex
token comment / token comment /
'//' any* :> '\n' | '//' any* :> '\n' |
'/*' any* :>> '*/' '/*' any* :>> '*/'
/ /
token id token id
skipping to change at line 50 skipping to change at line 51
| [number] | [number]
| [symbol] | [symbol]
| [string] | [string]
| [`{ _IN_ item* _EX_ `} ] | [`{ _IN_ item* _EX_ `} ]
def c_out def c_out
[_IN_ _EX_ item*] [_IN_ _EX_ item*]
end end
namespace c_gen namespace c_gen
global _: parser<c_out::c_out>
global Parser: parser<c_out::c_out>
void tok_list( TL: host::tok* ) void tok_list( TL: host::tok* )
{ {
for Tok: host::tok in repeat(TL) { for Tok: host::tok in repeat(TL) {
switch Tok switch Tok
case [host::`${ StmtList: stmt* host::`}$] { case Stmt {
send Parser "{
"{ " [stmt_list( StmtList )]
" [stmt_list( StmtList )] "}
"}
} }
case [host::`={ Expr: expr host::`}=] { case Expr {
send Parser "([expr( Expr )])"
"([expr( Expr )])"
} }
case [E: escape] { case Escape {
Str: str = $E Str: str = $escape
send Parser "[Str.suffix( 1 )]"
"[Str.suffix( 1 )]"
} }
default { default {
send Parser [Tok]
[Tok]
} }
} }
} }
void embedded_host( EmbeddedHost: embedded_host ) void embedded_host( EmbeddedHost: embedded_host )
{ {
switch EmbeddedHost switch EmbeddedHost
case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] case Expr
{ {
send Parser "([tok_list( TL )])"
"([tok_list( TL )])"
} }
case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] case Stmt
{ {
send Parser "{
"{ " [tok_list( TL )]
" [tok_list( TL )] "}
"}
} }
case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] case Bare
{ {
send Parser [tok_list( TL )]
[tok_list( TL )]
} }
} }
void expr_factor( ExprFactor: expr_factor ) void expr_factor( ExprFactor: expr_factor )
{ {
switch ExprFactor switch ExprFactor
case [EH: embedded_host] case [EH: embedded_host]
{ {
send Parser [embedded_host( EH )]
[embedded_host( EH )]
} }
case [`( E: expr `)] case Paren
{ {
send Parser "([expr( expr )])"
"([expr(E)])"
} }
case [I: ident `[ E: expr `]] case ArraySub
{ {
send Parser "[ident]\[[expr( expr )]\]"
"[I]\[[expr( E )]\]"
} }
case [I: ident `[ E: expr `] `. F: ident] case ArraySubField
{ {
send Parser "[ident]\[[expr( expr )]\].[Field]"
"[I]\[[expr( E )]\].[F]"
} }
case [`offset `( ident `, expr `)] case Offset
{ {
send Parser "[ident] + [expr( expr )]"
[ExprFactor.ident ' + ' expr( ExprFactor.expr )]
} }
case [`deref `( ident `, expr `)] case Deref
{ {
send Parser "(*( [expr(expr)] ))
"(*( [expr(ExprFactor.expr)] ))
} }
case [`TRUE] case [`TRUE]
{ {
send Parser "1" "1"
} }
case [`FALSE] case [`FALSE]
{ {
send Parser "1" "1"
} }
case [N: `nil] case [N: `nil]
{ {
send Parser "0" "0"
} }
case [Number: number] case [Number: number]
{ {
number( Number ) number( Number )
} }
case [E1: embedded_host `-> E2: expr_factor] case [E1: embedded_host `-> E2: expr_factor]
{ {
# The accessor operator is contained wihtin the lhs. # The accessor operator is contained wihtin the lhs.
embedded_host( E1 ) embedded_host( E1 )
expr_factor( E2 ) expr_factor( E2 )
} }
case [`cast `( T: type `) F: expr_factor] case [`cast `( T: type `) F: expr_factor]
{ {
send Parser "( [type( T )] ) [expr_factor( F )]"
"( [type( T )] ) [expr_factor( F )]"
} }
default { default {
# Catches cases not specified # Catches cases not specified
send Parser [ExprFactor] [ExprFactor]
} }
} }
void lvalue( ExprFactor: lvalue ) void lvalue( ExprFactor: lvalue )
{ {
switch ExprFactor switch ExprFactor
case [EH: embedded_host] case [EH: embedded_host]
{ {
send Parser [embedded_host( EH )]
[embedded_host( EH )]
} }
case [ident O: `[ TL: expr C: `]] case [ident O: `[ TL: expr C: `]]
{ {
send Parser [ident O expr( TL ) C]
[ExprFactor.ident O expr( TL ) C]
} }
case [I: ident `[ E: expr `] `. F: ident] case [I: ident `[ E: expr `] `. F: ident]
{ {
send Parser "[I]\[[ expr( E )]\].[F]
"[I]\[[ expr( E )]\].[F]
} }
case [E1: embedded_host `-> E2: lvalue] case [E1: embedded_host `-> E2: lvalue]
{ {
# The accessor operator is contained wihtin the lhs. # The accessor operator is contained wihtin the lhs.
embedded_host( E1 ) embedded_host( E1 )
lvalue( E2 ) lvalue( E2 )
} }
default { default {
# Catches cases not specified # Catches cases not specified
send Parser [ExprFactor] [ExprFactor]
} }
} }
void expr_factor_op( ExprFactorOp: expr_factor_op ) void expr_factor_op( ExprFactorOp: expr_factor_op )
{ {
switch ExprFactorOp switch ExprFactorOp
case [B: `! expr_factor_op] case [B: `! expr_factor_op]
{ {
send Parser [B] ['!' expr_factor_op( _expr_factor_op )]
expr_factor_op( ExprFactorOp._expr_factor_op )
} }
case [T: `~ expr_factor_op] case [T: `~ expr_factor_op]
{ {
send Parser [T] ['~' expr_factor_op( _expr_factor_op )]
expr_factor_op( ExprFactorOp._expr_factor_op )
} }
case [expr_factor] case [expr_factor]
{ {
expr_factor( ExprFactorOp.expr_factor ) [expr_factor( expr_factor )]
} }
} }
void expr_bitwise( ExprBitwise: expr_bitwise ) void expr_bitwise( ExprBitwise: expr_bitwise )
{ {
switch ExprBitwise switch ExprBitwise
case [expr_bitwise A: `& expr_factor_op] case [expr_bitwise A: `& expr_factor_op]
{ {
expr_bitwise( ExprBitwise._expr_bitwise ) [expr_bitwise( _expr_bitwise ) A expr_factor_op( expr_fac
send Parser [A] tor_op )]
expr_factor_op( ExprBitwise.expr_factor_op )
} }
case [expr_factor_op] case [expr_factor_op]
{ {
expr_factor_op( ExprBitwise.expr_factor_op ) [expr_factor_op( expr_factor_op )]
} }
} }
void expr_mult( ExprMult: expr_mult ) void expr_mult( ExprMult: expr_mult )
{ {
switch ExprMult switch ExprMult
case [expr_mult T: `* expr_bitwise] case [expr_mult T: `* expr_bitwise]
{ {
expr_mult( ExprMult._expr_mult ) [expr_mult( _expr_mult ) T expr_bitwise( expr_bitwise )]
send Parser [T]
expr_bitwise( ExprMult.expr_bitwise )
} }
case [expr_bitwise] case [expr_bitwise]
{ {
expr_bitwise( ExprMult.expr_bitwise ) [expr_bitwise( expr_bitwise )]
} }
} }
void expr_add( ExprAdd: expr_add ) void expr_add( ExprAdd: expr_add )
{ {
switch ExprAdd switch ExprAdd
case [expr_add Op: add_op expr_mult] case [expr_add Op: add_op expr_mult]
{ {
expr_add( ExprAdd._expr_add ) [expr_add( _expr_add ) Op expr_mult( expr_mult )]
send Parser [Op]
expr_mult( ExprAdd.expr_mult )
} }
case [expr_mult] case [expr_mult]
{ {
expr_mult( ExprAdd.expr_mult ) [expr_mult( expr_mult )]
} }
} }
void expr_shift( ExprShift: expr_shift ) void expr_shift( ExprShift: expr_shift )
{ {
switch ExprShift switch ExprShift
case [expr_shift Op: shift_op expr_add] case [expr_shift Op: shift_op expr_add]
{ {
expr_shift( ExprShift._expr_shift ) [expr_shift( _expr_shift ) Op expr_add( expr_add )]
send Parser [Op]
expr_add( ExprShift.expr_add )
} }
case [expr_add] case [expr_add]
{ {
expr_add( ExprShift.expr_add ) [expr_add( expr_add )]
} }
} }
void expr_test( ExprTest: expr_test ) void expr_test( ExprTest: expr_test )
{ {
switch ExprTest switch ExprTest
case [expr_test Op: test_op expr_shift] case [expr_test Op: test_op expr_shift]
{ {
expr_test( ExprTest._expr_test ) [expr_test( _expr_test ) Op expr_shift( expr_shift )]
send Parser [Op]
expr_shift( ExprTest.expr_shift )
} }
case [expr_shift] case [expr_shift]
{ {
expr_shift( ExprTest.expr_shift ) [expr_shift( expr_shift )]
} }
} }
void expr( Expr: expr ) void expr( Expr: expr )
{ {
expr_test( Expr.expr_test ) expr_test( Expr.expr_test )
} }
void type( Type: type ) void type( Type: type )
{ {
switch Type switch Type
case "s8" case S8
send Parser ['char '] ['signed char ']
case "s16" case S16
send Parser ['short '] ['short ']
case "s32" case S32
send Parser ['int '] ['int ']
case "s64" case S64
send Parser ['long '] ['long ']
case "s128" case S128
send Parser ['long long '] ['long long ']
case "uint" case "uint"
send Parser ['unsigned int '] ['unsigned int ']
default default
send Parser [Type] [Type]
} }
void number( Number: number ) void number( Number: number )
{ {
switch Number switch Number
case [`u `( uint `) ] case Unsigned
send Parser "[Number.uint]u" "[uint]u"
default default
send Parser [Number] [Number]
} }
void num_list( NumList: num_list ) void num_list( NumList: num_list )
{ {
for Number: number in NumList for Number: number in NumList
send Parser "[number( Number )], " "[number( Number )], "
} }
void stmt( Stmt: stmt ) void stmt( Stmt: stmt )
{ {
switch Stmt switch Stmt
case [EH: embedded_host] case [EH: embedded_host]
{ {
send Parser [embedded_host( EH )]
[embedded_host( EH )]
} }
case [A: static_array] { case [A: static_array] {
send Parser "static const [type(A.type)] "
"static const [type(A.type)] " "[A.ident] \[\] = { [num_list(A.num_list)] };
"[A.ident] \[\] = { [num_list(A.num_list)
] };
} }
case [V: static_value] { case [V: static_value] {
send Parser "static const [V.type] [V.ident] = [V.number];
"static const [V.type] [V.ident] = [V.number];
} }
case [ case [
`if `( IfExpr: expr `) IfStmt: stmt `if `( IfExpr: expr `)
ElseIfClauseList: else_if_clause* ElseClauseOpt: IfStmt: stmt
else_clause? ElseIfClauseList: else_if_clause*
ElseClauseOpt: else_clause?
] { ] {
send Parser "if ( [expr(IfExpr)] )
"if ( [expr(IfExpr)] ) " [stmt(IfStmt)]
" [stmt(IfStmt)]
for ElseIfClause: else_if_clause in repeat( ElseIfClauseL ist ) { for ElseIfClause: else_if_clause in repeat( ElseIfClauseL ist ) {
match ElseIfClause match ElseIfClause
[`else `if `( ElseIfExpr: expr `) ElseIfS tmt: stmt] [`else `if `( ElseIfExpr: expr `) ElseIfS tmt: stmt]
send Parser "else if ( [expr(ElseIfExpr)] )
"else if ( [expr(ElseIfExpr)] ) " [stmt(ElseIfStmt)]
" [stmt(ElseIfStmt)]
} }
if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) {
send Parser "else
"else " [stmt(ElseStmt)]
" [stmt(ElseStmt)]
} }
} }
case [`while `( WhileExpr: expr `) WhileStmt: stmt] { case [`while `( WhileExpr: expr `) WhileStmt: stmt] {
send Parser "while ( [expr(WhileExpr)] )
"while ( [expr(WhileExpr)] ) " [stmt(WhileStmt)]
" [stmt(WhileStmt)]
} }
case [M: match_stmt] { case [M: match_stmt] {
send Parser "switch ( [expr(M.E)] ) {
"switch ( [expr(M.E)] ) {
for PB: pat_block in repeat( M.P ) { for PB: pat_block in repeat( M.P ) {
send Parser "case [expr( PB.expr )]:
"case [expr( PB.expr )]: "[stmt_list( PB._repeat_stmt )]
"[stmt_list( PB._repeat_stmt )] "break;
"break;
} }
if match M.D [D: default_block] { if match M.D [D: default_block] {
send Parser "default:
"default: "[stmt_list( D._repeat_stmt )]
"[stmt_list( D._repeat_stmt )] "break;
"break;
} }
send Parser "}
"}
} }
case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] {
send Parser "switch ( [expr(SwitchExpr)] ) {
"switch ( [expr(SwitchExpr)] ) { " [stmt_list(StmtList)]
" [stmt_list(StmtList)] "}
"} }
} case [ES: expr_stmt] {
case [ExprExpr: expr Semi: `;] { "[expr(ES.expr)];
send Parser }
[expr(ExprExpr) Semi] case [B: block] {
} "{
case [L: `{ TL: stmt* R: `}] { " [stmt_list(B.StmtList)]
send Parser "}
[L stmt_list(TL) R]
} }
case [ case [
TypeList: opt_const Type: type OptConst: opt_const Type: type
Ident: ident OptInit: opt_init Semi: `; Ident: ident OptInit: opt_init Semi: `;
] ]
{ {
send Parser "[OptConst] [type(Type)] [Ident]"
[TypeList type(Type) Ident]
if match OptInit [E: `= expr] { if match OptInit [`= Init: expr] {
send Parser " = [expr(Init)]
[E expr(OptInit.expr)]
} }
send Parser ";
[Semi]
} }
case [Export: export_stmt] case [Export: export_stmt]
{ {
send Parser "#define [Export.ident] [number(Export.number)]
"#define [Export.ident] [number(Export.number)]
} }
case ['fallthrough' ';'] case [fallthrough]
{ {
# Nothing needed here. # Nothing needed here.
# C falls through by default.
} }
case [Index: index_stmt] case [Index: index_stmt]
{ {
send Parser "const [type(Index.type)] *[Index.ident]
"const [type(Index.type)] *[Index.ident]
if match Index.opt_init [E: `= expr] { if match Index.opt_init [E: `= expr] {
send Parser [E expr(Index.opt_init.expr)]
[E expr(Index.opt_init.expr)]
} }
send Parser "; ";
}
case [case_block]
{
send Parser
"case [expr( Stmt.case_block.expr )]:
"[stmt_list( Stmt.case_block._repeat_stmt )]
"break;
}
case [default_block]
{
send Parser
"default:
"[stmt_list( Stmt.default_block._repeat_stmt )]
"break;
} }
case [case_label] case [CB: case_block]
{ {
send Parser "case [expr( CB.expr )]:
"case [expr( Stmt.case_label.expr )]: "[stmt_list( CB._repeat_stmt )]
"break;
} }
case [label_stmt] case [DB: default_block]
{ {
send Parser "default:
"[Stmt.label_stmt.ident]: "[stmt_list( DB._repeat_stmt )]
"[stmt_list( Stmt.label_stmt._repeat_stmt )] "break;
} }
case [entry_loop] case [CL: case_label]
{ {
send Parser "case [expr( CL.expr )]:
[stmt_list( Stmt.entry_loop._repeat_stmt )]
} }
case [AS: assign_stmt] case [AS: assign_stmt]
{ {
send Parser "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)];
"[lvalue(AS.LValue) AS.assign_op expr(AS.expr)];
} }
default { default {
# catches unspecified cases # catches unspecified cases
send Parser [Stmt] [Stmt]
} }
} }
void stmt_list( StmtList: stmt* ) void stmt_list( StmtList: stmt* )
{ {
for Stmt: stmt in repeat( StmtList ) for Stmt: stmt in repeat( StmtList )
stmt( Stmt ) stmt( Stmt )
} }
void trans( Output: stream, Start: start ) void trans( Output: stream, Start: start )
{ {
Parser = new parser<c_out::c_out>() _ = new parser<c_out::c_out>()
stmt_list( Start._repeat_stmt ) stmt_list( Start._repeat_stmt )
CO: c_out::c_out = Parser->finish() CO: c_out::c_out = _->finish()
if CO { if CO {
send Output send Output
[CO] [CO]
} }
else { else {
send stderr send stderr
"failed to parse output: [Parser->error] "failed to parse output: [_->error]
} }
} }
end end
void trans( Output: stream, Start: start ) void trans( Output: stream, Start: start )
{ {
c_gen::trans( Output, Start ) c_gen::trans( Output, Start )
} }
include 'rlhc-main.lm' include 'rlhc-main.lm'
 End of changes. 85 change blocks. 
192 lines changed or deleted 131 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)